|
2 | 2 | using GeneralUpdate.Bowl; |
3 | 3 | using GeneralUpdate.Bowl.Internal; |
4 | 4 | using GeneralUpdate.Bowl.Strategies; |
5 | | -using GeneralUpdate.Bowl.Strategys; |
6 | 5 | using BowlTest.Utilities; |
7 | 6 |
|
8 | 7 | /// <summary> |
|
16 | 15 | /// - HandleCrashAsync: skip restore when conditions not met |
17 | 16 | /// - HandleCrashAsync: OnCrash callback with valid path -> invoked |
18 | 17 | /// - HandleCrashAsync: OnCrash callback throws -> swallowed |
19 | | -/// - MapToContext: all fields mapped correctly |
20 | | -/// - CreateParameter: env var not set/empty/whitespace/invalid -> ArgumentNullException |
21 | | -/// - CreateParameter: valid JSON -> correct MonitorParameter |
22 | 18 | /// </summary> |
23 | 19 | public class BowlTests |
24 | 20 | { |
25 | 21 | private readonly FakeBowlStrategy _strategy; |
26 | 22 | private readonly FakeCrashReporter _reporter; |
27 | 23 | private readonly FakeSystemInfoProvider _sysInfo; |
28 | | - private readonly FakeEnvironmentProvider _env; |
29 | 24 |
|
30 | 25 | public BowlTests() |
31 | 26 | { |
32 | 27 | _strategy = new FakeBowlStrategy(); |
33 | 28 | _reporter = new FakeCrashReporter(); |
34 | 29 | _sysInfo = new FakeSystemInfoProvider(); |
35 | | - _env = new FakeEnvironmentProvider(); |
36 | 30 | } |
37 | 31 |
|
38 | 32 | private Bowl CreateBowl() => |
39 | | - new Bowl(_strategy, _reporter, _sysInfo, _env); |
| 33 | + new Bowl(_strategy, _reporter, _sysInfo); |
40 | 34 |
|
41 | 35 | private static BowlContext CreateValidContext( |
42 | 36 | string processName = "test.exe", |
@@ -70,34 +64,26 @@ public void Constructor_AllArgsValid_DoesNotThrow() |
70 | 64 | public void Constructor_StrategyNull_ThrowsArgumentNullException() |
71 | 65 | { |
72 | 66 | var ex = Assert.Throws<ArgumentNullException>(() => |
73 | | - new Bowl(null!, _reporter, _sysInfo, _env)); |
| 67 | + new Bowl(null!, _reporter, _sysInfo)); |
74 | 68 | Assert.Equal("strategy", ex.ParamName); |
75 | 69 | } |
76 | 70 |
|
77 | 71 | [Fact] |
78 | 72 | public void Constructor_CrashReporterNull_ThrowsArgumentNullException() |
79 | 73 | { |
80 | 74 | var ex = Assert.Throws<ArgumentNullException>(() => |
81 | | - new Bowl(_strategy, null!, _sysInfo, _env)); |
| 75 | + new Bowl(_strategy, null!, _sysInfo)); |
82 | 76 | Assert.Equal("crashReporter", ex.ParamName); |
83 | 77 | } |
84 | 78 |
|
85 | 79 | [Fact] |
86 | 80 | public void Constructor_SystemInfoProviderNull_ThrowsArgumentNullException() |
87 | 81 | { |
88 | 82 | var ex = Assert.Throws<ArgumentNullException>(() => |
89 | | - new Bowl(_strategy, _reporter, null!, _env)); |
| 83 | + new Bowl(_strategy, _reporter, null!)); |
90 | 84 | Assert.Equal("systemInfoProvider", ex.ParamName); |
91 | 85 | } |
92 | 86 |
|
93 | | - [Fact] |
94 | | - public void Constructor_EnvNull_ThrowsArgumentNullException() |
95 | | - { |
96 | | - var ex = Assert.Throws<ArgumentNullException>(() => |
97 | | - new Bowl(_strategy, _reporter, _sysInfo, null!)); |
98 | | - Assert.Equal("env", ex.ParamName); |
99 | | - } |
100 | | - |
101 | 87 | // ---- LaunchAsync: Strategy returns null ---- |
102 | 88 |
|
103 | 89 | [Fact] |
@@ -145,7 +131,6 @@ await Assert.ThrowsAnyAsync<OperationCanceledException>(() => |
145 | 131 | [Fact] |
146 | 132 | public async Task LaunchAsync_ProcessTimeout_ReturnsFailedResult() |
147 | 133 | { |
148 | | - // Use a short timeout to trigger timeout |
149 | 134 | _strategy.PrepareResult = new ProcessStartInfo |
150 | 135 | { |
151 | 136 | FileName = "cmd.exe", |
@@ -264,155 +249,6 @@ public async Task LaunchAsync_CrashDetected_HandleCrashInvoked() |
264 | 249 | } |
265 | 250 | } |
266 | 251 |
|
267 | | - // ---- MapToContext ---- |
268 | | - |
269 | | - [Fact] |
270 | | - public void MapToContext_ConvertsAllFields_CorrectValues() |
271 | | - { |
272 | | - var param = new MonitorParameter |
273 | | - { |
274 | | - ProcessNameOrId = "myapp.exe", |
275 | | - DumpFileName = "v2_fail.dmp", |
276 | | - FailFileName = "v2_fail.json", |
277 | | - TargetPath = "C:\\app", |
278 | | - FailDirectory = "C:\\app\\fail\\v2", |
279 | | - BackupDirectory = "C:\\app\\v2", |
280 | | - WorkModel = "Normal", |
281 | | - ExtendedField = "2.0.0", |
282 | | - }; |
283 | | - |
284 | | - var ctx = Bowl.MapToContext(param); |
285 | | - |
286 | | - Assert.Equal("myapp.exe", ctx.ProcessNameOrId); |
287 | | - Assert.Equal("v2_fail.dmp", ctx.DumpFileName); |
288 | | - Assert.Equal("v2_fail.json", ctx.FailFileName); |
289 | | - Assert.Equal("C:\\app", ctx.TargetPath); |
290 | | - Assert.Equal("C:\\app\\fail\\v2", ctx.FailDirectory); |
291 | | - Assert.Equal("C:\\app\\v2", ctx.BackupDirectory); |
292 | | - Assert.Equal("Normal", ctx.WorkModel); |
293 | | - Assert.Equal("2.0.0", ctx.ExtendedField); |
294 | | - Assert.Equal(30_000, ctx.TimeoutMs); |
295 | | - Assert.Equal(DumpType.Full, ctx.DumpType); |
296 | | - Assert.True(ctx.AutoRestore); |
297 | | - } |
298 | | - |
299 | | - [Fact] |
300 | | - public void MapToContext_TimeoutMsFixedAt30000() |
301 | | - { |
302 | | - var param = new MonitorParameter { ProcessNameOrId = "test" }; |
303 | | - var ctx = Bowl.MapToContext(param); |
304 | | - Assert.Equal(30_000, ctx.TimeoutMs); |
305 | | - } |
306 | | - |
307 | | - [Fact] |
308 | | - public void MapToContext_DumpTypeFixedAtFull() |
309 | | - { |
310 | | - var param = new MonitorParameter { ProcessNameOrId = "test" }; |
311 | | - var ctx = Bowl.MapToContext(param); |
312 | | - Assert.Equal(DumpType.Full, ctx.DumpType); |
313 | | - } |
314 | | - |
315 | | - [Fact] |
316 | | - public void MapToContext_AutoRestoreFixedAtTrue() |
317 | | - { |
318 | | - var param = new MonitorParameter { ProcessNameOrId = "test" }; |
319 | | - var ctx = Bowl.MapToContext(param); |
320 | | - Assert.True(ctx.AutoRestore); |
321 | | - } |
322 | | - |
323 | | - // ---- CreateParameter: Env var not set ---- |
324 | | - |
325 | | - [Fact] |
326 | | - public void CreateParameter_EnvVarNotSet_ThrowsArgumentNullException() |
327 | | - { |
328 | | - var oldValue = Environment.GetEnvironmentVariable("ProcessInfo", EnvironmentVariableTarget.Process); |
329 | | - try |
330 | | - { |
331 | | - Environment.SetEnvironmentVariable("ProcessInfo", null, EnvironmentVariableTarget.Process); |
332 | | - var ex = Assert.Throws<ArgumentNullException>(() => Bowl.CreateParameter()); |
333 | | - Assert.Contains("ProcessInfo", ex.Message); |
334 | | - } |
335 | | - finally |
336 | | - { |
337 | | - Environment.SetEnvironmentVariable("ProcessInfo", oldValue, EnvironmentVariableTarget.Process); |
338 | | - } |
339 | | - } |
340 | | - |
341 | | - [Fact] |
342 | | - public void CreateParameter_EnvVarEmpty_ThrowsArgumentNullException() |
343 | | - { |
344 | | - var oldValue = Environment.GetEnvironmentVariable("ProcessInfo", EnvironmentVariableTarget.Process); |
345 | | - try |
346 | | - { |
347 | | - Environment.SetEnvironmentVariable("ProcessInfo", string.Empty, EnvironmentVariableTarget.Process); |
348 | | - var ex = Assert.Throws<ArgumentNullException>(() => Bowl.CreateParameter()); |
349 | | - Assert.Contains("ProcessInfo", ex.Message); |
350 | | - } |
351 | | - finally |
352 | | - { |
353 | | - Environment.SetEnvironmentVariable("ProcessInfo", oldValue, EnvironmentVariableTarget.Process); |
354 | | - } |
355 | | - } |
356 | | - |
357 | | - [Fact] |
358 | | - public void CreateParameter_EnvVarWhitespace_ThrowsArgumentNullException() |
359 | | - { |
360 | | - var oldValue = Environment.GetEnvironmentVariable("ProcessInfo", EnvironmentVariableTarget.Process); |
361 | | - try |
362 | | - { |
363 | | - Environment.SetEnvironmentVariable("ProcessInfo", " ", EnvironmentVariableTarget.Process); |
364 | | - var ex = Assert.Throws<ArgumentNullException>(() => Bowl.CreateParameter()); |
365 | | - Assert.Contains("ProcessInfo", ex.Message); |
366 | | - } |
367 | | - finally |
368 | | - { |
369 | | - Environment.SetEnvironmentVariable("ProcessInfo", oldValue, EnvironmentVariableTarget.Process); |
370 | | - } |
371 | | - } |
372 | | - |
373 | | - [Fact] |
374 | | - public void CreateParameter_InvalidJson_ThrowsArgumentNullException() |
375 | | - { |
376 | | - var oldValue = Environment.GetEnvironmentVariable("ProcessInfo", EnvironmentVariableTarget.Process); |
377 | | - try |
378 | | - { |
379 | | - Environment.SetEnvironmentVariable("ProcessInfo", "not valid json", EnvironmentVariableTarget.Process); |
380 | | - var ex = Assert.Throws<ArgumentNullException>(() => Bowl.CreateParameter()); |
381 | | - Assert.Contains("ProcessInfo", ex.Message); |
382 | | - } |
383 | | - finally |
384 | | - { |
385 | | - Environment.SetEnvironmentVariable("ProcessInfo", oldValue, EnvironmentVariableTarget.Process); |
386 | | - } |
387 | | - } |
388 | | - |
389 | | - [Fact] |
390 | | - public void CreateParameter_ValidJson_ReturnsCorrectMonitorParameter() |
391 | | - { |
392 | | - var oldValue = Environment.GetEnvironmentVariable("ProcessInfo", EnvironmentVariableTarget.Process); |
393 | | - var tempDir = Path.Combine(Path.GetTempPath(), $"BowlTest_App_{Guid.NewGuid():N}"); |
394 | | - try |
395 | | - { |
396 | | - Environment.SetEnvironmentVariable("ProcessInfo", |
397 | | - $"{{\"AppName\":\"myapp.exe\",\"LastVersion\":\"2.5.0\",\"InstallPath\":\"{tempDir.Replace("\\", "\\\\")}\"}}", |
398 | | - EnvironmentVariableTarget.Process); |
399 | | - |
400 | | - var param = Bowl.CreateParameter(); |
401 | | - |
402 | | - Assert.Equal("myapp.exe", param.ProcessNameOrId); |
403 | | - Assert.Equal("2.5.0_fail.dmp", param.DumpFileName); |
404 | | - Assert.Equal("2.5.0_fail.json", param.FailFileName); |
405 | | - Assert.Equal(tempDir, param.TargetPath); |
406 | | - Assert.Equal("2.5.0", param.ExtendedField); |
407 | | - Assert.Equal(Path.Combine(tempDir, "fail", "2.5.0"), param.FailDirectory); |
408 | | - Assert.Equal(Path.Combine(tempDir, "2.5.0"), param.BackupDirectory); |
409 | | - } |
410 | | - finally |
411 | | - { |
412 | | - Environment.SetEnvironmentVariable("ProcessInfo", oldValue, EnvironmentVariableTarget.Process); |
413 | | - } |
414 | | - } |
415 | | - |
416 | 252 | // ---- HandleCrashAsync: All steps success ---- |
417 | 253 |
|
418 | 254 | [Fact] |
@@ -566,11 +402,8 @@ public async Task HandleCrashAsync_SkipRestoreConditions(string workModel, bool |
566 | 402 | var result = await bowl.LaunchAsync(ctx); |
567 | 403 |
|
568 | 404 | Assert.True(result.DumpCaptured); |
569 | | - // For Normal mode, UpgradeFail should NOT be set |
570 | | - if (workModel != "Upgrade") |
571 | | - { |
572 | | - Assert.False(_env.SetVariableCalled); |
573 | | - } |
| 405 | + // Restore should NOT happen for Normal mode or Upgrade with AutoRestore=false |
| 406 | + Assert.False(result.Restored); |
574 | 407 | } |
575 | 408 | finally |
576 | 409 | { |
|
0 commit comments