Skip to content

Commit 31ea305

Browse files
committed
Refactored the markdown report and added tests for it
1 parent 2f20f98 commit 31ea305

16 files changed

+275
-106
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ bin/
33
obj/
44
*.user
55
*.suo
6+
*.DotSettings
67
*~
78
*.swp
89
*.orig

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

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

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using NUnit.Framework;
55
using TestStack.BDDfy.Processors;
66
using TestStack.BDDfy.Processors.Diagnostics;
7+
using TestStack.BDDfy.Tests.Processors.Reports;
78

89
namespace TestStack.BDDfy.Tests.Processors.Diagnostics
910
{
@@ -19,9 +20,9 @@ public void GivenADiagnosticsCalculator()
1920
_sut = new DiagnosticsCalculator();
2021
}
2122

22-
public void AndGivenTwoStoriesEachWithTwoScenariosWithTwoStepsOfFiveMilliseconds()
23+
public void AndGivenTwoStoriesEachWithTwoScenariosWithThreeStepsOfFiveMilliseconds()
2324
{
24-
_stories = new DiagnosticTestData().CreateTwoStoriesEachWithTwoScenariosWithTwoStepsOfFiveMilliseconds();
25+
_stories = new ReportTestData().CreateTwoStoriesEachWithTwoScenariosWithThreeStepsOfFiveMilliseconds();
2526
}
2627

2728
public void WhenTheDiagnosticDataIsCalculated()
@@ -34,15 +35,15 @@ public void ThenTwoStoriesShouldBeReturned()
3435
Assert.AreEqual(2, _result.Count);
3536
}
3637

37-
public void AndThenEachStoryShouldHaveDurationOf20Milliseconds()
38+
public void AndThenEachStoryShouldHaveDurationOf30Milliseconds()
3839
{
39-
_result.ToList().ForEach(story => Assert.AreEqual(20, story.Duration));
40+
_result.ToList().ForEach(story => Assert.AreEqual(30, story.Duration));
4041
}
4142

4243
public void AndThenEachScenarioShouldHaveDurationOf10Milliseconds()
4344
{
44-
_result[0].Scenarios.ForEach(scenario => Assert.AreEqual(10, scenario.Duration));
45-
_result[1].Scenarios.ForEach(scenario => Assert.AreEqual(10, scenario.Duration));
45+
_result[0].Scenarios.ForEach(scenario => Assert.AreEqual(15, scenario.Duration));
46+
_result[1].Scenarios.ForEach(scenario => Assert.AreEqual(15, scenario.Duration));
4647
}
4748

4849
public void AndThenEachStepShouldHaveDurationOf5Milliseconds()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public void ShouldCreateReportIfProcessingSucceeds()
2222

2323
sut.Process(new List<Core.Story>());
2424

25-
_writer.Received().Create("Report Data", Arg.Any<string>());
25+
_writer.Received().OutputReport("Report Data", Arg.Any<string>());
2626
}
2727

2828
[Test]
@@ -33,7 +33,7 @@ public void ShouldPrintErrorInReportIfProcessingFails()
3333

3434
sut.Process(new List<Core.Story>());
3535

36-
_writer.Received().Create("There was an error compiling the json report: Error occurred.", Arg.Any<string>());
36+
_writer.Received().OutputReport("There was an error compiling the json report: Error occurred.", Arg.Any<string>());
3737
}
3838

