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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
// 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 Microsoft.Win32;
using WixTestTools;
using WixToolset.BootstrapperApplicationApi;
public class TestBAController : IDisposable
{
public TestBAController(WixTestContext testContext, bool x64 = false)
{
this.TestGroupName = testContext.TestGroupName;
this.BaseRegKeyPath = x64 ? @"Software\WiX\Tests" : @"Software\WOW6432Node\WiX\Tests";
this.TestBaseRegKeyPath = String.Format(@"{0}\TestBAControl\{1}", this.BaseRegKeyPath, this.TestGroupName);
}
private string BaseRegKeyPath { get; }
private string TestBaseRegKeyPath { get; }
public string TestGroupName { get; }
/// <summary>
/// Sets a test value in the registry to communicate with the TestBA.
/// </summary>
/// <param name="name">Name of the value to set.</param>
/// <param name="value">Value to set. If this is null, the value is removed.</param>
public void SetBurnTestValue(string name, string value)
{
using (var testKey = Registry.LocalMachine.CreateSubKey(this.TestBaseRegKeyPath))
{
if (String.IsNullOrEmpty(value))
{
testKey.DeleteValue(name, false);
}
else
{
testKey.SetValue(name, value);
}
}
}
public void SetAllowAcquireAfterValidationFailure(string value = "true")
{
this.SetBurnTestValue("AllowAcquireAfterValidationFailure", value);
}
public void SetExplicitlyElevateAndPlanFromOnElevateBegin(string value = "true")
{
this.SetBurnTestValue("ExplicitlyElevateAndPlanFromOnElevateBegin", value);
}
public void SetForceKeepRegistration(string value = "true")
{
this.SetBurnTestValue("ForceKeepRegistration", value);
}
public void SetImmediatelyQuit(string value = "true")
{
this.SetBurnTestValue("ImmediatelyQuit", value);
}
public void SetQuitAfterDetect(string value = "true")
{
this.SetBurnTestValue("QuitAfterDetect", value);
}
/// <summary>
/// Slows the cache progress of a package.
/// </summary>
/// <param name="packageId">Package identity.</param>
/// <param name="delay">Sets or removes the delay on a package being cached.</param>
public void SetPackageSlowCache(string packageId, int? delay)
{
this.SetPackageState(packageId, "SlowCache", delay.HasValue ? delay.ToString() : null);
}
/// <summary>
/// Cancels the cache of a package at a particular progress point.
/// </summary>
/// <param name="packageId">Package identity.</param>
/// <param name="cancelPoint">Sets or removes the cancel progress on a package being cached.</param>
public void SetPackageCancelCacheAtProgress(string packageId, int? cancelPoint)
{
this.SetPackageState(packageId, "CancelCacheAtProgress", cancelPoint.HasValue ? cancelPoint.ToString() : null);
}
/// <summary>
/// Slows the execute progress of a package.
/// </summary>
/// <param name="packageId">Package identity.</param>
/// <param name="delay">Sets or removes the delay on a package being executed.</param>
public void SetPackageSlowExecute(string packageId, int? delay)
{
this.SetPackageState(packageId, "SlowExecute", delay.HasValue ? delay.ToString() : null);
}
/// <summary>
/// Cancels the execute of a package at a particular progress point.
/// </summary>
/// <param name="packageId">Package identity.</param>
/// <param name="cancelPoint">Sets or removes the cancel progress on a package being executed.</param>
public void SetPackageCancelExecuteAtProgress(string packageId, int? cancelPoint)
{
this.SetPackageState(packageId, "CancelExecuteAtProgress", cancelPoint.HasValue ? cancelPoint.ToString() : null);
}
/// <summary>
/// Cancels the execute of a package at the next progess after the specified MSI action start.
/// </summary>
/// <param name="packageId">Package identity.</param>
/// <param name="actionName">Sets or removes the cancel progress on a package being executed.</param>
public void SetPackageCancelExecuteAtActionStart(string packageId, string actionName)
{
this.SetPackageState(packageId, "CancelExecuteAtActionStart", actionName);
}
/// <summary>
/// Cancels the execute of a package at a particular OnProgress point.
/// </summary>
/// <param name="packageId">Package identity.</param>
/// <param name="cancelPoint">Sets or removes the cancel OnProgress point on a package being executed.</param>
public void SetPackageCancelOnProgressAtProgress(string packageId, int? cancelPoint)
{
this.SetPackageState(packageId, "CancelOnProgressAtProgress", cancelPoint.HasValue ? cancelPoint.ToString() : null);
}
/// <summary>
/// Retries the files in use one or more times before canceling.
/// </summary>
/// <param name="packageId">Package identity.</param>
/// <param name="cancelPoint">Sets or removes the retry count on a package's file in use message.</param>
public void SetPackageRetryExecuteFilesInUse(string packageId, int? retryCount)
{
this.SetPackageState(packageId, "RetryExecuteFilesInUse", retryCount.HasValue ? retryCount.ToString() : null);
}
/// <summary>
/// Sets the requested cache type for a package that the TestBA will return to the engine during plan.
/// </summary>
/// <param name="packageId">Package identity.</param>
/// <param name="type">Cache type to request.</param>
public void SetPackageRequestedCacheType(string packageId, BOOTSTRAPPER_CACHE_TYPE type)
{
this.SetPackageState(packageId, "CacheRequested", type.ToString());
}
/// <summary>
/// Sets the requested state for a package that the TestBA will return to the engine during plan.
/// </summary>
/// <param name="packageId">Package identity.</param>
/// <param name="state">State to request.</param>
public void SetPackageRequestedState(string packageId, RequestState state)
{
this.SetPackageState(packageId, "Requested", state.ToString());
}
/// <summary>
/// Sets the requested state for a package that the TestBA will return to the engine during plan.
/// </summary>
/// <param name="packageId">Package identity.</param>
/// <param name="state">State to request.</param>
public void SetPackageFeatureState(string packageId, string featureId, FeatureState state)
{
this.SetPackageState(packageId, String.Concat(featureId, "Requested"), state.ToString());
}
/// <summary>
/// Requests the BA to log the test registry value for the specified package.
/// </summary>
/// <param name="packageId"></param>
/// <param name="value"></param>
public void SetPackageRecordTestRegistryValue(string packageId, string value = "true")
{
this.SetPackageState(packageId, "RecordTestRegistryValue", value);
}
public void SetPackageProcessCancelAction(string packageId, BOOTSTRAPPER_EXECUTEPROCESSCANCEL_ACTION action)
{
this.SetPackageState(packageId, "ProcessCancelAction", action.ToString());
}
/// <summary>
/// At startup, set the payload's source path to the given path.
/// </summary>
/// <param name="payloadId"></param>
/// <param name="sourcePath"></param>
public void SetPayloadInitialLocalSource(string payloadId, string sourcePath)
{
this.SetPayloadState(payloadId, "InitialLocalSource", sourcePath);
}
/// <summary>
/// At startup, set the container's source path to the given path.
/// </summary>
/// <param name="containerId"></param>
/// <param name="sourcePath"></param>
public void SetContainerInitialLocalSource(string containerId, string sourcePath)
{
this.SetContainerState(containerId, "InitialLocalSource", sourcePath);
}
/// <summary>
/// Sets the number of times to re-run the Detect phase.
/// </summary>
/// <param name="state">Number of times to run Detect (after the first, normal, Detect).</param>
public void SetRedetectCount(int redetectCount)
{
this.SetPackageState(null, "RedetectCount", redetectCount.ToString());
}
/// <summary>
/// Resets the state for a package that the TestBA will return to the engine during plan.
/// </summary>
/// <param name="packageId">Package identity.</param>
public void ResetPackageStates(string packageId)
{
var key = String.Format(@"{0}\{1}", this.TestBaseRegKeyPath, packageId ?? String.Empty);
Registry.LocalMachine.DeleteSubKey(key);
}
public void SetVerifyArguments(string verifyArguments)
{
this.SetBurnTestValue("VerifyArguments", verifyArguments);
}
private void SetPackageState(string packageId, string name, string value)
{
var key = String.Format(@"{0}\{1}", this.TestBaseRegKeyPath, packageId ?? String.Empty);
using (var packageKey = Registry.LocalMachine.CreateSubKey(key))
{
if (String.IsNullOrEmpty(value))
{
packageKey.DeleteValue(name, false);
}
else
{
packageKey.SetValue(name, value);
}
}
}
private void SetContainerState(string containerId, string name, string value)
{
var key = String.Format(@"{0}\container\{1}", this.TestBaseRegKeyPath, containerId);
using (var containerKey = Registry.LocalMachine.CreateSubKey(key))
{
if (String.IsNullOrEmpty(value))
{
containerKey.DeleteValue(name, false);
}
else
{
containerKey.SetValue(name, value);
}
}
}
private void SetPayloadState(string payloadId, string name, string value)
{
var key = String.Format(@"{0}\payload\{1}", this.TestBaseRegKeyPath, payloadId ?? String.Empty);
using (var payloadKey = Registry.LocalMachine.CreateSubKey(key))
{
if (String.IsNullOrEmpty(value))
{
payloadKey.DeleteValue(name, false);
}
else
{
payloadKey.SetValue(name, value);
}
}
}
public void Dispose()
{
Registry.LocalMachine.DeleteSubKeyTree($@"{this.BaseRegKeyPath}\{this.TestGroupName}", false);
Registry.LocalMachine.DeleteSubKeyTree($@"{this.BaseRegKeyPath}\TestBAControl", false);
}
}
}
|