From the course: Practical Application Architecture with Entity Framework Core

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Testing business logic in queries

Testing business logic in queries - Entity Framework Tutorial

From the course: Practical Application Architecture with Entity Framework Core

Start my 1-month free trial

Testing business logic in queries

- [Instructor] We have a lot of good setup for testing in place, but there's one more piece I want to cover. Link queries can be really easy to use against the database with EF Core, but they can also end up containing a lot of business logic that ought to be tested. Let's add a DAL test, forget by partial customer last name, in the order repository. Let's look quickly at the method to see what it's doing. Open the DAL project and the order repository. Scroll down in the method. We can see that it's checking for orders that are not deleted, where the customer's last name contains the search term, and it's using ToLowerInvariant so that it's case-insensitive. With EF Core, we can test this logic. Let's open up the DAL.tests project, and we'll add a new file, OrderRepositoryTests. Right-click, Add, Class. First, we'll add a using statement for the Visual Studio test tools. using Microsoft.VisualStudio.TestTools.UnitTesting. Now, we'll make the class a test class by adding the TestClass…

Contents