Skip to content

Commit 6356877

Browse files
committed
refactored diagnostics to provide consistent approach to report building and testing.
1 parent 31ea305 commit 6356877

17 files changed

+96
-74
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Collections.Generic;
2+
using NSubstitute;
3+
using NUnit.Framework;
4+
using TestStack.BDDfy.Processors;
5+
using TestStack.BDDfy.Processors.Reports.Diagnostics;
6+
using TestStack.BDDfy.Processors.Reports.Serializers;
7+
using TestStack.BDDfy.Tests.Processors.Reports;
8+
9+
namespace TestStack.BDDfy.Tests.Processors.Diagnostics
10+
{
11+
[TestFixture]
12+
public class DiagnosticsReportBuilderSpecs
13+
{
14+
[Test]
15+
public void ShouldSerializeDiagnosticDataToSpecifiedFormat()
16+
{
17+
var serializer = Substitute.For<ISerializer>();
18+
var model = new FileReportModel(
19+
new ReportTestData().CreateTwoStoriesEachWithTwoScenariosWithThreeStepsOfFiveMilliseconds());
20+
var sut = new DiagnosticsReportBuilder(serializer);
21+
22+
sut.CreateReport(model);
23+
24+
serializer.Received().Serialize(Arg.Any<IList<StoryDiagnostic>>());
25+
}
26+
27+
}
28+
}

TestStack.BDDfy.Tests/Processors/Diagnostics/DiagnosticsReporterSpecs.cs

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,24 @@
33
using NSubstitute;
44
using NUnit.Framework;
55
using TestStack.BDDfy.Processors;
6-
using TestStack.BDDfy.Processors.Diagnostics;
6+
using TestStack.BDDfy.Processors.Reports;
7+
using TestStack.BDDfy.Processors.Reports.Diagnostics;
8+
using TestStack.BDDfy.Processors.Reports.Serializers;
9+
using TestStack.BDDfy.Processors.Reports.Writers;
710

