我尝试使用AutoFixture 2为具有 ICollection 成员的 EntityFramework4 类生成测试数据。
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>();
由于 AutoFixture 无法解决ICollection<Child1>
我得到一个Ploeh.AutoFixture.ObjectCreationException
到目前为止,我发现的唯一解决方案是像这样注册每个可能的“ICollection”
var factory = new Fixture();
factory.Register<ICollection<Child1>>(() =>
new List<Child1>());
...
factory.Register<ICollection<Child759>>(() =>
new List<Child759>());
var parent = factory.CreateAnonymous<Parent>();
我的问题是
有没有人知道告诉 AutoFixture 总是在需要时使用的方法或List<T>
约定ICollection<T>
?