I am using SpecFlow version 1.9.0 I have a POCO class
public class MerchantContactDetails
{
public string Title;
public string Firstname;
public string Lastname;
public string Companyposition;
public string Phonecode;
public string Phoneno;
public string Mobilecode;
public string Mobileno;
public string Email;
}
My Specflow feature is
Scenario: Sample contact
When I add a new contact information
| title | firstname | lastname | companyposition | phonecode | phoneno | mobilecode | mobileno | email |
| Mr | Grim | Smith | Director | 1 (US) | 12345 | 1 (US) | 45678 | [email protected] |
And my step definitions has
[When(@"I add a new contact information")]
public void WhenIAddANewContactInformation(Table table)
{
MerchantContactDetails ContactDetails = table.CreateInstance<MerchantContactDetails>();
}
When the scenario is executed, I see ContactDetails is set to null. However object table has Rows count set 1 and I could access values explicitly by call
table.Rows[0]["title"] => this works fine
only table.CreateInstance(); returns null
Please can someone point me in the right direction..?
Best Regards
Finally I was able to find a solution. Turning all the fileds into properties makes SpecFlow to fill the object. The class definition now looks
@ Sam Holder, thanks for your suggestion. The names of the columns can be case-insensitive. May also contain spaces. For example in SpecFlow feature we may have First Name, and it perfectly matches the class property firstname.