3939
[Test]
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
using System.Collections.Generic;
2+
using System.Text.RegularExpressions;
3+
using NUnit.Framework;
4+
using TestStack.BDDfy.Processors;
5+
using TestStack.BDDfy.Processors.Reports.MarkDown;
6+
using TestStack.BDDfy.Scanners.StepScanners.ExecutableAttribute.GwtAttributes;
7+
8+
namespace TestStack.BDDfy.Tests.Processors.Reports.MarkDown
9+
{
10+
[TestFixture]
11+
public class MarkDownReportBuilderSpecs
12+
{
13+
private MarkDownReportBuilder _sut;
14+
private IEnumerable<Core.Story> _stories;
15+
private string[] _result;
16+
17+
[Given("Given a MarkDownReportBuilder")]
18+
public void GivenAMarkDownReportBuilder()
19+
{
20+
_sut = new MarkDownReportBuilder();
21+
}
22+
23+
public void AndGivenTwoStoriesEachWithTwoScenariosWithThreeStepsOfFiveMilliseconds()
24+
{
25+
_stories = new ReportTestData().CreateTwoStoriesEachWithTwoScenariosWithThreeStepsOfFiveMilliseconds();
26+
}
27+
28+
public void WhenTheReportIsCreated()
29+
{
30+
var report = _sut.CreateReport(new FileReportModel(_stories));
31+
_result = Regex.Split(report, "\r\n");
32+
}
33+
34+
public void ThenTheFirstLineShouldBeTheFirstStoryTitleAsH2()
35+
{
36+
AssertLine(0, "## Story: Account holder withdraws cash");
37+
}
38+
39+
public void AndThenShouldDisplayStoryIndentedByOneSpaceWithBoldFormatting()
40+
{
41+
AssertLine(1, " **As an account holder** ");
42+
AssertLine(2, " **I want to withdraw cash** ");
43+
AssertLine(3, " **So that I can get money when the bank is closed** ");
44+
}
45+
46+
public void AndThenShouldDisplayALineBreakAfterTheStory()
47+
{
48+
AssertLine(4, string.Empty);
49+
}
50+
51+
public void AndThenShouldDisplayScenarioTitleAsH3()
52+
{
53+
AssertLine(5, "### Happy Path Scenario");
54+
}
55+
56+
public void AndThenShouldDisplayScenarioStepsIndentedByTwoSpaces()
57+
{
58+
AssertLine(6, " Given a positive account balance ");
59+
AssertLine(7, " When the account holder requests money ");
60+
AssertLine(8, " Then money is dispensed ");
61+
}
62+
63+
public void AndThenShouldDisplayALineBreakBetweenScenarios()
64+
{
65+
AssertLine(9, string.Empty);
66+
AssertLine(10, "### Sad Path Scenario");
67+
}
68+
69+
public void AndThenShouldRepeatForSubsequentStories()
70+
{
71+
AssertLine(14, string.Empty);
72+
AssertLine(15, "## Story: Happiness");
73+
}
74+
75+
private void AssertLine(int lineNumber, string lineValue)
76+
{
77+
Assert.That(_result[lineNumber], Is.EqualTo(lineValue));
78+
}
79+
80+
[Test]
81+
public void RunSpecs()
82+
{
83+
this.BDDfy();
84+
}
85+
}
86+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using NSubstitute;
4+
using NUnit.Framework;
5+
using TestStack.BDDfy.Processors;
6+
using TestStack.BDDfy.Processors.Diagnostics;
7+
using TestStack.BDDfy.Processors.Reports;
8+
9+
namespace TestStack.BDDfy.Tests.Processors.Reports.MarkDown
10+
{
11+
[TestFixture]
12+
public class MarkDownReporterSpecs
13+
{
14+
private IReportBuilder _builder;
15+
private IReportWriter _writer;
16+
17+
[Test]
18+
public void ShouldCreateReportIfProcessingSucceeds()
19+
{
20+
var sut = CreateSut();
21+
_builder.CreateReport(Arg.Any<FileReportModel>()).Returns("Report Data");
22+
23+
sut.Process(new List<Core.Story>());
24+
25+
_writer.Received().OutputReport("Report Data", Arg.Any<string>());
26+
}
27+
28+
[Test]
29+
public void ShouldPrintErrorInReportIfProcessingFails()
30+
{
31+
var sut = CreateSut();
32+
_builder.CreateReport(Arg.Any<FileReportModel>()).Returns(x => { throw new Exception("Error occurred."); });
33+
34+
sut.Process(new List<Core.Story>());
35+
36+
_writer.Received().OutputReport("There was an error compiling the markdown report: Error occurred.", Arg.Any<string>());
37+
}
38+
39+
private MarkDownReporter CreateSut()
40+
{
41+
_builder = Substitute.For<IReportBuilder>();
42+
_writer = Substitute.For<IReportWriter>();
43+
return new MarkDownReporter(_builder, _writer);
44+
}
45+
}
46+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using TestStack.BDDfy.Core;
4+
5+
namespace TestStack.BDDfy.Tests.Processors.Reports
6+
{
7+
public class ReportTestData
8+
{
9+
public IEnumerable<Core.Story> CreateTwoStoriesEachWithTwoScenariosWithThreeStepsOfFiveMilliseconds()
10+
{
11+
var storyMetaData1 = new StoryMetaData(typeof(RegularAccountHolderStory), "As a person", "I want ice cream", "So that I can be happy", "Happiness");
12+
var storyMetaData2 = new StoryMetaData(typeof(GoldAccountHolderStory), "As an account holder", "I want to withdraw cash", "So that I can get money when the bank is closed", "Account holder withdraws cash");
13+
var stories = new List<Core.Story>()
14+
{
15+
new Core.Story(storyMetaData1, GetScenarios()),
16+
new Core.Story(storyMetaData2, GetScenarios())
17+
};
18+
19+
return stories;
20+
}
21+
22+
private Scenario[] GetScenarios()
23+
{
24+
var scenarios = new List<Scenario>()
25+
{
26+
new Scenario(typeof(HappyPathScenario), GetHappyExecutionSteps(), "Happy Path Scenario"),
27+
new Scenario(typeof(SadPathScenario), GetSadExecutionSteps(), "Sad Path Scenario")
28+
};
29+
return scenarios.ToArray();
30+
}
31+
32+
private IEnumerable<ExecutionStep> GetHappyExecutionSteps()
33+
{
34+
var steps = new List<ExecutionStep>()
35+
{
36+
new ExecutionStep(null, "Given a positive account balance", true, ExecutionOrder.Assertion, true) {Duration = new TimeSpan(0, 0, 0, 0, 5)},
37+
new ExecutionStep(null, "When the account holder requests money", true, ExecutionOrder.Assertion, true) {Duration = new TimeSpan(0, 0, 0, 0, 5)},
38+
new ExecutionStep(null, "Then money is dispensed", true, ExecutionOrder.Assertion, true) {Duration = new TimeSpan(0, 0, 0, 0, 5)},
39+
};
40+
return steps;
41+
}
42+
43+
private IEnumerable<ExecutionStep> GetSadExecutionSteps()
44+
{
45+
var steps = new List<ExecutionStep>()
46+
{
47+
new ExecutionStep(null, "Given a negative account balance", true, ExecutionOrder.Assertion, true) {Duration = new TimeSpan(0, 0, 0, 0, 5)},
48+
new ExecutionStep(null, "When the account holder requests money", true, ExecutionOrder.Assertion, true) {Duration = new TimeSpan(0, 0, 0, 0, 5)},
49+
new ExecutionStep(null, "Then no money is dispensed", true, ExecutionOrder.Assertion, true) {Duration = new TimeSpan(0, 0, 0, 0, 5)},
50+
};
51+
return steps;
52+
}
53+
54+
public class RegularAccountHolderStory { }
55+
public class GoldAccountHolderStory { }
56+
public class HappyPathScenario
57+
{
58+
public void GivenAPositiveAccountBalance() { }
59+
public void WhenTheAccountHolderRequestsMoney() { }
60+
public void ThenMoneyIsDispensed() { }
61+
}
62+
public class SadPathScenario
63+
{
64+
public void GivenANegativeAccountBalance() { }
65+
public void WhenTheAccountHolderRequestsMoney() { }
66+
public void ThenNoMoneyIsDispensed() { }
67+
}
68+
}
69+
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@
7979
<Compile Include="HumanizerTests.cs" />
8080
<Compile Include="Processors\Diagnostics\DiagnosticsCalculatorSpecs.cs" />
8181
<Compile Include="Processors\Diagnostics\DiagnosticsReporterSpecs.cs" />
82-
<Compile Include="Processors\Diagnostics\DiagnosticTestData.cs" />
82+
<Compile Include="Processors\Reports\MarkDown\MarkDownReportBuilderSpecs.cs" />
83+
<Compile Include="Processors\Reports\MarkDown\MarkDownReporterSpecs.cs" />
84+
<Compile Include="Processors\Reports\ReportTestData.cs" />
8385
<Compile Include="Scanner\ExecutableAttributeOrderOrdersTheStepsCorrectly.cs" />
8486
<Compile Include="Scanner\PropertiesAreNotConsideredAsStepsEvenWhenTheirNameMatchesConventions.cs" />
8587
<Compile Include="Scanner\ExpressionExtensionsTests.cs" />

TestStack.BDDfy.sln.DotSettings

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

TestStack.BDDfy/Processors/Diagnostics/DiagnosticsReporter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void Process(IEnumerable<Core.Story> stories)
3535
report = error + ex.Message;
3636
}
3737

38-
_writer.Create(report, "Diagnostics.json");
38+
_writer.OutputReport(report, "Diagnostics.json");
3939
}
4040
}
4141
}

0 commit comments

Comments
 (0)