【发布时间】:2011-08-06 19:55:39
【问题描述】:
我尝试使用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>();
我的问题是
如果需要ICollection<T>,是否有人知道告诉 AutoFixture 始终使用 List<T> 的方法或约定?
【问题讨论】:
标签: c# entity-framework testing test-data autofixture