One option is to create a Customization that omits properties of a certain name:
internal class PropertyNameOmitter : ISpecimenBuilder
{
private readonly IEnumerable<string> names;
internal PropertyNameOmitter(params string[] names)
{
this.names = names;
}
public object Create(object request, ISpecimenContext context)
{
var propInfo = request as PropertyInfo;
if (propInfo != null && names.Contains(propInfo.Name))
return new OmitSpecimen();
return new NoSpecimen(request);
}
}
You may use it as below:
var fixture = new Fixture();
fixture.Customizations.Add(
new PropertyNameOmitter("AllContacts"));
var sut = fixture.Create<OfficeBuilding>();
// -> The 'AllContacts' property should be omitted now.
See also: