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