How do you configure Fixture to use the initial values correctly .
The behavior you see is a consequence of how the FromSeed setting changes the AutoFixture pipeline. If you are interested in knowing the details, I described them here .
As a workaround, you can use a custom instance for seed queries, such as:
public class RelaxedSeededFactory<T> : ISpecimenBuilder { private readonly Func<T, T> create; public RelaxedSeededFactory(Func<T, T> factory) { this.create = factory; } public object Create(object request, ISpecimenContext context) { if (request != null && request.Equals(typeof(T))) { return this.create(default(T)); } var seededRequest = request as SeededRequest; if (seededRequest == null) { return new NoSpecimen(request); } if (!seededRequest.Request.Equals(typeof(T))) { return new NoSpecimen(request); } if ((seededRequest.Seed != null) && !(seededRequest.Seed is T)) { return new NoSpecimen(request); } var seed = (T)seededRequest.Seed; return this.create(seed); } }
Then you can use it to create objects of type Foo as follows:
fixture.Customize<Foo>(c => c.FromFactory( new RelaxedSeededFactory<Foo>(TestFooFactory)));
This setting will pass default(Foo) - this is null - as the start of the TestFooFactory factory function when populating properties of type Foo .
source share