Example #1
0
        public void UpdateFilmTest()
        {
            Mock <IUnitOfWork> uow = new Mock <IUnitOfWork>();
            FilmService        fs  = new FilmService(uow.Object);
            FilmApiController  FC  = new FilmApiController(fs);

            uow.Setup(x => x.PersonRoleRepository.DeletePersonRolesByFilm(1));
            uow.Setup(x => x.FilmGenreRepository.DeleteFilmGenresByFilmId(1));
            uow.Setup(x => x.FilmAwardRepository.DeleteFilmAwardsByFilmId(1));
            uow.Setup(x => x.FilmRepository.Update(FilmModel.To(fm)));
            uow.Setup(x => x.Save());
            uow.Setup(x => x.GenreRepository.GenresByIds(It.IsAny <List <long> >())).Returns(fakeGenres);
            uow.Setup(x => x.PersonRepository.PersonsByIds(It.IsAny <List <long> >())).Returns(fakePeople);
            uow.Setup(x => x.PersonRepository.GetByKey(It.IsAny <long>())).Returns(fakePeople[0]);
            uow.Setup(x => x.AwardRepository.AwardsByIds(It.IsAny <List <long> >())).Returns(fakeAwards);
            uow.Setup(x => x.FilmRoleRepository.GetByRoleName(It.IsAny <string>())).Returns(fakeFilmRoles[0]);
            uow.Setup(x => x.FileRepository.GetByKey(1)).Returns(new File()
            {
                Id = 1
            });
            var result = (FC.UpdateFilm(fm) as ObjectResult).Value as FilmModel;

            result.Should().NotBeNull();
            //var expected = fm;
            //Assert.Equal(expected, result);
        }
        public IActionResult UpdateFilm([FromBody] FilmModel filmModel)
        {
            var film = _filmService.UpdateFilm(
                FilmModel.To(filmModel),
                filmModel.Director,
                filmModel.Playwriter,
                filmModel.Actors,
                filmModel.Genres,
                filmModel.Awards
                );

            return(new ObjectResult(_filmService.GetFilmView(film)));
        }
        public void ShowFilmViews()
        {
            Mock <IUnitOfWork> uow = new Mock <IUnitOfWork>();
            int    param           = 1;
            string name            = "Name";

            uow.Setup(x => x.FilmRepository.GetFilms(It.IsAny <SortQuery>(), It.IsAny <FilmFilterQuery>())).Returns(fakeFilms);
            uow.Setup(x => x.PersonRoleRepository.DirectorByFilmId(param)).Returns(new Person()
            {
                Name = "Dir"
            });
            uow.Setup(x => x.FilmAwardRepository.GetAll()).Returns(new List <FilmAward>());
            FilmService fs = new FilmService(uow.Object);

            FilmController FC     = new FilmController(fs);
            var            result = (FC.ShowFilmViews(FilmConstants.SortAsc, FilmConstants.SortTitle, name, new List <long>(), "")
                                     as ViewResult).Model as SortedSearchResponse <FilmModel, FilmFilterQuery>;
            var real     = result.Data.Select(x => FilmModel.To(x)).ToList();
            var expected = fakeFilms.Where(x => x.Title.Contains(name)).ToList();

            Assert.Equal(expected[0].Title, real[0].Title);
        }