Yes, Build
is correct.
If you want to customize the creation algorithm for a single Category
use Build
:
var actual = fixture
.Build<Category>()
.With(x => x.SubCategories,
fixture.CreateMany<Category>().ToList())
.Create();
Assert.NotEmpty(actual.SubCategories);
If you want to customize the creation algorithm for all Category
instances use Customize
:
fixture.Customize<Category>(c => c
.With(x => x.SubCategories,
fixture.CreateMany<Category>().ToList()));
var actual = fixture.Create<Category>();
Assert.NotEmpty(actual.SubCategories);