811
namespace TestStack.BDDfy.Tests.Processors.Diagnostics
912
{
1013
[TestFixture]
1114
public class DiagnosticsReporterSpecs
1215
{
13-
private IDiagnosticsCalculator _calculator;
14-
private ISerializer _serializer;
16+
private IReportBuilder _builder;
1517
private IReportWriter _writer;
1618

1719
[Test]
1820
public void ShouldCreateReportIfProcessingSucceeds()
1921
{
2022
var sut = CreateSut();
21-
_serializer.Serialize(Arg.Any<object>()).Returns("Report Data");
23+
_builder.CreateReport(Arg.Any<FileReportModel>()).Returns("Report Data");
2224

2325
sut.Process(new List<Core.Story>());
2426

@@ -29,35 +31,18 @@ public void ShouldCreateReportIfProcessingSucceeds()
2931
public void ShouldPrintErrorInReportIfProcessingFails()
3032
{
3133
var sut = CreateSut();
32-
_serializer.Serialize(Arg.Any<object>()).Returns(x => { throw new Exception("Error occurred."); });
34+
_builder.CreateReport(Arg.Any<FileReportModel>()).Returns(x => { throw new Exception("Error occurred."); });
3335

3436
sut.Process(new List<Core.Story>());
3537

3638
_writer.Received().OutputReport("There was an error compiling the json report: Error occurred.", Arg.Any<string>());
3739
}
3840

39-
[Test]
40-
public void ShouldGetDiagnosticDataFromStories()
41-
{
42-
var sut = CreateSut();
43-
sut.Process(new List<Core.Story>());
44-
_calculator.Received().GetDiagnosticData(Arg.Any<FileReportModel>());
45-
}
46-
47-
[Test]
48-
public void ShouldSerializeDiagnosticDataToSpecifiedFormat()
49-
{
50-
var sut = CreateSut();
51-
sut.Process(new List<Core.Story>());
52-
_serializer.Received().Serialize(Arg.Any<IList<StoryDiagnostic>>());
53-
}
54-
5541
private DiagnosticsReporter CreateSut()
5642
{
57-
_calculator = Substitute.For<IDiagnosticsCalculator>();
58-
_serializer = Substitute.For<ISerializer>();
43+
_builder = Substitute.For<IReportBuilder>();
5944
_writer = Substitute.For<IReportWriter>();
60-
return new DiagnosticsReporter(_calculator, _serializer, _writer);
45+
return new DiagnosticsReporter(_builder, _writer);
6146
}
6247
}
6348
}

TestStack.BDDfy.Tests/Processors/Diagnostics/DiagnosticsCalculatorSpecs.cs renamed to TestStack.BDDfy.Tests/Processors/Diagnostics/WhenBuildingReportDiagnostics.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using System.Linq;
43
using NUnit.Framework;
54
using TestStack.BDDfy.Processors;
6-
using TestStack.BDDfy.Processors.Diagnostics;
5+
using TestStack.BDDfy.Processors.Reports.Diagnostics;
6+
using TestStack.BDDfy.Processors.Reports.MarkDown;
77
using TestStack.BDDfy.Tests.Processors.Reports;
88

99
namespace TestStack.BDDfy.Tests.Processors.Diagnostics
1010
{
1111
[TestFixture]
12-
public class DiagnosticsCalculatorSpecs
12+
public class WhenBuildingReportDiagnostics
1313
{
14-
private DiagnosticsCalculator _sut;
14+
private DiagnosticsReportBuilder _sut;
1515
private IEnumerable<Core.Story> _stories;
1616
private IList<StoryDiagnostic> _result;
1717

18-
public void GivenADiagnosticsCalculator()
18+
public void GivenADiagnosticsReportBuilder()
1919
{
20-
_sut = new DiagnosticsCalculator();
20+
_sut = new DiagnosticsReportBuilder();
2121
}
2222

2323
public void AndGivenTwoStoriesEachWithTwoScenariosWithThreeStepsOfFiveMilliseconds()

TestStack.BDDfy.Tests/Processors/Reports/MarkDown/MarkDownReporterSpecs.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
using NSubstitute;
44
using NUnit.Framework;
55
using TestStack.BDDfy.Processors;
6-
using TestStack.BDDfy.Processors.Diagnostics;
76
using TestStack.BDDfy.Processors.Reports;
7+
using TestStack.BDDfy.Processors.Reports.Diagnostics;
8+
using TestStack.BDDfy.Processors.Reports.Writers;
89

910
namespace TestStack.BDDfy.Tests.Processors.Reports.MarkDown
1011
{

TestStack.BDDfy.Tests/TestStack.BDDfy.Tests.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@
7777
<SubType>Code</SubType>
7878
</Compile>
7979
<Compile Include="HumanizerTests.cs" />
80-
<Compile Include="Processors\Diagnostics\DiagnosticsCalculatorSpecs.cs" />
80+
<Compile Include="Processors\Diagnostics\DiagnosticsReportBuilderSpecs.cs" />
81+
<Compile Include="Processors\Diagnostics\WhenBuildingReportDiagnostics.cs" />
8182
<Compile Include="Processors\Diagnostics\DiagnosticsReporterSpecs.cs" />
8283
<Compile Include="Processors\Reports\MarkDown\MarkDownReportBuilderSpecs.cs" />
8384
<Compile Include="Processors\Reports\MarkDown\MarkDownReporterSpecs.cs" />

TestStack.BDDfy/Configuration/BatchProcessors.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
using System.Linq;
33
using TestStack.BDDfy.Core;
44
using TestStack.BDDfy.Processors;
5-
using TestStack.BDDfy.Processors.Diagnostics;
65
using TestStack.BDDfy.Processors.HtmlReporter;
6+
using TestStack.BDDfy.Processors.Reports.Diagnostics;
77

88
namespace TestStack.BDDfy.Configuration
99
{

TestStack.BDDfy/Processors/Diagnostics/IDiagnosticsCalculator.cs

Lines changed: 0 additions & 9 deletions
This file was deleted.

TestStack.BDDfy/Processors/MarkDownReporter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
using System;
22
using System.Collections.Generic;
33
using TestStack.BDDfy.Core;
4-
using TestStack.BDDfy.Processors.Diagnostics;
54
using TestStack.BDDfy.Processors.Reports;
5+
using TestStack.BDDfy.Processors.Reports.Diagnostics;
66
using TestStack.BDDfy.Processors.Reports.MarkDown;
7+
using TestStack.BDDfy.Processors.Reports.Writers;
78

89
namespace TestStack.BDDfy.Processors
910
{

TestStack.BDDfy/Processors/Diagnostics/DiagnosticsCalculator.cs renamed to TestStack.BDDfy/Processors/Reports/Diagnostics/DiagnosticsReportBuilder.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
4+
using TestStack.BDDfy.Processors.Reports.Serializers;
35

4-
namespace TestStack.BDDfy.Processors.Diagnostics
6+
namespace TestStack.BDDfy.Processors.Reports.Diagnostics
57
{
6-
public class DiagnosticsCalculator : IDiagnosticsCalculator
8+
public class DiagnosticsReportBuilder : IReportBuilder
79
{
10+
private readonly ISerializer _serializer;
11+
12+
public DiagnosticsReportBuilder() : this(new JsonSerializer()) { }
13+
14+
public DiagnosticsReportBuilder(ISerializer serializer)
15+
{
16+
_serializer = serializer;
17+
}
18+
19+
public string CreateReport(FileReportModel model)
20+
{
21+
var graph = GetDiagnosticData(model);
22+
return _serializer.Serialize(graph);
23+
}
24+
825
public IList<StoryDiagnostic> GetDiagnosticData(FileReportModel viewModel)
926
{
1027
var graph = new List<StoryDiagnostic>();

TestStack.BDDfy/Processors/Diagnostics/DiagnosticsReporter.cs renamed to TestStack.BDDfy/Processors/Reports/Diagnostics/DiagnosticsReporter.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
using System;
22
using System.Collections.Generic;
33
using TestStack.BDDfy.Core;
4+
using TestStack.BDDfy.Processors.Reports.Writers;
45

5-
namespace TestStack.BDDfy.Processors.Diagnostics
6+
namespace TestStack.BDDfy.Processors.Reports.Diagnostics
67
{
78
public class DiagnosticsReporter : IBatchProcessor
89
{
9-
private readonly IDiagnosticsCalculator _calculator;
10-
private readonly ISerializer _serializer;
10+
private readonly IReportBuilder _builder;
1111
private readonly IReportWriter _writer;
1212

13-
public DiagnosticsReporter() : this(new DiagnosticsCalculator(), new JsonSerializer(), new FileWriter()) { }
13+
public DiagnosticsReporter() : this(new DiagnosticsReportBuilder(), new FileWriter()) { }
1414

15-
public DiagnosticsReporter(IDiagnosticsCalculator calculator, ISerializer serializer, IReportWriter writer)
15+
public DiagnosticsReporter(IReportBuilder builder, IReportWriter writer)
1616
{
17-
_calculator = calculator;
18-
_serializer = serializer;
17+
_builder = builder;
1918
_writer = writer;
2019
}
2120

@@ -27,8 +26,7 @@ public void Process(IEnumerable<Core.Story> stories)
2726

2827
try
2928
{
30-
var data = _calculator.GetDiagnosticData(viewModel);
31-
report = _serializer.Serialize(data);
29+
report = _builder.CreateReport(viewModel);
3230
}
3331
catch (Exception ex)
3432
{

0 commit comments

Comments
 (0)