shriiihariii
shriiihariii

Reputation: 1

.NET 6.0 and EF Core: How do I unit test EF Core LINQ Queries with a LEFT JOIN?

I have a LINQ query which performs a LEFT JOIN on two tables:


var leftJoinData = (from costDetails in dbContext.CostDetails
                    join orderInformation in dbContext.OrderInformation on costDetails.FK_INVTABLEUID equals orderInformation.FK_INVTABLEUID
                       into completeInformationList
                       from ci in completeInformationList.DefaultIfEmpty()
                       select new
                       {
                           ci.OrderId,
                           cost = costDetails.MaximumRetailPrice
                       }).AsNoTracking().ToList();

I want to test the method executing this query, but when I test after mocking the db set(using Moq), I get System.ArgumentNullException : Value cannot be null. (Parameter 'source'). But when I remove the LEFT JOIN and instead perform and INNER JOIN, that is, when I remove the completeInformationList.DefaultIfEmpty() call, I am able to test it.

Upvotes: 0

Views: 67

Answers (0)

Related Questions