aboutsummaryrefslogtreecommitdiff
path: root/src/test/burn/WixToolsetTest.BurnE2E/TestBAController.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/burn/WixToolsetTest.BurnE2E/TestBAController.cs')
-rw-r--r--src/test/burn/WixToolsetTest.BurnE2E/TestBAController.cs187
1 files changed, 187 insertions, 0 deletions
diff --git a/src/test/burn/WixToolsetTest.BurnE2E/TestBAController.cs b/src/test/burn/WixToolsetTest.BurnE2E/TestBAController.cs
new file mode 100644
index 00000000..6e4fe6c6
--- /dev/null
+++ b/src/test/burn/WixToolsetTest.BurnE2E/TestBAController.cs
@@ -0,0 +1,187 @@
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
3namespace WixToolsetTest.BurnE2E
4{
5 using System;
6 using Microsoft.Win32;
7 using WixTestTools;
8 using WixToolset.Mba.Core;
9
10 public class TestBAController : IDisposable
11 {
12 public TestBAController(WixTestContext testContext, bool x64 = false)
13 {
14 this.TestGroupName = testContext.TestGroupName;
15 this.BaseRegKeyPath = x64 ? @"Software\WiX\Tests" : @"Software\WOW6432Node\WiX\Tests";
16 this.TestBaseRegKeyPath = String.Format(@"{0}\TestBAControl\{1}", this.BaseRegKeyPath, this.TestGroupName);
17 }
18
19 private string BaseRegKeyPath { get; }
20
21 private string TestBaseRegKeyPath { get; }
22
23 public string TestGroupName { get; }
24
25 /// <summary>
26 /// Sets a test value in the registry to communicate with the TestBA.
27 /// </summary>
28 /// <param name="name">Name of the value to set.</param>
29 /// <param name="value">Value to set. If this is null, the value is removed.</param>
30 public void SetBurnTestValue(string name, string value)
31 {
32 using (var testKey = Registry.LocalMachine.CreateSubKey(this.TestBaseRegKeyPath))
33 {
34 if (String.IsNullOrEmpty(value))
35 {
36 testKey.DeleteValue(name, false);
37 }
38 else
39 {
40 testKey.SetValue(name, value);
41 }
42 }
43 }
44
45 public void SetExplicitlyElevateAndPlanFromOnElevateBegin(string value = "true")
46 {
47 this.SetBurnTestValue("ExplicitlyElevateAndPlanFromOnElevateBegin", value);
48 }
49
50 public void SetImmediatelyQuit(string value = "true")
51 {
52 this.SetBurnTestValue("ImmediatelyQuit", value);
53 }
54
55 public void SetQuitAfterDetect(string value = "true")
56 {
57 this.SetBurnTestValue("QuitAfterDetect", value);
58 }
59
60 /// <summary>
61 /// Slows the cache progress of a package.
62 /// </summary>
63 /// <param name="packageId">Package identity.</param>
64 /// <param name="delay">Sets or removes the delay on a package being cached.</param>
65 public void SetPackageSlowCache(string packageId, int? delay)
66 {
67 this.SetPackageState(packageId, "SlowCache", delay.HasValue ? delay.ToString() : null);
68 }
69
70 /// <summary>
71 /// Cancels the cache of a package at a particular progress point.
72 /// </summary>
73 /// <param name="packageId">Package identity.</param>
74 /// <param name="cancelPoint">Sets or removes the cancel progress on a package being cached.</param>
75 public void SetPackageCancelCacheAtProgress(string packageId, int? cancelPoint)
76 {
77 this.SetPackageState(packageId, "CancelCacheAtProgress", cancelPoint.HasValue ? cancelPoint.ToString() : null);
78 }
79
80 /// <summary>
81 /// Slows the execute progress of a package.
82 /// </summary>
83 /// <param name="packageId">Package identity.</param>
84 /// <param name="delay">Sets or removes the delay on a package being executed.</param>
85 public void SetPackageSlowExecute(string packageId, int? delay)
86 {
87 this.SetPackageState(packageId, "SlowExecute", delay.HasValue ? delay.ToString() : null);
88 }
89
90 /// <summary>
91 /// Cancels the execute of a package at a particular progress point.
92 /// </summary>
93 /// <param name="packageId">Package identity.</param>
94 /// <param name="cancelPoint">Sets or removes the cancel progress on a package being executed.</param>
95 public void SetPackageCancelExecuteAtProgress(string packageId, int? cancelPoint)
96 {
97 this.SetPackageState(packageId, "CancelExecuteAtProgress", cancelPoint.HasValue ? cancelPoint.ToString() : null);
98 }
99
100 /// <summary>
101 /// Cancels the execute of a package at the next progess after the specified MSI action start.
102 /// </summary>
103 /// <param name="packageId">Package identity.</param>
104 /// <param name="actionName">Sets or removes the cancel progress on a package being executed.</param>
105 public void SetPackageCancelExecuteAtActionStart(string packageId, string actionName)
106 {
107 this.SetPackageState(packageId, "CancelExecuteAtActionStart", actionName);
108 }
109
110 /// <summary>
111 /// Cancels the execute of a package at a particular OnProgress point.
112 /// </summary>
113 /// <param name="packageId">Package identity.</param>
114 /// <param name="cancelPoint">Sets or removes the cancel OnProgress point on a package being executed.</param>
115 public void SetPackageCancelOnProgressAtProgress(string packageId, int? cancelPoint)
116 {
117 this.SetPackageState(packageId, "CancelOnProgressAtProgress", cancelPoint.HasValue ? cancelPoint.ToString() : null);
118 }
119
120 /// <summary>
121 /// Sets the requested state for a package that the TestBA will return to the engine during plan.
122 /// </summary>
123 /// <param name="packageId">Package identity.</param>
124 /// <param name="state">State to request.</param>
125 public void SetPackageRequestedState(string packageId, RequestState state)
126 {
127 this.SetPackageState(packageId, "Requested", state.ToString());
128 }
129
130 /// <summary>
131 /// Sets the requested state for a package that the TestBA will return to the engine during plan.
132 /// </summary>
133 /// <param name="packageId">Package identity.</param>
134 /// <param name="state">State to request.</param>
135 public void SetPackageFeatureState(string packageId, string featureId, FeatureState state)
136 {
137 this.SetPackageState(packageId, String.Concat(featureId, "Requested"), state.ToString());
138 }
139
140 /// <summary>
141 /// Sets the number of times to re-run the Detect phase.
142 /// </summary>
143 /// <param name="state">Number of times to run Detect (after the first, normal, Detect).</param>
144 public void SetRedetectCount(int redetectCount)
145 {
146 this.SetPackageState(null, "RedetectCount", redetectCount.ToString());
147 }
148
149 /// <summary>
150 /// Resets the state for a package that the TestBA will return to the engine during plan.
151 /// </summary>
152 /// <param name="packageId">Package identity.</param>
153 public void ResetPackageStates(string packageId)
154 {
155 var key = String.Format(@"{0}\{1}", this.TestBaseRegKeyPath, packageId ?? String.Empty);
156 Registry.LocalMachine.DeleteSubKey(key);
157 }
158
159 public void SetVerifyArguments(string verifyArguments)
160 {
161 this.SetBurnTestValue("VerifyArguments", verifyArguments);
162
163 }
164
165 private void SetPackageState(string packageId, string name, string value)
166 {
167 var key = String.Format(@"{0}\{1}", this.TestBaseRegKeyPath, packageId ?? String.Empty);
168 using (var packageKey = Registry.LocalMachine.CreateSubKey(key))
169 {
170 if (String.IsNullOrEmpty(value))
171 {
172 packageKey.DeleteValue(name, false);
173 }
174 else
175 {
176 packageKey.SetValue(name, value);
177 }
178 }
179 }
180
181 public void Dispose()
182 {
183 Registry.LocalMachine.DeleteSubKeyTree($@"{this.BaseRegKeyPath}\{this.TestGroupName}", false);
184 Registry.LocalMachine.DeleteSubKeyTree($@"{this.BaseRegKeyPath}\TestBAControl", false);
185 }
186 }
187}