-
Notifications
You must be signed in to change notification settings - Fork 113
Elimination of the PickleIndex from Row Test Method Signature #938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
78510ee
523982b
8fd8575
b4a1517
302ba97
46a9eca
a536a37
b762676
83ceccd
efa40d8
22cb837
ffb8329
b67bd67
9956581
444cdce
9303148
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| using Io.Cucumber.Messages.Types; | ||
| using System.Collections; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
|
|
||
| namespace Reqnroll.Formatters.RuntimeSupport; | ||
|
|
||
| public static class TestRowPickleMapper | ||
| { | ||
| public static object ComputeHash(string featureName, string scenarioOutlineName, IEnumerable<string> tags, IEnumerable<string> rowValues) | ||
| { | ||
| var tagsList = tags ?? Enumerable.Empty<string>(); | ||
| var rowValuesList = rowValues ?? Enumerable.Empty<string>(); | ||
| var v = $"{featureName}|{scenarioOutlineName}|{string.Join("|", tagsList)}|{string.Join("|", rowValuesList)}"; | ||
| return v.GetHashCode(); | ||
|
||
| } | ||
|
|
||
| public static void MarkPickleWithRowHash(IEnumerable<Envelope> envelopes, int pickleIndex, object rowHash) | ||
| { | ||
| var pickle = envelopes | ||
| .Where(e => e.Pickle != null) | ||
| .Select(e => e.Pickle) | ||
| .ElementAt(pickleIndex); | ||
| pickle.Tags.Add(new Io.Cucumber.Messages.Types.PickleTag($"@RowHash_{rowHash}", "")); | ||
| } | ||
|
|
||
| public static string GetPickleIndexFromTestRow(string featureName, string scenarioOutlineName, IEnumerable<string> tags, ICollection rowValues, IEnumerable<Pickle> pickles) | ||
| { | ||
| var rowValuesStrings = rowValues.Cast<object>().Select(v => v?.ToString() ?? string.Empty); | ||
| var rowHash = ComputeHash(featureName, scenarioOutlineName, tags, rowValuesStrings); | ||
| var tagName = $"@RowHash_{rowHash}"; | ||
| for (int i = 0; i < pickles.Count(); i++) | ||
| { | ||
| var pickle = pickles.ElementAt(i); | ||
gasparnagy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // at this point, if the pickle has a tag with the row hash, we found it; | ||
| // in a thread safe way, remove the tag so that subsequent calls do not find the same pickle again | ||
| lock (pickle.Tags) | ||
| { | ||
| var tag = pickle.Tags.FirstOrDefault(t => t.Name == tagName); | ||
| if (tag != null) | ||
| { | ||
| pickle.Tags.Remove(tag); | ||
| return i.ToString(); | ||
| } | ||
| } | ||
|
||
| } | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have to make this public? It would be better if feature info would only expose things publicly that the users can/should work with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see it now - it is used in the generated code. I would pass the entire FeatureInfo to
GetPickleIndexFromTestRow, so that it can access the internal prop.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverted and modified code gen per suggestion.