This is my first time when i do unittesting with EF.Core and i met performance problems with autofilling EF models. They key problem for me are ICollection<> classes, where each class itself may have own collections and so on.
So the initialization takes a lot of time and i try to descrease this time somehow.
Example of model:
[DataContract]
public record DocumentEntity : IBaseDomainEntity
{
[DataMember(Order = 1)]
public int DocumentId { get; set; }
[DataMember(Order = 2)]
public int DocumentTypeId { get; set; }
[DataMember(Order = 3)]
public string Title { get; set; } = string.Empty;
[DataMember(Order = 4)]
public string Content { get; set; } = string.Empty;
[DataMember(Order = 5)]
public ICollection<DepartmentEntity> Departments { get; set; } = new List<DepartmentEntity>();
}
Example of initialization:
var expectedResult = new List<DocumentEntity>()
{
AutoFaker.Generate<DocumentEntity>()
};
Most of the time in tests i don’t need Departments collection in tests, but each time when i run AutoFaker, it fills it, slowly.
So if anyone can suggest some way to globally exclude for example ICollection<> (always make it null) or exclude by property names, or by level nesting.
Thank you