Hi Leland,
I'm sorry for the trouble you're having. I don't know how to fix it, but I can explain the problem and perhaps offer a suggestion.
The problem is that the CreateSet method uses only a default constructor (with no arguments) to instantiate the objects. If you added the following constructor to your object:
public class Product{
public Product(){
}
// ... everything else you already have
}
Then CreateSet<T> will work for you.
Just because you say you are new: With C#, every class you create gets a default constructor... *unless* you create your own. So if you just make a class like this:
public Product(){
}
you can instantiate it with Product.new(). But if you create a constructor like yours, the default one goes away. If you want it, you'll have to add it yourself with the code I listed above.
I hope that helps,
Darren
On Wednesday, February 27, 2013 8:08:36 AM UTC-6, Leland Schick wrote:
I'm trying to use SpecFlow.Assist with a custom class in C#, along with Mbunit, and my tests are all failing but for trivial reasons. The example I have is like this (I'm using the example from the documentation to explain the problem). Here's the SpecFlow Feature step:Given these products exist
| Sku | Name | Price |
| BOOK1 | Atlas Shrugged | 25.04 |
| BOOK2 | The Fountainhead | 20.15 |
And here's the step definition, using SpecFlow.Assist to make an IEnumerable of the Product class:
[Given(@"Given these products exist")]
public void x(Table table)
{
var products = table.CreateSet<Product>();
// ...
}
And finally, here's the very basic class definition,
public class Product
{
public Product(string sku, string name, double price)
{
this.Sku = sku;
this.Name = name;
this.Price = price;
}
public string Sku { get; set; }
public string Name { get; set; }
public double Price { get; set; }
This compiles fine, but when I try to run the tests, they all fail because at the first step there is an error which reads, "Unable to find a suitable constructor to create instance of Product." What kind of constructor should I write so that it can be used by the CreateSet method to generate an IEnumerable<Product>? Maybe I'm doing something basic wrong (I am very new with SpecFlow, and even .NET programming in general