Skip to content

Commit 828599e

Browse files
committed
Modified to conform to changes coming in Query cucumber#84 (Deprecate lineage derived methods).
1 parent 0c69735 commit 828599e

File tree

5 files changed

+149
-146
lines changed

5 files changed

+149
-146
lines changed

dotnet/Query/Query/NamingCollector.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ internal class NamingCollector : ICollector<string>
1313
// There are at most 5 levels to a feature file.
1414
private readonly List<string> parts = new List<string>(5);
1515
private readonly string delimiter = " - ";
16-
private readonly Strategy strategy;
17-
private readonly FeatureName featureName;
18-
private readonly ExampleName exampleName;
16+
private readonly NamingStrategy.Strategy strategy;
17+
private readonly NamingStrategy.FeatureName featureName;
18+
private readonly NamingStrategy.ExampleName exampleName;
1919

2020
private string scenarioName;
2121
private bool isExample;
2222
private int examplesIndex;
2323

24-
public static Func<NamingCollector> Of(Strategy strategy, FeatureName featureName, ExampleName exampleName)
24+
public static Func<NamingCollector> Of(NamingStrategy.Strategy strategy, NamingStrategy.FeatureName featureName, NamingStrategy.ExampleName exampleName)
2525
{
2626
return () => new NamingCollector(strategy, featureName, exampleName);
2727
}
2828

