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 - Entity Framework Tutorial
From the course: Practical Application Architecture with Entity Framework Core
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.