diff options
Diffstat (limited to 'src/test/burn/TestBA/TestBA.cs')
-rw-r--r-- | src/test/burn/TestBA/TestBA.cs | 60 |
1 files changed, 37 insertions, 23 deletions
diff --git a/src/test/burn/TestBA/TestBA.cs b/src/test/burn/TestBA/TestBA.cs index 43c1584b..8a116957 100644 --- a/src/test/burn/TestBA/TestBA.cs +++ b/src/test/burn/TestBA/TestBA.cs | |||
@@ -42,17 +42,15 @@ namespace WixToolset.Test.BA | |||
42 | private int retryExecuteFilesInUse; | 42 | private int retryExecuteFilesInUse; |
43 | private bool rollingBack; | 43 | private bool rollingBack; |
44 | 44 | ||
45 | private IBootstrapperCommand Command { get; } | 45 | private IBootstrapperCommand Command { get; set; } |
46 | 46 | ||
47 | private IEngine Engine => this.engine; | 47 | private IEngine Engine => this.engine; |
48 | 48 | ||
49 | /// <summary> | 49 | /// <summary> |
50 | /// Initializes test user experience. | 50 | /// Initializes test user experience. |
51 | /// </summary> | 51 | /// </summary> |
52 | public TestBA(IEngine engine, IBootstrapperCommand bootstrapperCommand) | 52 | public TestBA() |
53 | : base(engine) | ||
54 | { | 53 | { |
55 | this.Command = bootstrapperCommand; | ||
56 | this.wait = new ManualResetEvent(false); | 54 | this.wait = new ManualResetEvent(false); |
57 | } | 55 | } |
58 | 56 | ||
@@ -66,6 +64,12 @@ namespace WixToolset.Test.BA | |||
66 | /// </summary> | 64 | /// </summary> |
67 | private bool UpdateAvailable { get; set; } | 65 | private bool UpdateAvailable { get; set; } |
68 | 66 | ||
67 | protected override void OnCreate(CreateEventArgs args) | ||
68 | { | ||
69 | base.OnCreate(args); | ||
70 | this.Command = args.Command; | ||
71 | } | ||
72 | |||
69 | /// <summary> | 73 | /// <summary> |
70 | /// UI Thread entry point for TestUX. | 74 | /// UI Thread entry point for TestUX. |
71 | /// </summary> | 75 | /// </summary> |
@@ -97,7 +101,7 @@ namespace WixToolset.Test.BA | |||
97 | { | 101 | { |
98 | this.updateBundlePath = arg.Substring(14); | 102 | this.updateBundlePath = arg.Substring(14); |
99 | FileInfo info = new FileInfo(this.updateBundlePath); | 103 | FileInfo info = new FileInfo(this.updateBundlePath); |
100 | this.Engine.SetUpdate(this.updateBundlePath, null, info.Length, UpdateHashType.None, null); | 104 | this.Engine.SetUpdate(this.updateBundlePath, null, info.Length, UpdateHashType.None, null, null); |
101 | this.UpdateAvailable = true; | 105 | this.UpdateAvailable = true; |
102 | this.action = LaunchAction.UpdateReplaceEmbedded; | 106 | this.action = LaunchAction.UpdateReplaceEmbedded; |
103 | } | 107 | } |
@@ -124,9 +128,8 @@ namespace WixToolset.Test.BA | |||
124 | 128 | ||
125 | base.OnStartup(args); | 129 | base.OnStartup(args); |
126 | 130 | ||
127 | int redetectCount; | ||
128 | string redetect = this.ReadPackageAction(null, "RedetectCount"); | 131 | string redetect = this.ReadPackageAction(null, "RedetectCount"); |
129 | if (String.IsNullOrEmpty(redetect) || !Int32.TryParse(redetect, out redetectCount)) | 132 | if (String.IsNullOrEmpty(redetect) || !Int32.TryParse(redetect, out var redetectCount)) |
130 | { | 133 | { |
131 | redetectCount = 0; | 134 | redetectCount = 0; |
132 | } | 135 | } |
@@ -163,7 +166,7 @@ namespace WixToolset.Test.BA | |||
163 | if (this.action == LaunchAction.Help) | 166 | if (this.action == LaunchAction.Help) |
164 | { | 167 | { |
165 | this.Log("This is a BA for automated testing"); | 168 | this.Log("This is a BA for automated testing"); |
166 | this.Engine.Quit(0); | 169 | this.ShutdownUiThread(0); |
167 | return; | 170 | return; |
168 | } | 171 | } |
169 | 172 | ||
@@ -176,20 +179,15 @@ namespace WixToolset.Test.BA | |||
176 | 179 | ||
177 | protected override void Run() | 180 | protected override void Run() |
178 | { | 181 | { |
179 | this.dummyWindow = new Form(); | 182 | using (this.dummyWindow = new Form()) |
180 | this.windowHandle = this.dummyWindow.Handle; | 183 | { |
184 | this.windowHandle = this.dummyWindow.Handle; | ||
181 | 185 | ||
182 | this.Log("Running TestBA application"); | 186 | this.Log("Running TestBA application"); |
183 | this.wait.Set(); | 187 | this.wait.Set(); |
184 | Application.Run(); | ||
185 | } | ||
186 | 188 | ||
187 | private void ShutdownUiThread() | 189 | Application.Run(); |
188 | { | 190 | this.dummyWindow = null; |
189 | if (this.dummyWindow != null) | ||
190 | { | ||
191 | this.dummyWindow.Invoke(new Action(Application.ExitThread)); | ||
192 | this.dummyWindow.Dispose(); | ||
193 | } | 191 | } |
194 | 192 | ||
195 | var exitCode = this.result; | 193 | var exitCode = this.result; |
@@ -201,6 +199,23 @@ namespace WixToolset.Test.BA | |||
201 | this.Engine.Quit(exitCode); | 199 | this.Engine.Quit(exitCode); |
202 | } | 200 | } |
203 | 201 | ||
202 | private void ShutdownUiThread(int? exitCode = null) | ||
203 | { | ||
204 | try | ||
205 | { | ||
206 | if (exitCode.HasValue) | ||
207 | { | ||
208 | this.result = exitCode.Value; | ||
209 | } | ||
210 | |||
211 | this.dummyWindow?.Invoke(new Action(Application.ExitThread)); | ||
212 | } | ||
213 | catch (Exception e) | ||
214 | { | ||
215 | this.Log("Failed to shutdown TestBA window, exception: {0}", e.Message); | ||
216 | } | ||
217 | } | ||
218 | |||
204 | protected override void OnDetectUpdateBegin(DetectUpdateBeginEventArgs args) | 219 | protected override void OnDetectUpdateBegin(DetectUpdateBeginEventArgs args) |
205 | { | 220 | { |
206 | this.Log("OnDetectUpdateBegin"); | 221 | this.Log("OnDetectUpdateBegin"); |
@@ -220,7 +235,7 @@ namespace WixToolset.Test.BA | |||
220 | if (!this.UpdateAvailable && this.Engine.CompareVersions(e.Version, this.Version) > 0) | 235 | if (!this.UpdateAvailable && this.Engine.CompareVersions(e.Version, this.Version) > 0) |
221 | { | 236 | { |
222 | this.Log(String.Format("Selected update v{0}", e.Version)); | 237 | this.Log(String.Format("Selected update v{0}", e.Version)); |
223 | this.Engine.SetUpdate(null, e.UpdateLocation, e.Size, e.HashAlgorithm, e.Hash); | 238 | this.Engine.SetUpdate(null, e.UpdateLocation, e.Size, e.HashAlgorithm, e.Hash, null); |
224 | this.UpdateAvailable = true; | 239 | this.UpdateAvailable = true; |
225 | } | 240 | } |
226 | } | 241 | } |
@@ -575,8 +590,7 @@ namespace WixToolset.Test.BA | |||
575 | // Output what the privileges are now. | 590 | // Output what the privileges are now. |
576 | this.Log("After elevation: WixBundleElevated = {0}", this.Engine.GetVariableNumeric("WixBundleElevated")); | 591 | this.Log("After elevation: WixBundleElevated = {0}", this.Engine.GetVariableNumeric("WixBundleElevated")); |
577 | 592 | ||
578 | this.result = args.Status; | 593 | this.ShutdownUiThread(args.Status); |
579 | this.ShutdownUiThread(); | ||
580 | } | 594 | } |
581 | 595 | ||
582 | protected override void OnUnregisterBegin(UnregisterBeginEventArgs args) | 596 | protected override void OnUnregisterBegin(UnregisterBeginEventArgs args) |