我尝试使用AutoFixture 2为具有ICollection成员的EntityFramework4类生成testdata。
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>();
我的问题是
如果需要List<T>
,是否有人知道某种方式或约定告诉AutoFixture始终使用ICollection<T>
?
答案 0 :(得分:3)
AutoFixture 2.1将有conventions for various models of multiplicit y。计划是在GOTO Copenhagen之前获得2.1。