29-
public NamingCollector(Strategy strategy, FeatureName featureName, ExampleName exampleName)
29+
public NamingCollector(NamingStrategy.Strategy strategy, NamingStrategy.FeatureName featureName, NamingStrategy.ExampleName exampleName)
3030
{
3131
this.strategy = strategy;
3232
this.featureName = featureName;
@@ -36,7 +36,7 @@ public NamingCollector(Strategy strategy, FeatureName featureName, ExampleName e
3636
public void Add(GherkinDocument document) { }
3737
public void Add(Feature feature)
3838
{
39-
if (featureName == FeatureName.INCLUDE || strategy == Strategy.SHORT)
39+
if (featureName == NamingStrategy.FeatureName.INCLUDE || strategy == NamingStrategy.Strategy.SHORT)
4040
{
4141
parts.Add(feature.Name);
4242
}
@@ -76,9 +76,9 @@ public void Add(Pickle pickle)
7676
{
7777
switch (exampleName)
7878
{
79-
case ExampleName.NUMBER:
79+
case NamingStrategy.ExampleName.NUMBER:
8080
break;
81-
case ExampleName.NUMBER_AND_PICKLE_IF_PARAMETERIZED:
81+
case NamingStrategy.ExampleName.NUMBER_AND_PICKLE_IF_PARAMETERIZED:
8282
bool parameterized = !scenarioName.Equals(pickleName);
8383
if (parameterized)
8484
{
@@ -87,7 +87,7 @@ public void Add(Pickle pickle)
8787
parts.Add(exampleNumber + ": " + pickleName);
8888
}
8989
break;
90-
case ExampleName.PICKLE:
90+
case NamingStrategy.ExampleName.PICKLE:
9191
parts.RemoveAt(parts.Count - 1); // Remove example number
9292
parts.Add(pickleName);
9393
break;
@@ -99,7 +99,7 @@ public void Add(Pickle pickle)
9999

100100
public string Finish()
101101
{
102-
if (strategy == Strategy.SHORT)
102+
if (strategy == NamingStrategy.Strategy.SHORT)
103103
{
104104
return parts.Count > 0 ? parts[parts.Count - 1] : string.Empty;
105105
}

dotnet/Query/Query/NamingStrategy.cs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,27 @@ namespace Io.Cucumber.Query
66
/// <summary>
77
/// Names Pickles and other elements in a GherkinDocument.
88
/// </summary>
9-
public enum Strategy
9+
public abstract class NamingStrategy : ILineageReducer<string>
1010
{
11-
LONG,
12-
SHORT
13-
}
11+
public enum Strategy
12+
{
13+
LONG,
14+
SHORT
15+
}
1416

15-
public enum ExampleName
16-
{
17-
NUMBER,
18-
PICKLE,
19-
NUMBER_AND_PICKLE_IF_PARAMETERIZED
20-
}
17+
public enum ExampleName
18+
{
19+
NUMBER,
20+
PICKLE,
21+
NUMBER_AND_PICKLE_IF_PARAMETERIZED
22+
}
2123

22-
public enum FeatureName
23-
{
24-
INCLUDE,
25-
EXCLUDE
26-
}
27-
public abstract class NamingStrategy : ILineageReducer<string>
28-
{
24+
25+
public enum FeatureName
26+
{
27+
INCLUDE,
28+
EXCLUDE
29+
}
2930

3031
public static Builder Create(Strategy strategy)
3132
{
@@ -40,8 +41,8 @@ protected NamingStrategy() { }
4041
public class Builder
4142
{
4243
private readonly Strategy _strategy;
43-
private FeatureName _featureName = Io.Cucumber.Query.FeatureName.INCLUDE;
44-
private ExampleName _exampleName = Io.Cucumber.Query.ExampleName.NUMBER_AND_PICKLE_IF_PARAMETERIZED;
44+
private FeatureName _featureName = NamingStrategy.FeatureName.INCLUDE;
45+
private ExampleName _exampleName = NamingStrategy.ExampleName.NUMBER_AND_PICKLE_IF_PARAMETERIZED;
4546

4647
public Builder(Strategy strategy)
4748
{

dotnet/Query/Query/Query.cs

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,6 @@ public IList<TestCaseStarted> FindAllTestCaseStarted() => _testCaseStartedById.V
7171

7272
public IList<TestStep> FindAllTestSteps() => _testStepById.Values.OrderBy(ts => ts.Id).ToList();
7373

74-
public IDictionary<Feature?, List<TestCaseStarted>> FindAllTestCaseStartedGroupedByFeature()
75-
{
76-
// Group TestCaseStarted by Feature (null if not found)
77-
return FindAllTestCaseStarted()
78-
.GroupBy(tcs => FindFeatureBy(tcs))
79-
.ToDictionary(g => g.Key, g => g.ToList());
80-
}
81-
8274
public Meta? FindMeta() => _meta;
8375
public TestRunStarted? FindTestRunStarted() => _testRunStarted;
8476
public TestRunFinished? FindTestRunFinished() => _testRunFinished;
@@ -88,14 +80,8 @@ public IList<Attachment> FindAttachmentsBy(TestStepFinished testStepFinished) =>
8880
? attachments.Where(a => a.TestStepId == testStepFinished.TestStepId).ToList()
8981
: new List<Attachment>();
9082

91-
public Feature? FindFeatureBy(TestCaseStarted testCaseStarted)
92-
{
93-
return FindLineageBy(testCaseStarted)?.Feature;
94-
}
95-
9683
public Hook? FindHookBy(TestStep testStep)
9784
{
98-
// Java: testStep.getHookId().map(hookById::get)
9985
if (!string.IsNullOrEmpty(testStep.HookId) && _hookById.TryGetValue(testStep.HookId, out var hook))
10086
{
10187
return hook;
@@ -105,7 +91,6 @@ public IList<Attachment> FindAttachmentsBy(TestStepFinished testStepFinished) =>
10591

10692
public Pickle? FindPickleBy(TestCaseStarted testCaseStarted)
10793
{
108-
// Java: findTestCaseBy(testCaseStarted).map(TestCase::getPickleId).map(pickleById::get)
10994
var testCase = FindTestCaseBy(testCaseStarted);
11095
if (testCase != null && _pickleById.TryGetValue(testCase.PickleId, out var pickle))
11196
{
@@ -116,7 +101,6 @@ public IList<Attachment> FindAttachmentsBy(TestStepFinished testStepFinished) =>
116101

117102
public Pickle? FindPickleBy(TestStepStarted testStepStarted)
118103
{
119-
// Java: findTestCaseBy(testStepStarted).map(TestCase::getPickleId).map(pickleById::get)
120104
var testCaseStarted = FindTestCaseStartedBy(testStepStarted);
121105
if (testCaseStarted != null)
122106
{
@@ -127,7 +111,6 @@ public IList<Attachment> FindAttachmentsBy(TestStepFinished testStepFinished) =>
127111

128112
public TestCase? FindTestCaseBy(TestCaseStarted testCaseStarted)
129113
{
130-
// Java: testCaseById.get(testCaseStarted.getTestCaseId())
131114
if (_testCaseById.TryGetValue(testCaseStarted.TestCaseId, out var testCase))
132115
{
133116
return testCase;
@@ -137,32 +120,27 @@ public IList<Attachment> FindAttachmentsBy(TestStepFinished testStepFinished) =>
137120

138121
public TestCaseStarted? FindTestCaseStartedBy(TestStepStarted testStepStarted)
139122
{
140-
// Java: testCaseStartedById.get(testStepStarted.getTestCaseStartedId())
141123
return _testCaseStartedById.TryGetValue(testStepStarted.TestCaseStartedId, out var tcs) ? tcs : null;
142124
}
143125

144126
public TestCase? FindTestCaseBy(TestStepStarted testStepStarted)
145127
{
146-
// Java: findTestCaseStartedBy(testStepStarted).flatMap(this::findTestCaseBy)
147128
var testCaseStarted = FindTestCaseStartedBy(testStepStarted);
148129
return testCaseStarted != null ? FindTestCaseBy(testCaseStarted) : null;
149130
}
150131

151132
public TestStep? FindTestStepBy(TestStepStarted testStepStarted)
152133
{
153-
// Java: testStepById.get(testStepStarted.getTestStepId())
154134
return _testStepById.TryGetValue(testStepStarted.TestStepId, out var testStep) ? testStep : null;
155135
}
156136

157137
public TestStep? FindTestStepBy(TestStepFinished testStepFinished)
158138
{
159-
// Java: testStepById.get(testStepFinished.getTestStepId())
160139
return _testStepById.TryGetValue(testStepFinished.TestStepId, out var testStep) ? testStep : null;
161140
}
162141

163142
public PickleStep? FindPickleStepBy(TestStep testStep)
164143
{
165-
// Java: testStep.getPickleStepId().map(pickleStepById::get)
166144
if (!string.IsNullOrEmpty(testStep.PickleStepId))
167145
{
168146
if (_pickleStepById.TryGetValue(testStep.PickleStepId, out var pickleStep))
@@ -175,7 +153,6 @@ public IList<Attachment> FindAttachmentsBy(TestStepFinished testStepFinished) =>
175153

176154
public Step? FindStepBy(PickleStep pickleStep)
177155
{
178-
// Java: String stepId = pickleStep.getAstNodeIds().get(0); stepById.get(stepId)
179156
if (pickleStep.AstNodeIds != null && pickleStep.AstNodeIds.Count > 0)
180157
{
181158
var stepId = pickleStep.AstNodeIds[0];
@@ -202,13 +179,11 @@ public IList<Attachment> FindAttachmentsBy(TestStepFinished testStepFinished) =>
202179

203180
public TestCaseFinished? FindTestCaseFinishedBy(TestCaseStarted testCaseStarted)
204181
{
205-
// Java: testCaseFinishedByTestCaseStartedId.get(testCaseStarted.getId())
206182
return _testCaseFinishedByTestCaseStartedId.TryGetValue(testCaseStarted.Id, out var finished) ? finished : null;
207183
}
208184

209185
public System.TimeSpan? FindTestRunDuration()
210186
{
211-
// Java: if (testRunStarted == null || testRunFinished == null) return Optional.empty();
212187
if (_testRunStarted == null || _testRunFinished == null)
213188
return null;
214189
var start = Converters.ToDateTime(_testRunStarted.Timestamp);
@@ -218,18 +193,15 @@ public IList<Attachment> FindAttachmentsBy(TestStepFinished testStepFinished) =>
218193

219194
public IList<TestStepStarted> FindTestStepsStartedBy(TestCaseStarted testCaseStarted)
220195
{
221-
// Java: testStepsStartedByTestCaseStartedId.getOrDefault(testCaseStarted.getId(), emptyList())
222196
if (_testStepsStartedByTestCaseStartedId.TryGetValue(testCaseStarted.Id, out var steps))
223197
{
224-
// Return a copy for concurrency safety
225198
return new List<TestStepStarted>(steps);
226199
}
227200
return new List<TestStepStarted>();
228201
}
229202

230203
public IList<TestStepFinished> FindTestStepsFinishedBy(TestCaseStarted testCaseStarted)
231204
{
232-
// Java: testStepsFinishedByTestCaseStartedId.getOrDefault(testCaseStarted.getId(), emptyList())
233205
if (_testStepsFinishedByTestCaseStartedId.TryGetValue(testCaseStarted.Id, out var steps))
234206
{
235207
// Return a copy for concurrency safety
@@ -240,11 +212,6 @@ public IList<TestStepFinished> FindTestStepsFinishedBy(TestCaseStarted testCaseS
240212

241213
public IList<(TestStepFinished, TestStep)> FindTestStepFinishedAndTestStepBy(TestCaseStarted testCaseStarted)
242214
{
243-
// Java: findTestStepsFinishedBy(testCaseStarted).stream()
244-
// .map(testStepFinished -> findTestStepBy(testStepFinished).map(testStep -> new SimpleEntry<>(testStepFinished, testStep)))
245-
// .filter(Optional::isPresent)
246-
// .map(Optional::get)
247-
// .collect(toList());
248215
var finishedSteps = FindTestStepsFinishedBy(testCaseStarted);
249216
var result = new List<(TestStepFinished, TestStep)>();
250217
foreach (var testStepFinished in finishedSteps)
@@ -470,62 +437,6 @@ public void Update(Envelope envelope)
470437
}
471438
return FindLineageBy(pickle);
472439
}
473-
474-
public string FindNameOf(GherkinDocument element, NamingStrategy namingStrategy)
475-
{
476-
if (element == null) return string.Empty;
477-
var lineage = FindLineageBy(element);
478-
return GetNameFromStrategy(element, lineage, namingStrategy);
479-
}
480-
481-
public string FindNameOf(Feature element, NamingStrategy namingStrategy)
482-
{
483-
if (element == null) return string.Empty;
484-
var lineage = FindLineageBy(element);
485-
return GetNameFromStrategy(element, lineage, namingStrategy);
486-
}
487-
488-
public string FindNameOf(Rule element, NamingStrategy namingStrategy)
489-
{
490-
if (element == null) return string.Empty;
491-
var lineage = FindLineageBy(element);
492-
return GetNameFromStrategy(element, lineage, namingStrategy);
493-
}
494-
495-
public string FindNameOf(Scenario element, NamingStrategy namingStrategy)
496-
{
497-
if (element == null) return string.Empty;
498-
var lineage = FindLineageBy(element);
499-
return GetNameFromStrategy(element, lineage, namingStrategy);
500-
}
501-
502-
public string FindNameOf(Examples element, NamingStrategy namingStrategy)
503-
{
504-
if (element == null) return string.Empty;
505-
var lineage = FindLineageBy(element);
506-
return GetNameFromStrategy(element, lineage, namingStrategy);
507-
}
508-
509-
public string FindNameOf(TableRow element, NamingStrategy namingStrategy)
510-
{
511-
if (element == null) return string.Empty;
512-
var lineage = FindLineageBy(element);
513-
return GetNameFromStrategy(element, lineage, namingStrategy);
514-
}
515-
516-
public string FindNameOf(Pickle element, NamingStrategy namingStrategy)
517-
{
518-
if (element == null) return string.Empty;
519-
var lineage = FindLineageBy(element);
520-
var result = namingStrategy.Reduce(lineage, element);
521-
if (result == null)
522-
{
523-
throw new ArgumentException("Element was not part of this query object");
524-
}
525-
return result;
526-
527-
}
528-
529440
public Location? FindLocationOf(Pickle pickle)
530441
{
531442
var lineage = FindLineageBy(pickle);
@@ -537,15 +448,4 @@ public string FindNameOf(Pickle element, NamingStrategy namingStrategy)
537448
return lineage.Scenario.Location;
538449
return null;
539450
}
540-
541-
// Placeholder for actual naming strategy logic
542-
private string GetNameFromStrategy(object element, Lineage? lineage, NamingStrategy namingStrategy)
543-
{
544-
var result = namingStrategy.Reduce(lineage);
545-
if (result == null)
546-
{
547-
throw new ArgumentException("Element was not part of this query object");
548-
}
549-
return result;
550-
}
551451
}

0 commit comments

Comments
 (0)