TestIndex.cs (7372B)
1 // ----------------------------------------------------------------------------- 2 // <copyright file="TestIndex.cs" company="Microsoft Corporation"> 3 // Copyright (c) Microsoft Corporation. Licensed under the MIT License. 4 // </copyright> 5 // ----------------------------------------------------------------------------- 6 7 namespace AppInstallerCLIE2ETests.Helpers 8 { 9 using System; 10 using System.IO; 11 using System.Text.Json; 12 using Microsoft.WinGetSourceCreator; 13 using WinGetSourceCreator.Model; 14 15 /// <summary> 16 /// Test index setup. 17 /// </summary> 18 public static class TestIndex 19 { 20 static TestIndex() 21 { 22 // Expected path for the installers. 23 TestIndex.ExeInstaller = Path.Combine(TestSetup.Parameters.StaticFileRootPath, Constants.ExeInstaller, Constants.ExeInstallerFileName); 24 TestIndex.MsiInstaller = Path.Combine(TestSetup.Parameters.StaticFileRootPath, Constants.MsiInstaller, Constants.MsiInstallerFileName); 25 TestIndex.MsiInstallerV2 = Path.Combine(TestSetup.Parameters.StaticFileRootPath, Constants.MsiInstaller, Constants.MsiInstallerV2FileName); 26 TestIndex.MsixInstaller = Path.Combine(TestSetup.Parameters.StaticFileRootPath, Constants.MsixInstaller, Constants.MsixInstallerFileName); 27 TestIndex.ZipInstaller = Path.Combine(TestSetup.Parameters.StaticFileRootPath, Constants.ZipInstaller, Constants.ZipInstallerFileName); 28 } 29 30 /// <summary> 31 /// Gets the signed exe installer path used by the manifests in the E2E test. 32 /// </summary> 33 public static string ExeInstaller { get; private set; } 34 35 /// <summary> 36 /// Gets the signed msi installer path used by the manifests in the E2E test. 37 /// </summary> 38 public static string MsiInstaller { get; private set; } 39 40 /// <summary> 41 /// Gets the signed msi installerV2 path used by the manifests in the E2E test. 42 /// </summary> 43 public static string MsiInstallerV2 { get; private set; } 44 45 /// <summary> 46 /// Gets the signed msix installer path used by the manifests in the E2E test. 47 /// </summary> 48 public static string MsixInstaller { get; private set; } 49 50 /// <summary> 51 /// Gets the zip installer path used by the manifests in the E2E test. 52 /// </summary> 53 public static string ZipInstaller { get; private set; } 54 55 /// <summary> 56 /// Generate test source. 57 /// </summary> 58 public static void GenerateE2ESource() 59 { 60 var testParams = TestSetup.Parameters; 61 62 if (string.IsNullOrEmpty(testParams.ExeInstallerPath)) 63 { 64 throw new ArgumentNullException($"{Constants.ExeInstallerPathParameter} is required"); 65 } 66 67 if (!File.Exists(testParams.ExeInstallerPath)) 68 { 69 throw new FileNotFoundException(testParams.ExeInstallerPath); 70 } 71 72 if (string.IsNullOrEmpty(testParams.MsiInstallerPath)) 73 { 74 throw new ArgumentNullException($"{Constants.MsiInstallerPathParameter} is required"); 75 } 76 77 if (!File.Exists(testParams.MsiInstallerPath)) 78 { 79 throw new FileNotFoundException(testParams.MsiInstallerPath); 80 } 81 82 if (string.IsNullOrEmpty(testParams.MsiInstallerV2Path)) 83 { 84 throw new ArgumentNullException($"{Constants.MsiInstallerV2PathParameter} is required"); 85 } 86 87 if (!File.Exists(testParams.MsiInstallerV2Path)) 88 { 89 throw new FileNotFoundException(testParams.MsiInstallerV2Path); 90 } 91 92 if (string.IsNullOrEmpty(testParams.MsixInstallerPath)) 93 { 94 throw new ArgumentNullException($"{Constants.MsixInstallerPathParameter} is required"); 95 } 96 97 if (!File.Exists(testParams.MsixInstallerPath)) 98 { 99 throw new FileNotFoundException(testParams.MsixInstallerPath); 100 } 101 102 if (string.IsNullOrEmpty(testParams.PackageCertificatePath)) 103 { 104 throw new ArgumentNullException($"{Constants.PackageCertificatePathParameter} is required"); 105 } 106 107 if (!File.Exists(testParams.PackageCertificatePath)) 108 { 109 throw new FileNotFoundException(testParams.PackageCertificatePath); 110 } 111 112 LocalSource e2eSource = new () 113 { 114 AppxManifest = TestCommon.GetTestDataFile(Path.Combine("Package", "AppxManifest.xml")), 115 WorkingDirectory = testParams.StaticFileRootPath, 116 LocalManifests = new () 117 { 118 TestCommon.GetTestDataFile("Manifests"), 119 }, 120 LocalInstallers = new () 121 { 122 new LocalInstaller 123 { 124 Type = InstallerType.Exe, 125 Name = Path.Combine(Constants.ExeInstaller, Constants.ExeInstallerFileName), 126 Input = testParams.ExeInstallerPath, 127 HashToken = "<EXEHASH>", 128 }, 129 new LocalInstaller 130 { 131 Type = InstallerType.Msi, 132 Name = Path.Combine(Constants.MsiInstaller, Constants.MsiInstallerFileName), 133 Input = testParams.MsiInstallerPath, 134 HashToken = "<MSIHASH>", 135 }, 136 new LocalInstaller 137 { 138 Type = InstallerType.Msi, 139 Name = Path.Combine(Constants.MsiInstaller, Constants.MsiInstallerV2FileName), 140 Input = testParams.MsiInstallerPath, 141 HashToken = "<MSIHASHV2>", 142 }, 143 new LocalInstaller 144 { 145 Type = InstallerType.Msix, 146 Name = Path.Combine(Constants.MsixInstaller, Constants.MsixInstallerFileName), 147 Input = testParams.MsixInstallerPath, 148 HashToken = "<MSIXHASH>", 149 SignatureToken = "<SIGNATUREHASH>", 150 }, 151 }, 152 DynamicInstallers = new () 153 { 154 new DynamicInstaller 155 { 156 Type = InstallerType.Zip, 157 Name = Path.Combine(Constants.ZipInstaller, Constants.ZipInstallerFileName), 158 Input = new () 159 { 160 ExeInstaller, 161 MsiInstaller, 162 MsixInstaller, 163 }, 164 HashToken = "<ZIPHASH>", 165 }, 166 }, 167 Signature = new () 168 { 169 CertFile = testParams.PackageCertificatePath, 170 }, 171 }; 172 173 WinGetLocalSource.CreateLocalSource(e2eSource); 174 } 175 } 176 }