Skip to content

Commit 5402185

Browse files
committed
First pass at ReportModel for reports
1 parent dc80f5d commit 5402185

18 files changed

+232
-48
lines changed

.nuget/packages.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="xunit.runners" version="2.0.0-rc1-build2826" />
4+
<package id="xunit.runners" version="1.9.2" />
45
</packages>

TestStack.BDDfy.Tests/Reporters/Diagnostics/DiagnosticsReportBuilderTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public void ShouldSerializeDiagnosticDataToSpecifiedFormat()
1313
{
1414
var serializer = Substitute.For<ISerializer>();
1515
var testData = new ReportTestData().CreateTwoStoriesEachWithOneFailingScenarioAndOnePassingScenarioWithThreeStepsOfFiveMilliseconds();
16-
var model = new FileReportModel(testData);
16+
var model = new FileReportModel(testData.ToReportModel());
1717
var sut = new DiagnosticsReportBuilder(serializer);
1818

1919
sut.CreateReport(model);

TestStack.BDDfy.Tests/Reporters/Diagnostics/WhenBuildingReportDiagnostics.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public void AndGivenTwoStoriesEachWithTwoScenariosWithThreeStepsOfFiveMillisecon
2525

2626
public void WhenTheDiagnosticDataIsCalculated()
2727
{
28-
_result = _sut.GetDiagnosticData(new FileReportModel(_stories));
28+
_result = _sut.GetDiagnosticData(new FileReportModel(_stories.ToReportModel()));
2929
}
3030

3131
public void ThenTwoStoriesShouldBeReturned()

TestStack.BDDfy.Tests/Reporters/Html/ClassicReportBuilderTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ public class ClassicReportBuilderTests
1313
public void ShouldProduceExpectedHtml()
1414
{
1515
Func<FileReportModel> model = () =>
16-
new HtmlReportModel(new ReportTestData().CreateTwoStoriesEachWithOneFailingScenarioAndOnePassingScenarioWithThreeStepsOfFiveMilliseconds())
16+
new HtmlReportModel(new ReportTestData().CreateTwoStoriesEachWithOneFailingScenarioAndOnePassingScenarioWithThreeStepsOfFiveMilliseconds()
17+
.ToReportModel())
1718
{
1819
RunDate = new DateTime(2014, 3, 25, 11, 30, 5)
1920
};
@@ -27,7 +28,8 @@ public void ShouldProduceExpectedHtml()
2728
public void ShouldProduceExpectedHtmlWithExamples()
2829
{
2930
Func<FileReportModel> model = () =>
30-
new HtmlReportModel(new ReportTestData().CreateTwoStoriesEachWithOneFailingScenarioAndOnePassingScenarioWithThreeStepsOfFiveMillisecondsAndEachHasTwoExamples())
31+
new HtmlReportModel(new ReportTestData().CreateTwoStoriesEachWithOneFailingScenarioAndOnePassingScenarioWithThreeStepsOfFiveMillisecondsAndEachHasTwoExamples()
32+
.ToReportModel())
3133
{
3234
RunDate = new DateTime(2014, 3, 25, 11, 30, 5)
3335
};

TestStack.BDDfy.Tests/Reporters/Html/MetroReportBuilderTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class MetroReportBuilderTests
1313
public void ShouldProduceExpectedHtml()
1414
{
1515
Func<FileReportModel> model = () =>
16-
new HtmlReportModel(new ReportTestData().CreateMixContainingEachTypeOfOutcome())
16+
new HtmlReportModel(new ReportTestData().CreateMixContainingEachTypeOfOutcome().ToReportModel())
1717
{
1818
RunDate = new DateTime(2014, 3, 25, 11, 30, 5)
1919
};
@@ -27,7 +27,8 @@ public void ShouldProduceExpectedHtml()
2727
public void ShouldProduceExpectedHtmlWithExamples()
2828
{
2929
Func<FileReportModel> model = () =>
30-
new HtmlReportModel(new ReportTestData().CreateTwoStoriesEachWithOneFailingScenarioAndOnePassingScenarioWithThreeStepsOfFiveMillisecondsAndEachHasTwoExamples())
30+
new HtmlReportModel(new ReportTestData().CreateTwoStoriesEachWithOneFailingScenarioAndOnePassingScenarioWithThreeStepsOfFiveMillisecondsAndEachHasTwoExamples()
31+
.ToReportModel())
3132
{
3233
RunDate = new DateTime(2014, 3, 25, 11, 30, 5)
3334
};

TestStack.BDDfy.Tests/Reporters/MarkDown/MarkDownReportBuilderTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class MarkDownReportBuilderTests
1212
[MethodImpl(MethodImplOptions.NoInlining)]
1313
public void ShouldProduceExpectedMarkdown()
1414
{
15-
Func<FileReportModel> model = () => new FileReportModel(new ReportTestData().CreateMixContainingEachTypeOfOutcome());
15+
Func<FileReportModel> model = () => new FileReportModel(new ReportTestData().CreateMixContainingEachTypeOfOutcome().ToReportModel());
1616
var sut = new MarkDownReportBuilder();
1717
ReportApprover.Approve(model, sut);
1818
}
@@ -22,7 +22,8 @@ public void ShouldProduceExpectedMarkdown()
2222
public void ShouldProduceExpectedMarkdownWithExamples()
2323
{
2424
Func<FileReportModel> model = () =>
25-
new FileReportModel(new ReportTestData().CreateTwoStoriesEachWithOneFailingScenarioAndOnePassingScenarioWithThreeStepsOfFiveMillisecondsAndEachHasTwoExamples())
25+
new FileReportModel(new ReportTestData().CreateTwoStoriesEachWithOneFailingScenarioAndOnePassingScenarioWithThreeStepsOfFiveMillisecondsAndEachHasTwoExamples()
26+
.ToReportModel())
2627
{
2728
RunDate = new DateTime(2014, 3, 25, 11, 30, 5)
2829
};

TestStack.BDDfy.Tests/TagsTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public void TagsAreReportedInHtmlReport()
3232
var story = this.Given(_ => GivenAStep())
3333
.WithTags("Tag1", "Tag 2")
3434
.BDDfy();
35-
Func<FileReportModel> model = () => new HtmlReportModel(new[] { story })
35+
Func<FileReportModel> model = () => new HtmlReportModel(new[] { story }.ToReportModel())
3636
{
3737
RunDate = new DateTime(2014, 3, 25, 11, 30, 5)
3838
};
@@ -48,7 +48,7 @@ public void TagsAreReportedInMetroHtmlReport()
4848
var story = this.Given(_ => GivenAStep())
4949
.WithTags("Tag1", "Tag 2")
5050
.BDDfy();
51-
Func<FileReportModel> model = () => new HtmlReportModel(new[] { story })
51+
Func<FileReportModel> model = () => new HtmlReportModel(new[] { story }.ToReportModel())
5252
{
5353
RunDate = new DateTime(2014, 3, 25, 11, 30, 5)
5454
};
@@ -64,7 +64,7 @@ public void TagsAreReportedInMarkdownReport()
6464
var story = this.Given(_ => GivenAStep())
6565
.WithTags("Tag1", "Tag 2")
6666
.BDDfy();
67-
Func<FileReportModel> model = () => new FileReportModel(new[] { story });
67+
Func<FileReportModel> model = () => new FileReportModel(new[] { story }.ToReportModel());
6868
var sut = new MarkDownReportBuilder();
6969
ReportApprover.Approve(model, sut);
7070
}
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
namespace TestStack.BDDfy.Reporters
6+
{
7+
public static class ReportMappers
8+
{
9+
public static ReportModel ToReportModel(this IEnumerable<Story> stories)
10+
{
11+
var report = new ReportModel();
12+
foreach (var story in stories)
13+
{
14+
report.Stories.Add(story.ToStoryModel());
15+
}
16+
17+
return report;
18+
}
19+
20+
public static ReportModel.Story ToStoryModel(this Story story)
21+
{
22+
var model = new ReportModel.Story
23+
{
24+
Namespace = story.Namespace,
25+
Result = story.Result,
26+
Metadata = story.Metadata.ToStoryMetadataModel()
27+
};
28+
29+
foreach (var scenario in story.Scenarios)
30+
{
31+
model.Scenarios.Add(scenario.ToScenarioModel());
32+
}
33+
34+
return model;
35+
}
36+
37+
public static ReportModel.StoryMetadata ToStoryMetadataModel(this StoryMetadata metadata)
38+
{
39+
return new ReportModel.StoryMetadata
40+
{
41+
Type = metadata.Type,
42+
Title = metadata.Title,
43+
TitlePrefix = metadata.TitlePrefix,
44+
Narrative1 = metadata.Narrative1,
45+
Narrative2 = metadata.Narrative2,
46+
Narrative3 = metadata.Narrative3,
47+
};
48+
}
49+
public static ReportModel.Scenario ToScenarioModel(this Scenario scenario)
50+
{
51+
var model = new ReportModel.Scenario
52+
{
53+
Id = scenario.Id,
54+
Title = scenario.Title,
55+
Tags = scenario.Tags,
56+
Example = scenario.Example.ToExampleModel(),
57+
Duration = scenario.Duration,
58+
Result = scenario.Result
59+
};
60+
scenario.Steps.ForEach(x => model.Steps.Add(x.ToStepModel()));
61+
return model;
62+
}
63+
64+
public static ReportModel.Step ToStepModel(this Step step)
65+
{
66+
return new ReportModel.Step
67+
{
68+
Id = step.Id,
69+
Asserts = step.Asserts,
70+
ShouldReport = step.ShouldReport,
71+
Title = step.Title,
72+
ExecutionOrder = step.ExecutionOrder,
73+
Result = step.Result,
74+
Exception = step.Exception,
75+
Duration = step.Duration
76+
};
77+
}
78+
79+
public static ReportModel.Example ToExampleModel(this Example example)
80+
{
81+
return new ReportModel.Example
82+
{
83+
Headers = example.Headers,
84+
Values = example.Values
85+
};
86+
}
87+
}
88+
89+
public class ReportModel
90+
{
91+
public List<ReportModel.Story> Stories { get; set; }
92+
93+
public ReportModel()
94+
{
95+
Stories = new List<Story>();
96+
}
97+
98+
public class Story
99+
{
100+
public Story()
101+
{
102+
Scenarios = new List<Scenario>();
103+
}
104+
105+
public string Namespace { get; set; }
106+
public Result Result { get; set; }
107+
public List<Scenario> Scenarios { get; set; }
108+
public StoryMetadata Metadata { get; set; }
109+
}
110+
111+
public class StoryMetadata
112+
{
113+
public Type Type { get; set; }
114+
public string Title { get; set; }
115+
public string TitlePrefix { get; set; }
116+
public string Narrative1 { get; set; }
117+
public string Narrative2 { get; set; }
118+
public string Narrative3 { get; set; }
119+
}
120+
121+
public class Scenario
122+
{
123+
public Scenario()
124+
{
125+
Tags = new List<string>();
126+
Steps = new List<Step>();
127+
}
128+
129+
public string Id { get; set; }
130+
131+
public string Title { get; set; }
132+
133+
public List<string> Tags { get; set; }
134+
135+
public Example Example { get; set; }
136+
137+
public TimeSpan Duration { get; set; }
138+
139+
public List<Step> Steps { get; set; }
140+
141+
public Result Result { get; set; }
142+
}
143+
144+
public class Step
145+
{
146+
public string Id { get; set; }
147+
148+
public bool Asserts { get; set; }
149+
150+
public bool ShouldReport { get; set; }
151+
152+
public string Title { get; set; }
153+
154+
public ExecutionOrder ExecutionOrder { get; set; }
155+
156+
public Result Result { get; set; }
157+
158+
public Exception Exception { get; set; }
159+
160+
public TimeSpan Duration { get; set; }
161+
}
162+
163+
public class Example
164+
{
165+
public Example()
166+
{
167+
Values = new List<ExampleValue>();
168+
}
169+
170+
public string[] Headers { get; set; }
171+
172+
public IEnumerable<ExampleValue> Values { get; set; }
173+
174+
public override string ToString()
175+
{
176+
return string.Join(", ", Values.Select(i => i.ToString()));
177+
}
178+
}
179+
}
180+
}

TestStack.BDDfy/Reporters/Diagnostics/DiagnosticsReporter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public DiagnosticsReporter(IReportBuilder builder, IReportWriter writer)
1919

2020
public void Process(IEnumerable<Story> stories)
2121
{
22-
var viewModel = new FileReportModel(stories);
22+
var viewModel = new FileReportModel(stories.ToReportModel());
2323
string report;
2424

2525
try

TestStack.BDDfy/Reporters/FileReportModel.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ namespace TestStack.BDDfy.Reporters
66
{
77
public class FileReportModel
88
{
9-
public FileReportModel(IEnumerable<Story> stories)
9+
public FileReportModel(ReportModel reportModel)
1010
{
11-
_stories = stories;
12-
Summary = new FileReportSummaryModel(stories);
11+
_stories = reportModel.Stories;
12+
Summary = new FileReportSummaryModel(reportModel);
1313
RunDate = DateTime.Now;
1414
}
1515

16-
readonly IEnumerable<Story> _stories;
16+
readonly IEnumerable<ReportModel.Story> _stories;
1717
public FileReportSummaryModel Summary { get; private set; }
1818
public DateTime RunDate { get; set; }
1919

20-
public IEnumerable<Story> Stories
20+
public IEnumerable<ReportModel.Story> Stories
2121
{
2222
get
2323
{
@@ -35,9 +35,7 @@ group story by story.Metadata.Type.Name into g
3535

3636
var aggregatedStories =
3737
from story in groupedByStories.Union(groupedByNamespace)
38-
select new Story(
39-
story.First().Metadata, // first story in the group is a representative for the entire group
40-
story.SelectMany(s => s.Scenarios).OrderBy(s => s.Title).ToArray()) // order scenarios by title
38+
select new ReportModel.Story() // order scenarios by title
4139
{
4240
Namespace = story.Key
4341
};

0 commit comments

Comments
 (0)