public async Task Test_GetAll_Movies_Should_Be_Ok() { IEnumerable <Movie> fakeMovies = new Movie[] { new Movie() }; movieServiceMock.Setup(m => m.GetAll()).Returns(Task.FromResult(fakeMovies)); var apiResult = await movieController.GetAll(); apiResult.Should().BeOfType <OkObjectResult>().Which.Value.Should().Be(fakeMovies); movieServiceMock.Verify(m => m.GetAll(), Times.Once); movieServiceMock.VerifyNoOtherCalls(); }
public void Test_Controller_GetAll_WithParameter() { // Arrange int pageSize = 3; mockRepo.Setup(x => x.GetN(It.IsAny <int>())) .Returns(seed.Take(pageSize).ToList()); var controller = new MovieController(mockRepo.Object); //Act var response = controller.GetAll(pageSize); //Assert mockRepo.Verify(x => x.GetN(pageSize), Times.Once); var result = (Assert.IsType <ObjectResult>(response.Result)) as ObjectResult; var items = Assert.IsType <List <Movie> >(result.Value); Assert.Equal(pageSize, items.Count); }