diff options
Diffstat (limited to 'src/WixToolsetTest.BurnE2E/WixTestContext.cs')
-rw-r--r-- | src/WixToolsetTest.BurnE2E/WixTestContext.cs | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/WixToolsetTest.BurnE2E/WixTestContext.cs b/src/WixToolsetTest.BurnE2E/WixTestContext.cs new file mode 100644 index 00000000..97856089 --- /dev/null +++ b/src/WixToolsetTest.BurnE2E/WixTestContext.cs | |||
@@ -0,0 +1,70 @@ | |||
1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
2 | |||
3 | namespace WixToolsetTest.BurnE2E | ||
4 | { | ||
5 | using System; | ||
6 | using System.IO; | ||
7 | using System.Reflection; | ||
8 | using Microsoft.Win32; | ||
9 | using WixBuildTools.TestSupport; | ||
10 | using Xunit.Abstractions; | ||
11 | |||
12 | public class WixTestContext | ||
13 | { | ||
14 | static readonly string RootDataPath = Path.GetFullPath(TestData.Get("..")); | ||
15 | |||
16 | public WixTestContext(ITestOutputHelper testOutputHelper, string testGroupName) | ||
17 | { | ||
18 | var test = GetTest(testOutputHelper); | ||
19 | |||
20 | this.TestDataFolder = Path.Combine(RootDataPath, testGroupName); | ||
21 | this.TestGroupName = testGroupName; | ||
22 | this.TestName = test.TestCase.TestMethod.Method.Name; | ||
23 | } | ||
24 | |||
25 | public string TestDataFolder { get; } | ||
26 | |||
27 | /// <summary> | ||
28 | /// Gets the name of the current test group. | ||
29 | /// </summary> | ||
30 | public string TestGroupName { get; } | ||
31 | |||
32 | public string TestName { get; } | ||
33 | |||
34 | /// <summary> | ||
35 | /// Gets the test install directory for the current test. | ||
36 | /// </summary> | ||
37 | /// <param name="additionalPath">Additional subdirectories under the test install directory.</param> | ||
38 | /// <returns>Full path to the test install directory.</returns> | ||
39 | /// <remarks> | ||
40 | /// The package or bundle must install into [ProgramFilesFolder]\~Test WiX\[TestGroupName]\([Additional]). | ||
41 | /// </remarks> | ||
42 | public string GetTestInstallFolder(string additionalPath = null) | ||
43 | { | ||
44 | return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "~Test WiX", this.TestGroupName, additionalPath ?? String.Empty); | ||
45 | } | ||
46 | |||
47 | /// <summary> | ||
48 | /// Gets the test registry key for the current test. | ||
49 | /// </summary> | ||
50 | /// <param name="additionalPath">Additional subkeys under the test registry key.</param> | ||
51 | /// <returns>Full path to the test registry key.</returns> | ||
52 | /// <remarks> | ||
53 | /// The package must write into HKLM\Software\WiX\Tests\[TestGroupName]\([Additional]). | ||
54 | /// </remarks> | ||
55 | public RegistryKey GetTestRegistryRoot(string additionalPath = null) | ||
56 | { | ||
57 | var key = String.Format(@"Software\WiX\Tests\{0}\{1}", this.TestName, additionalPath ?? String.Empty); | ||
58 | return Registry.LocalMachine.OpenSubKey(key, true); | ||
59 | } | ||
60 | |||
61 | private static ITest GetTest(ITestOutputHelper output) | ||
62 | { | ||
63 | // https://github.com/xunit/xunit/issues/416#issuecomment-378512739 | ||
64 | var type = output.GetType(); | ||
65 | var testMember = type.GetField("test", BindingFlags.Instance | BindingFlags.NonPublic); | ||
66 | var test = (ITest)testMember.GetValue(output); | ||
67 | return test; | ||
68 | } | ||
69 | } | ||
70 | } | ||