.NET AutoFixture without initializing Inherited properties

29 Views Asked by At

I have a base class from which all my DBEntities inherit certain properties:

public abstract class DBEntity{
    public virtual string Key { get; set; } = Guid.NewGuid().ToString();
    public string CreatedBy { get; set; } = string.Empty;
    public bool IsDeleted { get; set; }
    // A lot more properties...
}

Additionally, I have multiple specific entities, such as:

public class Car : DBEntity{
    public string Manufacturer { get; set; } = string.Empty;
    public int DoorCount{ get; set; }
    // A lot more properties...
}

Is there a method to generate objects without initializing the properties inherited from the parent class DBEntity? (They should just be the default values)

Currently, for each DBEntity property, I use the following approach:

_fixture.Customize<Car >(composer =>composer.Without(x => x.Key ));
0

There are 0 best solutions below