DownloadCommand.cs (10453B)
1 // ----------------------------------------------------------------------------- 2 // <copyright file="DownloadCommand.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 Microsoft.Management.Deployment; 12 using NUnit.Framework; 13 using Windows.System; 14 15 /// <summary> 16 /// Test download command. 17 /// </summary> 18 public class DownloadCommand : BaseCommand 19 { 20 /// <summary> 21 /// Downloads the test installer and its package dependencies. 22 /// </summary> 23 [Test] 24 public void DownloadDependencies() 25 { 26 var downloadDir = TestCommon.GetRandomTestDir(); 27 var result = TestCommon.RunAICLICommand("download", $"AppInstallerTest.PackageDependency --download-directory {downloadDir}"); 28 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 29 var dependenciesDir = Path.Combine(downloadDir, Constants.Dependencies); 30 TestCommon.AssertInstallerDownload(dependenciesDir, "TestPortableExe", "3.0.0.0", ProcessorArchitecture.X64, TestCommon.Scope.Unknown, PackageInstallerType.Portable, "en-US"); 31 TestCommon.AssertInstallerDownload(downloadDir, "TestPackageDependency", "1.0.0.0", ProcessorArchitecture.X64, TestCommon.Scope.Unknown, PackageInstallerType.Exe, "en-US"); 32 } 33 34 /// <summary> 35 /// Downloads the test installer and skips dependencies. 36 /// </summary> 37 [Test] 38 public void DownloadDependencies_Skip() 39 { 40 var downloadDir = TestCommon.GetRandomTestDir(); 41 var result = TestCommon.RunAICLICommand("download", $"AppInstallerTest.PackageDependency --skip-dependencies --download-directory {downloadDir}"); 42 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 43 Assert.True(result.StdOut.Contains("Dependencies skipped.")); 44 Assert.IsFalse(Directory.Exists(Path.Combine(downloadDir, Constants.Dependencies))); 45 TestCommon.AssertInstallerDownload(downloadDir, "TestPackageDependency", "1.0.0.0", ProcessorArchitecture.X64, TestCommon.Scope.Unknown, PackageInstallerType.Exe, "en-US"); 46 } 47 48 /// <summary> 49 /// Downloads the test installer to the default downloads directory. 50 /// </summary> 51 [Test] 52 public void DownloadToDefaultDirectory() 53 { 54 var packageVersion = "2.0.0.0"; 55 var result = TestCommon.RunAICLICommand("download", $"{Constants.ExeInstallerPackageId} --version {packageVersion}"); 56 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 57 string downloadDir = Path.Combine(TestCommon.GetDefaultDownloadDirectory(), $"{Constants.ExeInstallerPackageId}_{packageVersion}"); 58 TestCommon.AssertInstallerDownload(downloadDir, "TestExeInstaller", packageVersion, ProcessorArchitecture.X86, TestCommon.Scope.User, PackageInstallerType.Exe); 59 } 60 61 /// <summary> 62 /// Downloads the test installer to a specified directory. 63 /// </summary> 64 [Test] 65 public void DownloadToDirectory() 66 { 67 var downloadDir = TestCommon.GetRandomTestDir(); 68 var result = TestCommon.RunAICLICommand("download", $"{Constants.ExeInstallerPackageId} --download-directory {downloadDir}"); 69 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 70 TestCommon.AssertInstallerDownload(downloadDir, "TestExeInstaller", "2.0.0.0", ProcessorArchitecture.X86, TestCommon.Scope.User, PackageInstallerType.Exe); 71 } 72 73 /// <summary> 74 /// Downloads the test installer with Arm64. 75 /// </summary> 76 [Test] 77 public void DownloadWithArm64() 78 { 79 var downloadDir = TestCommon.GetRandomTestDir(); 80 var result = TestCommon.RunAICLICommand("download", $"AppInstallerTest.TestMultipleInstallers --scope user --download-directory {downloadDir} --architecture Arm64"); 81 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 82 #pragma warning disable CA1416 // Validate platform compatibility. Arm64 is not reachable. 83 TestCommon.AssertInstallerDownload(downloadDir, "TestMultipleInstallers", "1.0.0.0", ProcessorArchitecture.Arm64, TestCommon.Scope.User, PackageInstallerType.Nullsoft, "en-US"); 84 #pragma warning restore CA1416 85 } 86 87 /// <summary> 88 /// Downloads the test installer using the user scope argument. 89 /// </summary> 90 [Test] 91 public void DownloadWithUserScope() 92 { 93 var downloadDir = TestCommon.GetRandomTestDir(); 94 var result = TestCommon.RunAICLICommand("download", $"AppInstallerTest.TestMultipleInstallers --scope user --download-directory {downloadDir}"); 95 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 96 TestCommon.AssertInstallerDownload(downloadDir, "TestMultipleInstallers", "1.0.0.0", ProcessorArchitecture.X64, TestCommon.Scope.User, PackageInstallerType.Nullsoft, "en-US"); 97 } 98 99 /// <summary> 100 /// Downloads the test installer using the machine scope argument. 101 /// </summary> 102 [Test] 103 public void DownloadWithMachineScope() 104 { 105 var downloadDir = TestCommon.GetRandomTestDir(); 106 var result = TestCommon.RunAICLICommand("download", $"AppInstallerTest.TestMultipleInstallers --scope machine --download-directory {downloadDir}"); 107 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 108 TestCommon.AssertInstallerDownload(downloadDir, "TestMultipleInstallers", "1.0.0.0", ProcessorArchitecture.X86, TestCommon.Scope.Machine, PackageInstallerType.Msi, "en-US"); 109 } 110 111 /// <summary> 112 /// Downloads the test installer using the 'zip' installer type argument. Verifies that base installer types such as 'zip' are still supported. 113 /// </summary> 114 [Test] 115 public void DownloadWithZipInstallerTypeArg() 116 { 117 var downloadDir = TestCommon.GetRandomTestDir(); 118 var result = TestCommon.RunAICLICommand("download", $"AppInstallerTest.TestMultipleInstallers --installer-type zip --download-directory {downloadDir}"); 119 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 120 TestCommon.AssertInstallerDownload(downloadDir, "TestMultipleInstallers", "1.0.0.0", ProcessorArchitecture.X64, TestCommon.Scope.Unknown, PackageInstallerType.Exe, "zh-CN", true); 121 } 122 123 /// <summary> 124 /// Downloads the test installer using the installer type argument. 125 /// </summary> 126 [Test] 127 public void DownloadWithInstallerTypeArg() 128 { 129 var downloadDir = TestCommon.GetRandomTestDir(); 130 var result = TestCommon.RunAICLICommand("download", $"AppInstallerTest.TestMultipleInstallers --installer-type msi --download-directory {downloadDir}"); 131 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 132 TestCommon.AssertInstallerDownload(downloadDir, "TestMultipleInstallers", "1.0.0.0", ProcessorArchitecture.X86, TestCommon.Scope.Machine, PackageInstallerType.Msi, "en-US"); 133 } 134 135 /// <summary> 136 /// Downloads the test installer using the architecture argument. 137 /// </summary> 138 [Test] 139 public void DownloadWithArchitectureArg() 140 { 141 var downloadDir = TestCommon.GetRandomTestDir(); 142 var result = TestCommon.RunAICLICommand("download", $"AppInstallerTest.TestMultipleInstallers --architecture x86 --download-directory {downloadDir}"); 143 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 144 TestCommon.AssertInstallerDownload(downloadDir, "TestMultipleInstallers", "1.0.0.0", ProcessorArchitecture.X86, TestCommon.Scope.Machine, PackageInstallerType.Msi, "en-US"); 145 } 146 147 /// <summary> 148 /// Downloads the test installer using the locale argument. 149 /// </summary> 150 [Test] 151 public void DownloadWithLocaleArg() 152 { 153 var downloadDir = TestCommon.GetRandomTestDir(); 154 var result = TestCommon.RunAICLICommand("download", $"AppInstallerTest.TestMultipleInstallers --locale zh-CN --download-directory {downloadDir}"); 155 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 156 TestCommon.AssertInstallerDownload(downloadDir, "TestMultipleInstallers", "1.0.0.0", ProcessorArchitecture.X64, TestCommon.Scope.Unknown, PackageInstallerType.Exe, "zh-CN", true); 157 } 158 159 /// <summary> 160 /// Downloads the test installer with a hash mismatch. 161 /// </summary> 162 [Test] 163 public void DownloadWithHashMismatch() 164 { 165 var downloadDir = TestCommon.GetRandomTestDir(); 166 var errorResult = TestCommon.RunAICLICommand("download", $"AppInstallerTest.TestExeSha256Mismatch --download-directory {downloadDir}"); 167 Assert.AreEqual(Constants.ErrorCode.ERROR_INSTALLER_HASH_MISMATCH, errorResult.ExitCode); 168 } 169 170 /// <summary> 171 /// Downloads the zero byte test installer with a hash mismatch. 172 /// </summary> 173 [Test] 174 public void DownloadZeroByteFileWithHashMismatch() 175 { 176 var downloadDir = TestCommon.GetRandomTestDir(); 177 var errorResult = TestCommon.RunAICLICommand("download", $"ZeroByteFile.IncorrectHash --download-directory {downloadDir}"); 178 Assert.AreEqual(Constants.ErrorCode.ERROR_INSTALLER_ZERO_BYTE_FILE, errorResult.ExitCode); 179 } 180 181 /// <summary> 182 /// Downloads the zero byte test installer. 183 /// </summary> 184 [Test] 185 public void DownloadZeroByteFile() 186 { 187 var downloadDir = TestCommon.GetRandomTestDir(); 188 var result = TestCommon.RunAICLICommand("download", $"ZeroByteFile.CorrectHash --download-directory {downloadDir}"); 189 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 190 TestCommon.AssertInstallerDownload(downloadDir, "ZeroByteFile-CorrectHash", "1.0.0.0", ProcessorArchitecture.X86, TestCommon.Scope.Unknown, PackageInstallerType.Exe, "en-US"); 191 } 192 } 193 }