示例#1
0
        public async Task <ActionResult> EditFilm(int id)
        {
            try
            {
                var model = await _filmService.GetFilmByIdAsync(id);

                return(View(model));
            }
            catch (Exception ex)
            {
                //TODO: Реализовать запись в лог.
                return(new HttpNotFoundResult(ex.Message));
            }
        }
        public async Task TestGetFilmByIdAsync_GetInvalidId_ThrowFilmNotExistException()
        {
            // Arrange
            int filmId = 3;

            filmRepository.Setup(f => f.GetFilmByIdAsync(filmId))
            .ReturnsAsync(filmsList.FirstOrDefault(f => f.FilmId == filmId));
            FilmService service = new FilmService(filmRepository.Object, ratingRepository.Object, mapper);

            // Act, Assert
            await Assert.ThrowsAsync <FilmNotExistException>(() => service.GetFilmByIdAsync(filmId));
        }
        public async Task TestGetFilmByIdAsync_GetValidId_ReturnFilmDetailsSuccessfully()
        {
            // Arrange
            int filmId = 2;

            filmRepository.Setup(f => f.GetFilmByIdAsync(filmId))
            .ReturnsAsync(filmsList.FirstOrDefault(f => f.FilmId == filmId));
            FilmService service = new FilmService(filmRepository.Object, ratingRepository.Object, mapper);

            // Act
            var result = await service.GetFilmByIdAsync(filmId);

            // Assert
            var film = result as FilmDetailsModel;

            Assert.NotNull(film);
            Assert.Equal(2016, film.Year);
        }