Skip to content

Commit b28dcd7

Browse files
msevestreclaude
andcommitted
Refactor ValidationReportingTask to use ReportOptions parameter
Replace DefaultFormat property with ReportOptions parameter that includes: - ReportFormat as flags enum (None, Markdown, Pdf, All) - OpenReport boolean - Convenience properties ExportToMarkdown and ExportToPdf This allows generating both Markdown and PDF reports in a single call by using ReportFormat.All. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent d998ac5 commit b28dcd7

6 files changed

Lines changed: 98 additions & 45 deletions

File tree

src/InstallationValidator.Core/Presentation/MainPresenter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public async Task<InstallationValidationResult> StartInstallationValidation()
8686
validationResult.RunSummary = runSummary;
8787

8888
this.LogLine(Logs.StartingReport);
89-
await _validationReportingTask.CreateReport(validationResult, _outputFolderDTO.FolderPath, openReport: true);
89+
await _validationReportingTask.CreateReport(validationResult, _outputFolderDTO.FolderPath, new ReportOptions(ReportFormat.Markdown, openReport: true));
9090
this.LogLine();
9191

9292
this.LogLine(Logs.ValidationCompleted);

src/InstallationValidator.Core/Presentation/SimulationComparisonPresenter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public async Task StartComparison()
7070
this.LogLine();
7171

7272
this.LogLine(Logs.StartingReport);
73-
await _validationReportingTask.CreateReport(comparisonResult, _folderComparisonDTO.FirstFolder.FolderPath, _folderComparisonDTO.SecondFolder.FolderPath, openReport: true);
73+
await _validationReportingTask.CreateReport(comparisonResult, _folderComparisonDTO.FirstFolder.FolderPath, _folderComparisonDTO.SecondFolder.FolderPath, new ReportOptions(ReportFormat.Markdown, openReport: true));
7474
this.LogLine();
7575

7676
this.LogLine(Logs.ComparisonCompleted);

src/InstallationValidator.Core/Services/ValidationReportingTask.cs

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,73 @@
1+
using System;
12
using System.Threading.Tasks;
23
using InstallationValidator.Core.Domain;
34

45
namespace InstallationValidator.Core.Services
56
{
6-
public interface IValidationReportingTask
7+
[Flags]
8+
public enum ReportFormat
79
{
8-
Task CreateReport(InstallationValidationResult installationValidationResult, string outputFolderPath, bool openReport = false);
9-
Task CreateReport(BatchComparisonResult comparisonResult, string firstFolderPath, string secondFolderPath, bool openReport);
10+
None = 0,
11+
Markdown = 1,
12+
Pdf = 2,
13+
All = Markdown | Pdf
1014
}
1115

12-
public enum ReportFormat
16+
public class ReportOptions
17+
{
18+
public ReportFormat Format { get; }
19+
public bool OpenReport { get; }
20+
21+
public bool ExportToMarkdown => Format.HasFlag(ReportFormat.Markdown);
22+
public bool ExportToPdf => Format.HasFlag(ReportFormat.Pdf);
23+
24+
public ReportOptions(ReportFormat format, bool openReport)
25+
{
26+
Format = format;
27+
OpenReport = openReport;
28+
}
29+
}
30+
31+
public interface IValidationReportingTask
1332
{
14-
Markdown,
15-
Pdf
33+
Task CreateReport(InstallationValidationResult installationValidationResult, string outputFolderPath, ReportOptions options);
34+
Task CreateReport(BatchComparisonResult comparisonResult, string firstFolderPath, string secondFolderPath, ReportOptions options);
1635
}
1736

1837
public class ValidationReportingTask : IValidationReportingTask
1938
{
2039
private readonly IMarkdownReportingTask _markdownReportingTask;
2140
private readonly IPdfReportingTask _pdfReportingTask;
2241

23-
public ReportFormat DefaultFormat { get; set; } = ReportFormat.Markdown;
24-
2542
public ValidationReportingTask(IMarkdownReportingTask markdownReportingTask, IPdfReportingTask pdfReportingTask)
2643
{
2744
_markdownReportingTask = markdownReportingTask;
2845
_pdfReportingTask = pdfReportingTask;
2946
}
3047

31-
public async Task CreateReport(BatchComparisonResult comparisonResult, string firstFolderPath, string secondFolderPath, bool openReport = false)
48+
public async Task CreateReport(BatchComparisonResult comparisonResult, string firstFolderPath, string secondFolderPath, ReportOptions options)
3249
{
33-
if (DefaultFormat == ReportFormat.Pdf)
50+
if (options.ExportToMarkdown)
3451
{
35-
await _pdfReportingTask.CreateReport(comparisonResult, firstFolderPath, secondFolderPath, openReport);
52+
await _markdownReportingTask.CreateReport(comparisonResult, firstFolderPath, secondFolderPath, options.OpenReport);
3653
}
37-
else
54+
55+
if (options.ExportToPdf)
3856
{
39-
await _markdownReportingTask.CreateReport(comparisonResult, firstFolderPath, secondFolderPath, openReport);
57+
await _pdfReportingTask.CreateReport(comparisonResult, firstFolderPath, secondFolderPath, options.OpenReport);
4058
}
4159
}
4260

43-
public async Task CreateReport(InstallationValidationResult installationValidationResult, string outputFolderPath, bool openReport = false)
61+
public async Task CreateReport(InstallationValidationResult installationValidationResult, string outputFolderPath, ReportOptions options)
4462
{
45-
if (DefaultFormat == ReportFormat.Pdf)
63+
if (options.ExportToMarkdown)
4664
{
47-
await _pdfReportingTask.CreateReport(installationValidationResult, outputFolderPath, openReport);
65+
await _markdownReportingTask.CreateReport(installationValidationResult, outputFolderPath, options.OpenReport);
4866
}
49-
else
67+
68+
if (options.ExportToPdf)
5069
{
51-
await _markdownReportingTask.CreateReport(installationValidationResult, outputFolderPath, openReport);
70+
await _pdfReportingTask.CreateReport(installationValidationResult, outputFolderPath, options.OpenReport);
5271
}
5372
}
5473
}

tests/InstallationValidator.Tests/Presentation/MainPresenterSpecs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public void should_state_the_comparison_task()
178178
[Observation]
179179
public void should_generate_the_report()
180180
{
181-
A.CallTo(() => _validationReportingTask.CreateReport(_result, _outputFolderDTO.FolderPath, true)).MustHaveHappened();
181+
A.CallTo(() => _validationReportingTask.CreateReport(_result, _outputFolderDTO.FolderPath, A<ReportOptions>._)).MustHaveHappened();
182182
}
183183
}
184184

