2

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?

4

1 に答える 1

3

AutoFixture 2.1 will have conventions for various models of multiplicity. The plan is to get 2.1 out before GOTO Copenhagen.

于 2011-04-16T09:36:57.157 に答える