I try to use AutoFixture 2 to generate testdata for EntityFramework4 classes that have ICollection member.
public class Parent
{
public virtual ICollection<Child1> Children1 { get; set; }
public virtual ICollection<Child2> Children2 { get; set; }
...
public virtual ICollection<Child759> Children759 { get; set; }
}
var factory = new Ploeh.AutoFixture.Fixture();
var parent = factory.CreateAnonymous<Parent>();
Since AutoFixture cannot resolve ICollection<Child1>
i get an Ploeh.AutoFixture.ObjectCreationException
The only solution i found so far is to register every possible 'ICollection` like this
var factory = new Fixture();
factory.Register<ICollection<Child1>>(() =>
new List<Child1>());
...
factory.Register<ICollection<Child759>>(() =>
new List<Child759>());
var parent = factory.CreateAnonymous<Parent>();
My question is
Does anybody know a way or a Convention to tell AutoFixture always to use List<T>
if a ICollection<T>
is required?