I am creating tests against an Entity Framework 6 repository. Due to a dependency between a product type and loan, I get a circular reference error when using Autofixture.AutoMoq. Is there an attribute that I can place over a test method so I can eliminate the following line of code (and its related items in the example, below): "fixture.Inject(Enumerable.Empty<Loan>());"
I am using XUnit 2.1.0.3179, Autofixture 3.50.2.0, Autofixutre.AutoMoq 3.50.2.0, AutoFixture.Xnit2, Moq 4.5.29.0
Here are some additional details, which may be helpful...
Loan(N) --- (1) ProductType
Due to the circular reference in my EF6 model, I cannot do the following:
[Theory, AutoMoqData]
public void ProductTypes_GetList()
List<ProductType> productTypeList,
[Frozen] Mock<IProductTypeRepository> productTypeRepo)
{
Instead, I have to do the following in order to avoid the circular reference issue:
var fixture = new Fixture().Customize(new AutoMoqCustomization());
// Avoid circular dependency in EF.
// Eliminating the many side of the relationship.
fixture.Inject(Enumerable.Empty<Loan>());
var productTypeRepo = fixture.Freeze<Mock<IProductTypeRepository>>();
// Create a list of product types.
List<ProductType> productTypeList = fixture.Create<List<ProductType>>();
productTypeRepo.Setup(_ => _.GetAll()).Returns(productTypeList);
I would appreciate learning whether it is possible to achieve my goal and reduce the lines of code.
Thank you in advance for time and suggestions.
Mike