- First, let's create a class library project in the solution:
- Next, we will change the generated code in the project to import xunit, dotnet-test-xunit, and moq. We will also have to add the reference on the Web API project.
- Here are some of the test methods:
public class ProductApiControllerTests{ #region Tests for GET : api/productapi [Fact] public void GET _Returns404NotFoundResultIfProductListHaveNoItemsInRepo() { // Arrange var mockRepo = new Mock<IProductRepository>(); var emptyProductList = GetEmptyProductsList(); mockRepo.Setup(repo => repo.GetAllProducts()) .Returns(emptyProductList); var controller = new ProductApiController(mockRepo.Object); ...