Is it possible to share data in DependsOn method chains? #4453
|
Scenario: I have 3 test methods: Create, Modify (DependsOn on Create) and Delete (DependsOn on Modify). I have tried using the StateBag of the previous method, but this does not work since it just gets the StateBag of a previous test method that has executed last. Is it possible to share data in DependsOn chains? |
Replies: 3 comments 1 reply
Not sure I quite follow? If you store data in the Create State bag, your modify tests should be able to use that. Calling I'd iterate through each of them and try something like: The TryRemove should remove it from the dictionary so only one test ever gets it, and then next repeat will then move on to the next test etc |
|
Ah! I already moved on to using a keyed data source with created-IDs and modified-IDs and pushing/popping these. But I didn't thought of "popping" them directly from the StateBag like you described. |
|
Works! |
Not sure I quite follow? If you store data in the Create State bag, your modify tests should be able to use that.
Calling
TestContext.GetTests(...)should give you an array of tests, so all of those repeats. The order of these won't be deterministic, so I would probably try to get an Id from the bag and remove it so another test can't see it.I'd iterate through each of them and try something like:
The TryRemove should remove it from the d…