Reputation: 27350
how do I create 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.
Upvotes: 3
Views: 511
Reputation: 233150
Have you tried this?
fixture.Customize<Child>(c => c.With(x => x.ParentId, 42).With(x => x.ChildId, 0));
Upvotes: 1