AutoProperties AutoFixture properties are assigned values ββonly for writable properties. The reason ParentClass.Children not populated is because it is a read-only property. - AutoFixture does not try to assign a value because it knows that this is not possible.
However, assuming you already have an instance of ParentClass, you can ask AutoFixture to fill out the collection for you:
fixture.AddManyto(parentClass.Children);
This can be encapsulated in a setting like this:
fixture.Customize<ParentClass>(c => c.Do(pc => fixture.AddManyTo(pc.Children)));
Since Children is an IList<ChildClass> , you also need to provide a mapping if you are not using MultipleCustomization :
fixture.Register<IList<ChildClass>>(() => fixture.CreateMany<ChildClass>().ToList());
This is definitely the behavior that we considered an addition to MultipleCustomization, but decided to postpone to version 2.1 , because it is not so completely simple to implement.
source share