Replies: 3 comments 12 replies
-
This is a good initiative and I was also thinking about that already. Without going into the details, basically the challenge is that tables are detached from the scenario execution context, but for performing the conversions we would need to have a scenario execution context. This is the reason why we cannot use I see two approaches:
Both options have pros and cons... I don't know. What do you think? |
Beta Was this translation helpful? Give feedback.
-
it looks like I have a similar issue with ValueRetrievers but another approach |
Beta Was this translation helpful? Give feedback.
-
Hello, |
Beta Was this translation helpful? Give feedback.
-
Currently when using for instance
Table.CreateInstance<SomeClass>()
internally all ValueRetrievers are stored in a static collection. This means that the first call will fix the ValueRetrievers for the entire test run.Given an application with a data store and a scenario such as the following:
When the record stored actually contains the data ABC then implementation is relatively straightforward. But imagine that the Customer record is actually just some long difficult string (for instance
easdjkf87ewrkhjasdh789ewrkjsasf
with some other non-relevant data. Writing those in scenario's is not something I would want.So a translation from the identifier used in the scenario and the actual scenario is needed. We use a ValueRetriever (and a StepArgumentTransformation) that is given a per scenario container to generate a mapping between in this case
ABC
andeasdjkf87ewrkhjasdh789ewrkjsasf
, specifically:The above is just a simplification of what we actually do, btw, but I hope the point comes across.
The above will work perfectly fine when all of the scenarios are executed in sequence as the Register call will overwrite the previous registration.
It breaks down when scenarios are executed in parallel as the ValueRetriever used most likely is given a context belonging to a different scenario, whereas the StepArgumentTransformation used will be given the proper context.
The issue is that the TEHelpers internally use the Reqnroll.Assist.Service.Instance method, which creates a single static instace that stores a list of ValueComparers and ValueRetrievers. A bit like how the ScenarioContext and FeatureContext used to be static as well.
I'd like to change this to something like a TableHelpers class that is injected through the DI. Which would mean that instead of writing table.CreateSet<>(), you'd write tablehelpers.CreateSet<>(table). The TableHelpers would then have an instance of the Service injected, which would make the ValueRetrievers changeable per scenario, I think.
Is this an approach that is viable?
(see also https://github.com/SpecFlowOSS/SpecFlow/issues/2492)
Beta Was this translation helpful? Give feedback.
All reactions