|
| 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 | +} |
0 commit comments