ListCommand.cs (13950B)
1 // ----------------------------------------------------------------------------- 2 // <copyright file="ListCommand.cs" company="Microsoft Corporation"> 3 // Copyright (c) Microsoft Corporation. Licensed under the MIT License. 4 // </copyright> 5 // ----------------------------------------------------------------------------- 6 7 namespace AppInstallerCLIE2ETests 8 { 9 using System.IO; 10 using AppInstallerCLIE2ETests.Helpers; 11 using NUnit.Framework; 12 13 /// <summary> 14 /// List command tests. 15 /// </summary> 16 public class ListCommand : BaseCommand 17 { 18 /// <summary> 19 /// Test list winget. 20 /// </summary> 21 [Test] 22 public void ListSelf() 23 { 24 var result = TestCommon.RunAICLICommand("list", Constants.AICLIPackageFamilyName); 25 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 26 Assert.True(result.StdOut.Contains(Constants.AICLIPackageName)); 27 Assert.True(result.StdOut.Contains(Constants.AICLIPackagePublisherHash)); 28 } 29 30 /// <summary> 31 /// Test list after installing a package. 32 /// </summary> 33 [Test] 34 public void ListAfterInstall() 35 { 36 System.Guid guid = System.Guid.NewGuid(); 37 string productCode = guid.ToString(); 38 var installDir = TestCommon.GetRandomTestDir(); 39 40 // DisplayName must be set to avoid conflicts with other packages that use the same exe installer. 41 string displayName = "TestExeInstaller"; 42 string localAppDataPath = System.Environment.GetEnvironmentVariable(Constants.LocalAppData); 43 string logFilePath = System.IO.Path.Combine(localAppDataPath, Constants.E2ETestLogsPathPackaged); 44 logFilePath = System.IO.Path.Combine(logFilePath, "ListAfterInstall-" + System.IO.Path.GetRandomFileName() + ".log"); 45 46 var result = TestCommon.RunAICLICommand("list", productCode); 47 Assert.AreEqual(Constants.ErrorCode.ERROR_NO_APPLICATIONS_FOUND, result.ExitCode); 48 49 result = TestCommon.RunAICLICommand("install", $"AppInstallerTest.TestExeInstaller --override \"/InstallDir {installDir} /ProductID {productCode} /LogFile {logFilePath} /DisplayName {displayName}\""); 50 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 51 52 result = TestCommon.RunAICLICommand("list", productCode); 53 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 54 Assert.True(result.StdOut.Contains("AppInstallerTest.TestExeInstaller")); 55 Assert.True(result.StdOut.Contains("1.0.0.0")); 56 Assert.True(result.StdOut.Contains("2.0.0.0")); 57 } 58 59 /// <summary> 60 /// Test expected entries after list. 61 /// </summary> 62 [Test] 63 public void ListWithArpVersionMapping() 64 { 65 // No mapping performed 66 this.ArpVersionMappingTest("AppInstallerTest.TestArpVersionSameVersion", "TestArpVersionSameVersion", "0.5", "0.5", "< 1.0"); 67 68 // Partial mapping performed(i.e. only if version falls within arp version range) 69 this.ArpVersionMappingTest("AppInstallerTest.TestArpVersionOppositeOrder", "TestArpVersionOppositeOrder", "10.1", "1.0", "10.1"); 70 this.ArpVersionMappingTest("AppInstallerTest.TestArpVersionOppositeOrder", "TestArpVersionOppositeOrder", "9.9", "9.9", "> 2.0"); 71 72 // Full mapping performed 73 this.ArpVersionMappingTest("AppInstallerTest.TestArpVersionSameOrder", "TestArpVersionSameOrder", "7.0", "< 1.0", "7.0"); 74 this.ArpVersionMappingTest("AppInstallerTest.TestArpVersionSameOrder", "TestArpVersionSameOrder", "10.1", "1.0", "10.1"); 75 this.ArpVersionMappingTest("AppInstallerTest.TestArpVersionSameOrder", "TestArpVersionSameOrder", "10.7", "< 2.0", "10.7"); 76 this.ArpVersionMappingTest("AppInstallerTest.TestArpVersionSameOrder", "TestArpVersionSameOrder", "11.1", "2.0", "11.1"); 77 this.ArpVersionMappingTest("AppInstallerTest.TestArpVersionSameOrder", "TestArpVersionSameOrder", "12.0", "> 2.0", "12.0"); 78 } 79 80 /// <summary> 81 /// Test list with upgrade code. 82 /// </summary> 83 [Test] 84 public void ListWithUpgradeCode() 85 { 86 // Installs the MSI installer using the TestMsiInstaller package. 87 // Then tries listing the TestMsiInstallerUpgradeCode package, which should 88 // be correlated to it by the UpgradeCode. 89 if (string.IsNullOrEmpty(TestIndex.MsiInstaller)) 90 { 91 Assert.Ignore("MSI installer not available"); 92 } 93 94 var installDir = TestCommon.GetRandomTestDir(); 95 Assert.AreEqual(Constants.ErrorCode.S_OK, TestCommon.RunAICLICommand("install", $"TestMsiInstaller --silent -l {installDir}").ExitCode); 96 97 var result = TestCommon.RunAICLICommand("list", "TestMsiInstallerUpgradeCode"); 98 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 99 Assert.True(result.StdOut.Contains("AppInstallerTest.TestMsiInstallerUpgradeCode")); 100 } 101 102 /// <summary> 103 /// Test list with exe installed with machine scope. 104 /// </summary> 105 [Test] 106 public void ListWithScopeExeInstalledAsMachine() 107 { 108 System.Guid guid = System.Guid.NewGuid(); 109 string identifier = "AppInstallerTest.TestExeInstaller"; 110 string productCode = guid.ToString(); 111 var installDir = TestCommon.GetRandomTestDir(); 112 var result = TestCommon.RunAICLICommand("install", $"{identifier} --override \"/InstallDir {installDir} /ProductID {productCode} /UseHKLM\""); 113 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 114 115 // List with user scope will not find the package 116 result = TestCommon.RunAICLICommand("list", $"{productCode} --scope user"); 117 Assert.AreEqual(Constants.ErrorCode.ERROR_NO_APPLICATIONS_FOUND, result.ExitCode); 118 Assert.False(result.StdOut.Contains(identifier)); 119 120 // List with machine scope will find the package 121 result = TestCommon.RunAICLICommand("list", $"{productCode} --scope machine"); 122 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 123 Assert.True(result.StdOut.Contains(identifier)); 124 125 TestCommon.RunCommand(Path.Combine(installDir, Constants.TestExeUninstallerFileName)); 126 } 127 128 /// <summary> 129 /// Test list with exe installed with user scope. 130 /// </summary> 131 [Test] 132 public void ListWithScopeExeInstalledAsUser() 133 { 134 System.Guid guid = System.Guid.NewGuid(); 135 string identifier = "AppInstallerTest.TestExeInstaller"; 136 string productCode = guid.ToString(); 137 var installDir = TestCommon.GetRandomTestDir(); 138 var result = TestCommon.RunAICLICommand("install", $"{identifier} --override \"/InstallDir {installDir} /ProductID {productCode}\""); 139 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 140 141 // List with user scope will find the package 142 result = TestCommon.RunAICLICommand("list", $"{productCode} --scope user"); 143 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 144 Assert.True(result.StdOut.Contains(identifier)); 145 146 // List with machine scope will not find the package 147 result = TestCommon.RunAICLICommand("list", $"{productCode} --scope machine"); 148 Assert.AreEqual(Constants.ErrorCode.ERROR_NO_APPLICATIONS_FOUND, result.ExitCode); 149 Assert.False(result.StdOut.Contains(identifier)); 150 151 TestCommon.RunCommand(Path.Combine(installDir, Constants.TestExeUninstallerFileName)); 152 } 153 154 /// <summary> 155 /// Test list with msix installed with machine scope. 156 /// </summary> 157 [Test] 158 public void ListWithScopeMsixInstalledAsMachine() 159 { 160 // TODO: Provision and Deprovision api not supported in build server. 161 Assert.Ignore(); 162 163 var result = TestCommon.RunAICLICommand("install", $"{Constants.MsixInstallerPackageId} --scope machine"); 164 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 165 166 // List with user scope will also find the package because msix is provisioned for all users 167 result = TestCommon.RunAICLICommand("list", $"{Constants.MsixInstallerPackageId} --scope user"); 168 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 169 Assert.True(result.StdOut.Contains(Constants.MsixInstallerPackageId)); 170 171 // List with machine scope will find the package 172 result = TestCommon.RunAICLICommand("list", $"{Constants.MsixInstallerPackageId} --scope machine"); 173 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 174 Assert.True(result.StdOut.Contains(Constants.MsixInstallerPackageId)); 175 176 TestCommon.RemoveMsix(Constants.MsixInstallerName, true); 177 } 178 179 /// <summary> 180 /// Test list with msix installed with user scope. 181 /// </summary> 182 [Test] 183 public void ListWithScopeMsixInstalledAsUser() 184 { 185 var result = TestCommon.RunAICLICommand("install", $"{Constants.MsixInstallerPackageId} --scope user"); 186 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 187 188 // List with user scope will find the package 189 result = TestCommon.RunAICLICommand("list", $"{Constants.MsixInstallerPackageId} --scope user"); 190 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 191 Assert.True(result.StdOut.Contains(Constants.MsixInstallerPackageId)); 192 193 // List with machine scope will not find the package 194 result = TestCommon.RunAICLICommand("list", $"{Constants.MsixInstallerPackageId} --scope machine"); 195 Assert.AreEqual(Constants.ErrorCode.ERROR_NO_APPLICATIONS_FOUND, result.ExitCode); 196 Assert.False(result.StdOut.Contains(Constants.MsixInstallerPackageId)); 197 198 TestCommon.RemoveMsix(Constants.MsixInstallerName); 199 } 200 201 /// <summary> 202 /// Test package correlation with same package name but different architecture is correct. 203 /// </summary> 204 [Test] 205 public void ListWithMappingWithArchitecture() 206 { 207 var installDir = TestCommon.GetRandomTestDir(); 208 var result = TestCommon.RunAICLICommand("install", $"AppInstallerTest.TestMappingWithArchitectureX86 -l {installDir}"); 209 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 210 211 // List with AppInstallerTest.TestMappingWithArchitectureX64 (from available to installed scenario) will not find the package. 212 result = TestCommon.RunAICLICommand("list", "AppInstallerTest.TestMappingWithArchitectureX64"); 213 Assert.AreEqual(Constants.ErrorCode.ERROR_NO_APPLICATIONS_FOUND, result.ExitCode); 214 Assert.False(result.StdOut.Contains("AppInstallerTest.TestMappingWithArchitectureX64")); 215 216 // List with AppInstallerTest.TestMappingWithArchitectureX86 (from available to installed scenario) will find the package. 217 result = TestCommon.RunAICLICommand("list", "AppInstallerTest.TestMappingWithArchitectureX86"); 218 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 219 Assert.True(result.StdOut.Contains("AppInstallerTest.TestMappingWithArchitectureX86")); 220 221 // List with product code (from installed to available scenario) will find the AppInstallerTest.TestMappingWithArchitectureX86 package. 222 result = TestCommon.RunAICLICommand("list", "{0e426f01-b682-4e67-a357-52f9ecb4590d}"); 223 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 224 Assert.True(result.StdOut.Contains("AppInstallerTest.TestMappingWithArchitectureX86")); 225 226 // best effort clean up 227 TestCommon.RunCommand(Path.Combine(installDir, Constants.TestExeUninstallerFileName)); 228 } 229 230 private void ArpVersionMappingTest(string packageIdentifier, string displayNameOverride, string displayVersionOverride, string expectedListVersion, string notExpectedListVersion = "") 231 { 232 System.Guid guid = System.Guid.NewGuid(); 233 string productCode = guid.ToString(); 234 var installDir = TestCommon.GetRandomTestDir(); 235 236 var result = TestCommon.RunAICLICommand("list", productCode); 237 Assert.AreEqual(Constants.ErrorCode.ERROR_NO_APPLICATIONS_FOUND, result.ExitCode); 238 239 result = TestCommon.RunAICLICommand("install", $"{packageIdentifier} --override \"/InstallDir {installDir} /ProductID {productCode} /DisplayName {displayNameOverride} /Version {displayVersionOverride}\""); 240 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 241 242 result = TestCommon.RunAICLICommand("list", productCode); 243 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 244 245 Assert.True(result.StdOut.Contains(packageIdentifier)); 246 Assert.True(result.StdOut.Contains(expectedListVersion)); 247 if (!string.IsNullOrEmpty(notExpectedListVersion)) 248 { 249 Assert.False(result.StdOut.Contains(notExpectedListVersion)); 250 } 251 252 // Try clean up 253 if (File.Exists(Path.Combine(installDir, Constants.TestExeInstalledFileName))) 254 { 255 TestCommon.RunCommand(Path.Combine(installDir, Constants.TestExeUninstallerFileName)); 256 } 257 } 258 } 259 }