ttutisani/Xunit.Gherkin.Quick

Pass string as list

Enough7 opened this issue · 3 comments

Hey,
consider the following code:

Scenario: <...>
    Given A graph with Nodes named A, B, C, D

Is it possible to pass A, B, C, D as a List<string>? Like so:

[Given(@"A graph with Nodes named <magic regex>")]
public void AGraphWithNodesNamed(string nodeNames)
{
    ...
}

You should write the regex expression that will match "A, B, C, D" or whatever. The entire, comma-separated values will be matched as one string, which will be in the nodeNames variable when the method executes.

Have a look at this page for examples of various regexes. You can look up online the examples of matching comma-separated values.

Note that you cannot have a List<string> argument in the method. This is not currently supported. Only primitive types can be used for the arguments.

After some thought, maybe you can use DataTable as an argument, which is supported. So, instead of passing it as comma-separated values, you will write it as a table in the feature file, and you will receive it in the DataTable argument, which has rows. So each value will be on a new row.

Thank you! Do you mind if I add some of this information to the readme?

I don't mind. Please add where you expected to find this information, and others will find it there in the future.

Thank you!