コード例 #1
0
        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();
        }
コード例 #2
0
        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);
        }