2

我尝试使用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>

4

1 回答 1

3

AutoFixture 2.1 将有各种多重y 模型的约定。计划是在GOTO Copenhagen之前推出 2.1 。

于 2011-04-16T09:36:57.157 回答