使用 AutoFixture 测试数据生成:解析 ICollection不提每一个T
我尝试使用 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
我得到一个 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
,有人知道一种方法或约定来告诉 AutoFixture 始终使用 List
吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AutoFixture 2.1 将具有各种多重模型的约定。计划是在GOTO Copenhagen之前发布2.1。
AutoFixture 2.1 will have conventions for various models of multiplicity. The plan is to get 2.1 out before GOTO Copenhagen.