How do I create a list of classes which always have a predefined value set in AutoFixture?
how do I crea开发者_开发百科te a collection of classes which always have a certain predefined value set in AutoFixture?
Fixture.Register<IList<Child>>(() => Fixture.CreateMany<Child>().ToList());
Say the child class has the following:
public class Child
{
public int ParentId { get; set; }
public int ChildId { get; set; }
public string ChildName { get; set; }
public int ChildValue { get; set; }
}
How do I ensure the anonymous classes always have the same parent Id whilst all other properties can be random? I guess it would also be advisable to set ChildId to 0 too as these will be pushed into a database in a repository data test.
Have you tried this?
fixture.Customize<Child>(c => c.With(x => x.ParentId, 42).With(x => x.ChildId, 0));
精彩评论