Exemple #1
0
        public async Task CallCorrectServiceMethodWithCorrectParams()
        {
            //Arrange
            const string movieName     = "Venom";
            const string movieDirector = "director";
            var          genreList     = new List <string> {
                null
            };
            var newMovie = new Movie();

            var model = new MovieViewModel()
            {
                Name = movieName, Genres = genreList, Director = movieDirector
            };
            var movieServiceMock = new Mock <IMovieServices>();

            movieServiceMock
            .Setup(ms => ms.CreateMovieAsync(movieName, genreList, movieDirector))
            .ReturnsAsync(newMovie);

            var cache           = new MemoryCache(new MemoryCacheOptions());
            var userManagerMock = new Mock <IUserManager <User> >();

            var sut = new MovieController(movieServiceMock.Object, cache, userManagerMock.Object);
            //Act
            var result = await sut.Create(model) as ViewResult;

            //Assert
            movieServiceMock.Verify(s => s.CreateMovieAsync(movieName, genreList, movieDirector));
        }
        public async Task Create_ReturnsACreatedAtActionResultAndAddsMovie_WhenModelStateIsValid()
        {
            var mapper = CreateAutomapper();

            var movieServiceMock = new Mock <IMovieService>();

            movieServiceMock.Setup(s => s.CreateAsync(It.IsAny <Movie>()))
            .Returns(Task.FromResult(new Movie()
            {
                Id = 1
            }))
            .Verifiable();

            var controller = new MovieController(mapper, movieServiceMock.Object);
            var movie      = new MovieFormViewModel
            {
                Title    = "New movie",
                Synopsis = "It's about people",
                Tags     = new List <string>()
                {
                    "Tag 1", "Tag 2"
                }
            };

            var result = await controller.Create(movie);

            var createdAtActionResult = Assert.IsType <CreatedAtActionResult>(result);

            Assert.Null(createdAtActionResult.ControllerName);
            Assert.Equal("GetById", createdAtActionResult.ActionName);
            Assert.IsType <MovieDetailViewModel>(createdAtActionResult.Value);
            movieServiceMock.Verify();
        }
Exemple #3
0
        public void CreateTest()
        {
            Mock <IRepository>      repoMock        = new Mock <IRepository>();
            Mock <IPriceCalculator> calculatorMock  = new Mock <IPriceCalculator>();
            MovieController         movieController = new MovieController(repoMock.Object, calculatorMock.Object);
            ICollection <Showing>   showings        = new HashSet <Showing>();

            showings.Add(new Showing {
                Id = 1, MovieId = 1, RoomId = 1
            });
            Movie movie = new Movie {
                Id               = 1,
                Name             = "TestFilm",
                Director         = "Tester",
                Genre            = "Test",
                ImageUrl         = "image.url.com",
                Imdb             = "imdb.url.com",
                Is3D             = true,
                SpokenLanguage   = "Nederlands",
                SubtitleLanguage = "Nederlands, slechthorend",
                LengthInMinutes  = 123,
                YearOfRelease    = 2018,
                Trailer          = "trailer.url.com",
                MinimumAge       = 12,
                ShortDescription = "Test film description",
                LastShowDate     = DateTime.Now.AddYears(1),
                Showings         = showings
            };

            ViewResult result = (ViewResult)movieController.Create(movie);

            MovieDetails savedDetails = (MovieDetails)result.Model;

            Movie savedMovie = savedDetails.Movie;

            Assert.IsNotNull(savedMovie);
            Assert.AreEqual(movie.Name, savedMovie.Name);
            Assert.AreEqual(movie.Director, savedMovie.Director);
            Assert.AreEqual(movie.Genre, savedMovie.Genre);
            Assert.AreEqual(movie.ImageUrl, savedMovie.ImageUrl);
            Assert.AreEqual(movie.Imdb, savedMovie.Imdb);
            Assert.AreEqual(movie.Is3D, savedMovie.Is3D);
            Assert.AreEqual(movie.SpokenLanguage, savedMovie.SpokenLanguage);
            Assert.AreEqual(movie.SubtitleLanguage, savedMovie.SubtitleLanguage);
            Assert.AreEqual(movie.LengthInMinutes, savedMovie.LengthInMinutes);
            Assert.AreEqual(movie.YearOfRelease, savedMovie.YearOfRelease);
            Assert.AreEqual(movie.Trailer, savedMovie.Trailer);
            Assert.AreEqual(movie.MinimumAge, savedMovie.MinimumAge);
            Assert.AreEqual(movie.ShortDescription, savedMovie.ShortDescription);
            Assert.AreEqual(movie.LastShowDate, savedMovie.LastShowDate);

            List <Showing> savedShowings = savedMovie.Showings.ToList();

            Assert.IsNotNull(savedShowings);
            Assert.AreEqual(1, savedShowings.Count());
            Assert.AreEqual(1, savedShowings.First <Showing>().MovieId);
            Assert.AreEqual(1, savedShowings.First <Showing>().RoomId);
        }
