Read a bit more on Mark's blog (this particularly) I found the way to do what I want:
/// <summary>
/// Customisation to ignore the virtual members in the class - helps ignoring the navigational
/// properties and makes it quicker to generate objects when you don't care about these
/// </summary>
public class IgnoreVirtualMembers : ISpecimenBuilder
{
public object Create(object request, ISpecimenContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
var pi = request as PropertyInfo;
if (pi == null)
{
return new NoSpecimen(request);
}
if (pi.GetGetMethod().IsVirtual)
{
return null;
}
return new NoSpecimen(request);
}
}
And you can wrap these into customisation:
public class IgnoreVirtualMembersCustomisation : ICustomization
{
public void Customize(IFixture fixture)
{
fixture.Customizations.Add(new IgnoreVirtualMembers());
}
}
So in your test you just do:
var fixture = new Fixture().Customize(new IgnoreVirtualMembersCustomisation());
and go create your complex models.
Enjoy!