I'm trying to customize the data that is generated in a class .. where a property is another class.
eg.
public class Foo
{
public string Id { get; set; }
public Baa Baa { get; set; }
}
public class Baa
{
// 30 properties which are strings, ints, etc.
}
I was wondering if i could do something like this...
var fixture = new Fixture();
return fixture.Build<Foo>()
.With(x => x.Id, $"Foo-{fixture.Create<int>()}")
.With(x => x.Baa, CreateSomeCustomBaaUsingAutofixture)
.Create();
and then ..
private Baa CreateSomeCustomBaaUsingAutofixture()
{
var fixture = new Fixture();
return fixture.Build<Baa>()
.With(lots of customizations here)
.Create();
}
Is there a cleaner way of doing this? Or is .. that basically the only/recommended way?
I understand that AutoFixture can automatically create an instance of a Baa
for me and data for the properties in there. I was just hoping to just customize it a bit more.