Exemple #4
0
        public void Can_Create_Movie()
        {
            var movieRepo = new MovieRepository(null);
            var underTest = new MovieController(movieRepo);

            var result = underTest.Create();

            Assert.IsType <ViewResult>(result);
        }
Exemple #5
0
        public void Create()
        {
            // Arrange
            MovieController controller = new MovieController();

            // Act
            ViewResult result = controller.Create() as ViewResult;

            // Assert
            Assert.AreEqual("Your application description page.", result.ViewBag.Message);
        }
        public void Create()
        {
            // Arrange
            MovieController controller = new MovieController();

            // Act
            ViewResult result = controller.Create() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }
Exemple #7
0
        public async Task ReturnsCorrectViewResult()
        {
            //Arrange
            var movieServiceMock = new Mock <IMovieServices>();

            movieServiceMock
            .Setup(msm => msm.GetGenresAsync())
            .ReturnsAsync(new List <Genre>());
            var cache           = new MemoryCache(new MemoryCacheOptions());
            var userManagerMock = new Mock <IUserManager <User> >();
            var sut             = new MovieController(movieServiceMock.Object, cache, userManagerMock.Object);
            //Act
            var result = await sut.Create() as ViewResult;

            //Assert
            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }
Exemple #8
0
        public async Task CallCorrectServiceMethodWithCorrectParams()
        {
            //Arrange
            var movieServiceMock = new Mock <IMovieServices>();

            movieServiceMock
            .Setup(msm => msm.GetGenresAsync())
            .ReturnsAsync(new List <Genre>());

            var cache           = new MemoryCache(new MemoryCacheOptions());
            var userManagerMock = new Mock <IUserManager <User> >();

            var sut = new MovieController(movieServiceMock.Object, cache, userManagerMock.Object);
            //Act
            await sut.Create();

            //Assert
            movieServiceMock.Verify(msm => msm.GetGenresAsync(), Times.Once);
        }
Exemple #9
0
        public async Task ReturnsCorrectViewResult()
        {
            //Arrange
            var model            = new MovieViewModel();
            var movieServiceMock = new Mock <IMovieServices>();

            movieServiceMock
            .Setup(ms => ms.CreateMovieAsync(null, null, null))
            .ReturnsAsync(new Movie());

            var cache           = new MemoryCache(new MemoryCacheOptions());
            var userManagerMock = new Mock <IUserManager <User> >();

            var sut = new MovieController(movieServiceMock.Object, cache, userManagerMock.Object);
            //Act
            var result = await sut.Create(model);

            //Assert
            Assert.IsInstanceOfType(result, typeof(RedirectToActionResult));
        }
        public async Task Index_ShouldDisplayTheModel_GivenAValidId()
        {
            //Arrange
            int   testId    = 1;
            Movie testMovie = new Movie {
                ID = 1, Title = "title", Genre = "genre", Rating = 1
            };

            _repo.Setup(r => r.GetMovieByIdAsync(testId)).ReturnsAsync(testMovie).Verifiable();
            //Act
            await _controller.Create(testMovie);

            _repo.Verify(r => r.AddMovieAsync(testMovie), "Never called add movie");

            var result = await _controller.Index(testId) as ViewResult;

            _repo.Verify(r => r.GetMovieByIdAsync(testId), Times.Once, "Never called get movie by id");
            _repo.Verify();
            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(testMovie, result.Model);
        }