tests/InstallationValidator.Tests/Presentation/SimulationComparisonPresenterSpecs.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using InstallationValidator.Core.Presentation.Views;
1010
using InstallationValidator.Core.Services;
1111
using OSPSuite.BDDHelper;
12+
using OSPSuite.BDDHelper.Extensions;
1213
using OSPSuite.Core;
1314
using OSPSuite.Core.Services;
1415

@@ -129,7 +130,7 @@ public void should_start_the_comparison_task()
129130
[Observation]
130131
public void should_generate_the_report()
131132
{
132-
A.CallTo(() => _validationReportingTask.CreateReport(A<BatchComparisonResult>._, _firstFolder.FolderPath, _secondFolder.FolderPath, true)).MustHaveHappened();
133+
A.CallTo(() => _validationReportingTask.CreateReport(A<BatchComparisonResult>._, _firstFolder.FolderPath, _secondFolder.FolderPath, A<ReportOptions>._)).MustHaveHappened();
133134
}
134135
}
135136

tests/InstallationValidator.Tests/Services/ValidationReportingTaskSpecs.cs

Lines changed: 56 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,11 @@ protected override void Context()
2929
}
3030
}
3131

32-
public class When_creating_report_with_default_markdown_format : concern_for_ValidationReportingTask
32+
public class When_creating_report_with_markdown_format : concern_for_ValidationReportingTask
3333
{
34-
protected override void Context()
35-
{
36-
base.Context();
37-
sut.DefaultFormat = ReportFormat.Markdown;
38-
}
39-
4034
protected override void Because()
4135
{
42-
sut.CreateReport(_installationValidationResult, _outputFolder).Wait();
36+
sut.CreateReport(_installationValidationResult, _outputFolder, new ReportOptions(ReportFormat.Markdown, openReport: false)).Wait();
4337
}
4438

4539
[Observation]
@@ -59,15 +53,9 @@ public void should_not_use_pdf_reporting_task()
5953

6054
public class When_creating_report_with_pdf_format : concern_for_ValidationReportingTask
6155
{
62-
protected override void Context()
63-
{
64-
base.Context();
65-
sut.DefaultFormat = ReportFormat.Pdf;
66-
}
67-
6856
protected override void Because()
6957
{
70-
sut.CreateReport(_installationValidationResult, _outputFolder).Wait();
58+
sut.CreateReport(_installationValidationResult, _outputFolder, new ReportOptions(ReportFormat.Pdf, openReport: false)).Wait();
7159
}
7260

7361
[Observation]
@@ -87,46 +75,91 @@ public void should_not_use_markdown_reporting_task()
8775

8876
public class When_creating_report_with_open_report_flag : concern_for_ValidationReportingTask
8977
{
78+
protected override void Because()
79+
{
80+
sut.CreateReport(_installationValidationResult, _outputFolder, new ReportOptions(ReportFormat.Markdown, openReport: true)).Wait();
81+
}
82+
83+
[Observation]
84+
public void should_pass_open_report_flag_to_underlying_task()
85+
{
86+
A.CallTo(() => _markdownReportingTask.CreateReport(_installationValidationResult, _outputFolder, true))
87+
.MustHaveHappened();
88+
}
89+
}
90+
91+
public class When_creating_batch_comparison_report : concern_for_ValidationReportingTask
92+
{
93+
private BatchComparisonResult _batchComparisonResult;
94+
9095
protected override void Context()
9196
{
9297
base.Context();
93-
sut.DefaultFormat = ReportFormat.Markdown;
98+
_batchComparisonResult = new BatchComparisonResult();
9499
}
95100

96101
protected override void Because()
97102
{
98-
sut.CreateReport(_installationValidationResult, _outputFolder, openReport: true).Wait();
103+
sut.CreateReport(_batchComparisonResult, "folder1", "folder2", new ReportOptions(ReportFormat.Markdown, openReport: false)).Wait();
99104
}
100105

101106
[Observation]
102-
public void should_pass_open_report_flag_to_underlying_task()
107+
public void should_use_markdown_reporting_task_for_batch_comparison()
103108
{
104-
A.CallTo(() => _markdownReportingTask.CreateReport(_installationValidationResult, _outputFolder, true))
109+
A.CallTo(() => _markdownReportingTask.CreateReport(_batchComparisonResult, "folder1", "folder2", false))
105110
.MustHaveHappened();
106111
}
107112
}
108113

109-
public class When_creating_batch_comparison_report : concern_for_ValidationReportingTask
114+
public class When_creating_report_with_all_formats : concern_for_ValidationReportingTask
115+
{
116+
protected override void Because()
117+
{
118+
sut.CreateReport(_installationValidationResult, _outputFolder, new ReportOptions(ReportFormat.All, openReport: false)).Wait();
119+
}
120+
121+
[Observation]
122+
public void should_use_markdown_reporting_task()
123+
{
124+
A.CallTo(() => _markdownReportingTask.CreateReport(_installationValidationResult, _outputFolder, false))
125+
.MustHaveHappened();
126+
}
127+
128+
[Observation]
129+
public void should_use_pdf_reporting_task()
130+
{
131+
A.CallTo(() => _pdfReportingTask.CreateReport(_installationValidationResult, _outputFolder, false))
132+
.MustHaveHappened();
133+
}
134+
}
135+
136+
public class When_creating_batch_comparison_report_with_all_formats : concern_for_ValidationReportingTask
110137
{
111138
private BatchComparisonResult _batchComparisonResult;
112139

113140
protected override void Context()
114141
{
115142
base.Context();
116143
_batchComparisonResult = new BatchComparisonResult();
117-
sut.DefaultFormat = ReportFormat.Markdown;
118144
}
119145

120146
protected override void Because()
121147
{
122-
sut.CreateReport(_batchComparisonResult, "folder1", "folder2", openReport: false).Wait();
148+
sut.CreateReport(_batchComparisonResult, "folder1", "folder2", new ReportOptions(ReportFormat.All, openReport: false)).Wait();
123149
}
124150

125151
[Observation]
126-
public void should_use_markdown_reporting_task_for_batch_comparison()
152+
public void should_use_markdown_reporting_task()
127153
{
128154
A.CallTo(() => _markdownReportingTask.CreateReport(_batchComparisonResult, "folder1", "folder2", false))
129155
.MustHaveHappened();
130156
}
157+
158+
[Observation]
159+
public void should_use_pdf_reporting_task()
160+
{
161+
A.CallTo(() => _pdfReportingTask.CreateReport(_batchComparisonResult, "folder1", "folder2", false))
162+
.MustHaveHappened();
163+
}
131164
}
132165
}

0 commit comments

Comments
 (0)