Default Values Specflow Step Definitions
- by Gavin Osborn
I'm starting out in the world of SpecFlow and I have come across my first problem.
In terms of keeping my code DRY I'd like to do the following:
Have two scenarios:
Given I am on a product page
And myfield equals todays date
Then...
Given I am on a product page
And myfield equals todays date plus 4 days
Then...
I was hoping to use the following Step Definition to cover both variants of my And clause:
[Given(@"myfield equals todays date(?: (plus|minus) (\d+) days)?")]
public void MyfieldEqualsTodaysDate(string direction, int? days)
{
//do stuff
}
However I keep getting exceptions when SpecFlow tries to parse the int? param.
I've checked the regular expression and it definitely parses the scenario as expected.
I'm aware that I could so something as crude as method overloading etc, I was just wondering if SpecFlow supported the idea of default parameter values, or indeed another way to achieve the same effect.
Many Thanks