示例#1
0
        public async Task GetVideoGame_BasedOnId_WithNotExistingVideogame_ReturnNotFound()
        {
            //Arrange
            //use the mock to set up the test. we are basically telling here that whatever int id we pass to this method
            //it will always return null
            videogameController = new VideogameController(videoGameStub.Object);
            videoGameStub.Setup(service => service.GetVideogame(It.IsAny <int>())).ReturnsAsync(new NotFoundResult());
            //Act
            var actionResult = await videogameController.GetVideogame(1);

            //Assert
            Assert.IsType <NotFoundResult>(actionResult.Result);
        }
示例#2
0
        public async Task GetVideoGame_BasedOnId_WithExistingVideogame_ReturnVideogame()
        {
            //Arrange
            //use the mock to set up the test. we are basically telling here that whatever int id we pass to this method
            //it will always return a new Videogame object
            videoGameStub.Setup(service => service.GetVideogame(It.IsAny <int>())).ReturnsAsync(sampleVideogame);
            videogameController = new VideogameController(videoGameStub.Object);
            //Act
            var actionResult = await videogameController.GetVideogame(1);

            //Assert
            Assert.IsType <Videogame>(actionResult.Value);
            var result = actionResult.Value;

            sampleVideogame.Should().BeEquivalentTo(result,
                                                    options => options.ComparingByMembers <Videogame>());
        }