|
4 | 4 | using FolderDiffIL4DotNet.Common; |
5 | 5 | using FolderDiffIL4DotNet.Models; |
6 | 6 | using FolderDiffIL4DotNet.Services; |
| 7 | +using FolderDiffIL4DotNet.Services.Caching; |
7 | 8 | using Xunit; |
8 | 9 |
|
9 | 10 | namespace FolderDiffIL4DotNet.Tests.Services |
@@ -410,6 +411,83 @@ public void GenerateDiffReport_WritesWarningsInSeverityOrder_WhenMd5MismatchAndT |
410 | 411 | reportText.IndexOf("files in `new` have older last-modified timestamps", StringComparison.Ordinal)); |
411 | 412 | } |
412 | 413 |
|
| 414 | + [Fact] |
| 415 | + public void GenerateDiffReport_ILCacheStats_NotIncludedByDefault() |
| 416 | + { |
| 417 | + var oldDir = Path.Combine(_rootDir, "old-ilcs-default"); |
| 418 | + var newDir = Path.Combine(_rootDir, "new-ilcs-default"); |
| 419 | + var reportDir = Path.Combine(_rootDir, "report-ilcs-default"); |
| 420 | + Directory.CreateDirectory(oldDir); |
| 421 | + Directory.CreateDirectory(newDir); |
| 422 | + Directory.CreateDirectory(reportDir); |
| 423 | + |
| 424 | + var config = CreateConfig(); |
| 425 | + _service.GenerateDiffReport( |
| 426 | + oldDir, newDir, reportDir, |
| 427 | + appVersion: "test", elapsedTimeString: null, computerName: "test-host", |
| 428 | + config); |
| 429 | + |
| 430 | + var reportText = File.ReadAllText(Path.Combine(reportDir, "diff_report.md")); |
| 431 | + Assert.DoesNotContain("## IL Cache Stats", reportText); |
| 432 | + } |
| 433 | + |
| 434 | + [Fact] |
| 435 | + public void GenerateDiffReport_ILCacheStats_NotOutputWhenEnabled_ButCacheIsNull() |
| 436 | + { |
| 437 | + var oldDir = Path.Combine(_rootDir, "old-ilcs-null"); |
| 438 | + var newDir = Path.Combine(_rootDir, "new-ilcs-null"); |
| 439 | + var reportDir = Path.Combine(_rootDir, "report-ilcs-null"); |
| 440 | + Directory.CreateDirectory(oldDir); |
| 441 | + Directory.CreateDirectory(newDir); |
| 442 | + Directory.CreateDirectory(reportDir); |
| 443 | + |
| 444 | + var config = CreateConfig(); |
| 445 | + config.ShouldIncludeILCacheStatsInReport = true; |
| 446 | + _service.GenerateDiffReport( |
| 447 | + oldDir, newDir, reportDir, |
| 448 | + appVersion: "test", elapsedTimeString: null, computerName: "test-host", |
| 449 | + config, ilCache: null); |
| 450 | + |
| 451 | + var reportText = File.ReadAllText(Path.Combine(reportDir, "diff_report.md")); |
| 452 | + Assert.DoesNotContain("## IL Cache Stats", reportText); |
| 453 | + } |
| 454 | + |
| 455 | + [Fact] |
| 456 | + public void GenerateDiffReport_ILCacheStats_OutputBetweenSummaryAndWarnings_WhenEnabledWithCache() |
| 457 | + { |
| 458 | + var oldDir = Path.Combine(_rootDir, "old-ilcs-full"); |
| 459 | + var newDir = Path.Combine(_rootDir, "new-ilcs-full"); |
| 460 | + var reportDir = Path.Combine(_rootDir, "report-ilcs-full"); |
| 461 | + Directory.CreateDirectory(oldDir); |
| 462 | + Directory.CreateDirectory(newDir); |
| 463 | + Directory.CreateDirectory(reportDir); |
| 464 | + |
| 465 | + var config = CreateConfig(); |
| 466 | + config.ShouldIncludeILCacheStatsInReport = true; |
| 467 | + var ilCache = new ILCache(ilCacheDirectoryAbsolutePath: string.Empty); |
| 468 | + |
| 469 | + _resultLists.RecordDiffDetail("some.dll", FileDiffResultLists.DiffDetailResult.MD5Mismatch); |
| 470 | + _service.GenerateDiffReport( |
| 471 | + oldDir, newDir, reportDir, |
| 472 | + appVersion: "test", elapsedTimeString: null, computerName: "test-host", |
| 473 | + config, ilCache); |
| 474 | + |
| 475 | + var reportText = File.ReadAllText(Path.Combine(reportDir, "diff_report.md")); |
| 476 | + Assert.Contains("## IL Cache Stats", reportText); |
| 477 | + Assert.Contains("- Hits :", reportText); |
| 478 | + Assert.Contains("- Misses :", reportText); |
| 479 | + Assert.Contains("- Hit Rate:", reportText); |
| 480 | + Assert.Contains("- Stores :", reportText); |
| 481 | + Assert.Contains("- Evicted :", reportText); |
| 482 | + Assert.Contains("- Expired :", reportText); |
| 483 | + // IL Cache Stats section must appear between Summary and Warnings |
| 484 | + int summaryIdx = reportText.IndexOf("## Summary", StringComparison.Ordinal); |
| 485 | + int ilCacheIdx = reportText.IndexOf("## IL Cache Stats", StringComparison.Ordinal); |
| 486 | + int warningsIdx = reportText.IndexOf("## Warnings", StringComparison.Ordinal); |
| 487 | + Assert.True(summaryIdx < ilCacheIdx); |
| 488 | + Assert.True(ilCacheIdx < warningsIdx); |
| 489 | + } |
| 490 | + |
413 | 491 | private static ConfigSettings CreateConfig() => new() |
414 | 492 | { |
415 | 493 | IgnoredExtensions = new List<string>(), |
|
0 commit comments