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.

Mocking objects

Mocking objects - Entity Framework Tutorial

From the course: Practical Application Architecture with Entity Framework Core

Start my 1-month free trial

Mocking objects

- [Instructor] Now that we have some tests, let's make the business logic test of move salesperson to group better by mocking out some of the dependencies. First, we'll add some mocks of our own, and then we'll use the mocking framework, Moq, M-O-Q. In the HPlusSports.Core.Test project, we can add a folder for mocks. Right-click, add, folder, Mocks, and then we can right-click Mocks, add class, SalesPersonRepositoryMock, and add class, SalesGroupRepositoryMock. Let's start in SalesGroupRepositoryMock. We'll add the interface of the repository we're mocking. And Ctrl + Period to add models DAL, and to implement the interface. Now we'll do the same thing for the SalesPersonRepositoryMock. Ctrl + Shift + S to save both files. We'll come back to the implementations of the mock momentarily. For now, we'll change the test to use these mocks. Open up the tests file. We don't need the context anymore since we can test against mock repositories instead of the real ones. So let's remove that…

Contents