Skip to content

Conversion conventions

Marcus Hammarberg edited this page Jan 23, 2016 · 5 revisions

SpecFlow.Assist.Dynamic uses a few conventions, for conversion of Gherkin to code, that helps you keep your specification readable for non-technical team members and business users but still usable when translated to code:

Column names to properties

When translating column names to properties spaces are removed and each new word is capitalised. The first word is left alone though. So for example:

  • Birth date translates to BirthDate
  • Total score is translated to TotalScore
  • age is translated to age
  • age average is translated to ageAverage

Reserved characters allowed

You can even use reserved chars like #$() etc in your column names. SpecFlow.Assist.Dynamic will simply take those away. Any thing that is not a-z, A-Z, 1-9 or an underscore is stripped out.

Here's some specs that show you how this works:

Scenario: Using reserved C# characters in column names
	When I create a dynamic instance from this table
		| C$harp n@me (with strange chars) |
		| A value | 
	Then the CharpNmeWithStrangeChars property should equal 'A value'

Scenario: Only alpha-numeric characters, plus underscore is allowed in variable names
       When I create a dynamic instance from this table
		| My_Nice_Variable | My $$ Variable (needs clean up) |
		| A value |  Another value |
	Then the My_Nice_Variable property should equal 'A value'
           And the MyVariableNeedsCleanUp property should equal 'Another value'

Scenario: Using only reserved C# characters in column names
	When I create a dynamic instance from this table
		| $@() |
		| A value | 
	Then an exception with a nice error message about the property only containing reserved chars should be thrown

There's some logging that shows how the conversions are made:

 - converted  'Birth date' to property 'BirthDate'
 - converted  'C$harp n@me (with strange chars)' to property 'CharpNmeWithStrangeChars'

Property type conversions

SpecFlow.Assist.Dynamic will try to do a basic value conversion. Properties will be converted into DateTime, double, bool and int. It does a TryParse for each and falls back to ordinary strings if nothing fits.

Clone this wiki locally