Default Values Specflow Step Definitions

Posted by Gavin Osborn on Stack Overflow See other posts from Stack Overflow or by Gavin Osborn
Published on 2011-02-07T14:42:31Z Indexed on 2012/06/12 4:40 UTC
Read the original article Hit count: 185

Filed under:
|
|
|

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

© Stack Overflow or respective owner

Related posts about .NET

Related posts about testing