SpecFlow Table.CreateInstance returns null
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 function
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 | Grim.Smith@gmail.com |
And my definitions of steps
[When(@"I add a new contact information")]
public void WhenIAddANewContactInformation(Table table)
{
MerchantContactDetails ContactDetails = table.CreateInstance<MerchantContactDetails>();
}
When the script is executed, I see the ContactDetails is null. However, the object table has a number of rows that is set to 1 and I could explicitly access the call
table.Rows[0]["title"] => this works fine
only table.CreateInstance (); returns null
Please can someone point me in the right direction ..?
Regards
+3
source to share
1 answer
Finally, I was able to find a solution. Turning all properties into properties makes the SpecFlow populate the object. Now the class definition looks like
public class MerchantContactDetails
{
public string Title{get;set;}
public string Firstname{get;set;}
public string Lastname{get;set;}
public string Companyposition{get;set;}
public string Phonecode{get;set;}
public string Phoneno{get;set;}
public string Mobilecode{get;set;}
public string Mobileno{get;set;}
public string Email{get;set;}
}
@Sam Holder, thanks for your suggestion. Column names can be case insensitive. May also contain spaces. For example, in the SpecFlow function we can have a name and it matches the first first class perfectly.
+3
source to share