Jan 7, 2014 at 5:42 AM
Edited Jan 7, 2014 at 5:44 AM
I am using Customize to set parent properties to null when creating child instances.
thus creates all the children of Parent with null Parent properties.
Is there a way to add a customization that will automatically set the parent property when fixture.Create<Parent>() is pre-empted.
fixture.Customize<A>(o => o.With(_ => _.Parent, null));
fixture.Customize<B>(o => o.With(_ => _.Parent, null));
fixture.Customize<C>(o => o.With(_ => _.Parent, null));
fixture.Customize<D>(o => o.With(_ => _.Parent, null));
Ideally I would like the parent properties set to the parent when the child instances are created.
Jan 7, 2014 at 4:08 PM
There's no such thing built in, partly for the reasons outlined
, and partly because it would result in an infinite recursion.
My best advice is to change your API so that you don't have circular references. Not only will it make it easier for you to use AutoFixture, but it will also make it easier for you to use your API.
If you can't change the API, perhaps you can use
this proposed solution