Skip to content

Commit 546de0c

Browse files
mwhelanJakeGinnivan
authored andcommitted
got existing tests passing with ReportModel
1 parent 3252bf3 commit 546de0c

10 files changed

Lines changed: 237 additions & 214 deletions

File tree

TestStack.BDDfy/Reporters/Class1.cs

Lines changed: 0 additions & 180 deletions
This file was deleted.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
namespace TestStack.BDDfy.Reporters
6+
{
7+
public class ReportModel
8+
{
9+
public List<ReportModel.Story> Stories { get; set; }
10+
11+
public ReportModel()
12+
{
13+
Stories = new List<Story>();
14+
}
15+
16+
public class Story
17+
{
18+
public Story()
19+
{
20+
Scenarios = new List<Scenario>();
21+
}
22+
23+
public string Namespace { get; set; }
24+
public Result Result { get; set; }
25+
public List<Scenario> Scenarios { get; set; }
26+
public StoryMetadata Metadata { get; set; }
27+
}
28+
29+
public class StoryMetadata
30+
{
31+
public Type Type { get; set; }
32+
public string Title { get; set; }
33+
public string TitlePrefix { get; set; }
34+
public string Narrative1 { get; set; }
35+
public string Narrative2 { get; set; }
36+
public string Narrative3 { get; set; }
37+
}
38+
39+
public class Scenario
40+
{
41+
public Scenario()
42+
{
43+
Tags = new List<string>();
44+
Steps = new List<Step>();
45+
}
46+
47+
public string Id { get; set; }
48+
49+
public string Title { get; set; }
50+
51+
public List<string> Tags { get; set; }
52+
53+
public Example Example { get; set; }
54+
55+
public TimeSpan Duration { get; set; }
56+
57+
public List<Step> Steps { get; set; }
58+
59+
public Result Result { get; set; }
60+
}
61+
62+
public class Step
63+
{
64+
public string Id { get; set; }
65+
66+
public bool Asserts { get; set; }
67+
68+
public bool ShouldReport { get; set; }
69+
70+
public string Title { get; set; }
71+
72+
public ExecutionOrder ExecutionOrder { get; set; }
73+
74+
public Result Result { get; set; }
75+
76+
public Exception Exception { get; set; }
77+
78+
public TimeSpan Duration { get; set; }
79+
}
80+
81+
public class Example
82+
{
83+
public Example()
84+
{
85+
Values = new List<ExampleValue>();
86+
}
87+
88+
public string[] Headers { get; set; }
89+
90+
public IEnumerable<ExampleValue> Values { get; set; }
91+
92+
public override string ToString()
93+
{
94+
return string.Join(", ", Values.Select(i => i.ToString()));
95+
}
96+
}
97+
}
98+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
namespace TestStack.BDDfy.Reporters
2+
{
3+
using System.Collections.Generic;
4+
5+
public static class ReportModelMappers
6+
{
7+
public static ReportModel ToReportModel(this IEnumerable<Story> stories)
8+
{
9+
var report = new ReportModel();
10+
foreach (var story in stories)
11+
{
12+
report.Stories.Add(story.ToStoryModel());
13+
}
14+
15+
return report;
16+
}
17+
18+
public static ReportModel.Story ToStoryModel(this Story story)
19+
{
20+
if (story == null)
21+
return null;
22+
23+
var model = new ReportModel.Story
24+
{
25+
Namespace = story.Namespace,
26+
Result = story.Result,
27+
Metadata = story.Metadata.ToStoryMetadataModel()
28+
};
29+
30+
foreach (var scenario in story.Scenarios)
31+
{
32+
model.Scenarios.Add(scenario.ToScenarioModel());
33+
}
34+
35+
return model;
36+
}
37+
38+
public static ReportModel.StoryMetadata ToStoryMetadataModel(this StoryMetadata metadata)
39+
{
40+
if (metadata == null)
41+
return null;
42+
43+
return new ReportModel.StoryMetadata
44+
{
45+
Type = metadata.Type,
46+
Title = metadata.Title,
47+
TitlePrefix = metadata.TitlePrefix,
48+
Narrative1 = metadata.Narrative1,
49+
Narrative2 = metadata.Narrative2,
50+
Narrative3 = metadata.Narrative3,
51+
};
52+
}
53+
public static ReportModel.Scenario ToScenarioModel(this Scenario scenario)
54+
{
55+
if (scenario == null)
56+
return null;
57+
58+
var model = new ReportModel.Scenario
59+
{
60+
Id = scenario.Id,
61+
Title = scenario.Title,
62+
Tags = scenario.Tags,
63+
Example = scenario.Example != null ? scenario.Example.ToExampleModel() : null,
64+
Duration = scenario.Duration,
65+
Result = scenario.Result
66+
};
67+
scenario.Steps.ForEach(x => model.Steps.Add(x.ToStepModel()));
68+
return model;
69+
}
70+
71+
public static ReportModel.Step ToStepModel(this Step step)
72+
{
73+
if (step == null)
74+
return null;
75+
76+
return new ReportModel.Step
77+
{
78+
Id = step.Id,
79+
Asserts = step.Asserts,
80+
ShouldReport = step.ShouldReport,
81+
Title = step.Title,
82+
ExecutionOrder = step.ExecutionOrder,
83+
Result = step.Result,
84+
Exception = step.Exception,
85+
Duration = step.Duration
86+
};
87+
}
88+
89+
public static ReportModel.Example ToExampleModel(this Example example)
90+
{
91+
if (example == null)
92+
return null;
93+
94+
return new ReportModel.Example
95+
{
96+
Headers = example.Headers,
97+
Values = example.Values
98+
};
99+
}
100+
}
101+
}

0 commit comments

Comments
 (0)