public void GetGenreById_Returns_OkObjectResult() { // Arrange var genreRepositoryMock = new Mock <IGenreRepository>(); var genreIMapperMock = new MapperConfiguration(config => { config.AddProfile(new MovieMapper()); }); var genreMapper = genreIMapperMock.CreateMapper(); var logMock = new Mock <ILogger <GenresController> >(); ILogger <GenresController> logger = logMock.Object; GenresController genreApiController = new GenresController(genreRepositoryMock.Object, mapper: genreMapper, logger); var genreModel = new GenreModel() { Name = "Adult Content", DateCreated = DateTime.Parse("15 May 2015"), Id = Guid.NewGuid() }; genreRepositoryMock.Setup(repo => repo.GetGenre(It.IsAny <Guid>())) .Returns(genreModel); // Act var genreResult = genreApiController.GetGenreById(It.IsAny <Guid>()); var okResult = genreResult as OkObjectResult; // Assert Assert.True(okResult.StatusCode is StatusCodes.Status200OK); }
public async Task GetGenreById_ReturnsObjectResult() { // Arrange Genre genre = new Genre() { Id = 1, Name = "Horror alt." }; _mockRepo.Setup(repo => repo.Get <Genre>(1)).ReturnsAsync(genre); // Act var response = await _genresController.GetGenreById(1); // Assert Assert.IsAssignableFrom <ObjectResult>(response.Result); }