Exemplo n.º 1
0
        public void CallMovieServiceDeleteMovie_WhenPassedGridMovieViewModel()
        {
            // Arrange
            var movieServiceMock  = new Mock <IMovieService>();
            var fileConverterMock = new Mock <IFileConverter>();
            var mapperMock        = new Mock <IMapper>();

            var gridMovieViewModel = new GridMovieViewModel()
            {
                Id          = 1,
                Name        = "Movie name",
                RunningTime = 120,
                Year        = "1980",
                Image       = null,
                GenreName   = "Genre name"
            };

            // Act
            var moviesGridController =
                new MoviesGridController(movieServiceMock.Object, fileConverterMock.Object, mapperMock.Object);

            moviesGridController.DeleteMovie(gridMovieViewModel);

            // Assert
            movieServiceMock.Verify(ms => ms.DeleteMovie(gridMovieViewModel.Id), Times.Once);
        }
Exemplo n.º 2
0
        public void CreateAnInstanceOfMoviesGridController_WhenPassedArgumentsAreNotNull()
        {
            // Arrange
            var movieServiceMock  = new Mock <IMovieService>();
            var fileConverterMock = new Mock <IFileConverter>();
            var mapperMock        = new Mock <IMapper>();

            // Act
            var moviesGridController =
                new MoviesGridController(movieServiceMock.Object, fileConverterMock.Object, mapperMock.Object);

            // Assert
            Assert.IsInstanceOf <MoviesGridController>(moviesGridController);
        }
Exemplo n.º 3
0
        public void ReturnJsonContainingMovies()
        {
            // Arrange
            var movieServiceMock  = new Mock <IMovieService>();
            var fileConverterMock = new Mock <IFileConverter>();
            var mapperMock        = new Mock <IMapper>();
            var dataSourceRequest = new DataSourceRequest();

            var movieDbModel = new Movie()
            {
                Name        = "Movie name",
                Description = "Movie description",
                RunningTime = 120,
                Year        = "1980",
                Image       = null,
                GenreId     = 1
            };

            var gridMovieViewModel = new GridMovieViewModel()
            {
                Name        = movieDbModel.Name,
                Image       = movieDbModel.Image,
                Year        = movieDbModel.Year,
                RunningTime = movieDbModel.RunningTime,
                GenreName   = "Genre name"
            };

            var moviesList = new List <Movie>()
            {
                movieDbModel
            };

            movieServiceMock.Setup(ms => ms.GetAllMovies()).Returns(moviesList);

            mapperMock.Setup(x => x.Map <GridMovieViewModel>(movieDbModel)).Returns(gridMovieViewModel);

            // Act
            var moviesGridController =
                new MoviesGridController(movieServiceMock.Object, fileConverterMock.Object, mapperMock.Object);
            var jsonResult = moviesGridController.ReadMovies(dataSourceRequest) as JsonResult;

            var dataSourceResult = jsonResult.Data as DataSourceResult;
            var dataEnumerator   = dataSourceResult.Data.GetEnumerator();

            dataEnumerator.MoveNext();

            // Assert
            Assert.AreSame(dataEnumerator.Current, gridMovieViewModel);
        }
Exemplo n.º 4
0
        public void NotCallMovieServiceDeleteMovie_WhenPassedNullGridMovieViewModel()
        {
            // Arrange
            var movieServiceMock  = new Mock <IMovieService>();
            var fileConverterMock = new Mock <IFileConverter>();
            var mapperMock        = new Mock <IMapper>();

            // Act
            var moviesGridController =
                new MoviesGridController(movieServiceMock.Object, fileConverterMock.Object, mapperMock.Object);

            moviesGridController.DeleteMovie(null);

            // Assert
            movieServiceMock.Verify(ms => ms.DeleteMovie(It.IsAny <int>()), Times.Never);
        }
Exemplo n.º 5
0
        public void ReturnDefaultView_WhenCalled()
        {
            // Arrange
            var movieServiceMock  = new Mock <IMovieService>();
            var fileConverterMock = new Mock <IFileConverter>();
            var mapperMock        = new Mock <IMapper>();

            // Act
            var moviesGridController =
                new MoviesGridController(movieServiceMock.Object, fileConverterMock.Object, mapperMock.Object);

            // Assert
            moviesGridController
            .WithCallTo(c => c.Index())
            .ShouldRenderDefaultView();
        }
Exemplo n.º 6
0
        public void CallMovieServiceUpdateMovie_WhenPassedGridMovieViewModel()
        {
            // Arrange
            var movieServiceMock  = new Mock <IMovieService>();
            var fileConverterMock = new Mock <IFileConverter>();
            var mapperMock        = new Mock <IMapper>();
            var image             = new byte[128];

            var gridMovieViewModel = new GridMovieViewModel()
            {
                Id          = 1,
                Name        = "Movie name",
                Image       = image,
                Year        = "1980",
                RunningTime = 120,
                GenreName   = "Genre name"
            };

            var movieDbModel = new Movie()
            {
                Name        = gridMovieViewModel.Name,
                Image       = gridMovieViewModel.Image,
                Year        = gridMovieViewModel.Year,
                RunningTime = gridMovieViewModel.RunningTime
            };

            var moviesList = new List <Movie>()
            {
                movieDbModel
            };

            movieServiceMock.Setup(ms => ms.GetAllMovies()).Returns(moviesList);

            mapperMock.Setup(x => x.Map <Movie>(gridMovieViewModel)).Returns(movieDbModel);
            mapperMock.Setup(x => x.Map <GridMovieViewModel>(movieDbModel)).Returns(gridMovieViewModel);

            // Act
            var moviesGridController =
                new MoviesGridController(movieServiceMock.Object, fileConverterMock.Object, mapperMock.Object);

            moviesGridController.EditMovie(gridMovieViewModel);

            // Assert
            movieServiceMock.Verify(ms => ms.UpdateMovie(movieDbModel), Times.Once);
        }
Exemplo n.º 7
0
        public void ReturnFileContentResult_WhenPictureWithThePassedIdExists()
        {
            // Arrange
            var movieServiceMock  = new Mock <IMovieService>();
            var fileConverterMock = new Mock <IFileConverter>();
            var mapperMock        = new Mock <IMapper>();
            var pictureId         = "1";

            var gridMovieViewModel = new GridMovieViewModel()
            {
                Id          = 1,
                Name        = "Movie name",
                Image       = null,
                Year        = "1980",
                RunningTime = 120,
                GenreName   = "Genre name"
            };

            var movieDbModel = new Movie()
            {
                Name        = gridMovieViewModel.Name,
                Image       = gridMovieViewModel.Image,
                Year        = gridMovieViewModel.Year,
                RunningTime = gridMovieViewModel.RunningTime
            };

            var moviesList = new List <Movie>()
            {
                movieDbModel
            };

            movieServiceMock.Setup(ms => ms.GetAllMovies()).Returns(moviesList);

            mapperMock.Setup(x => x.Map <Movie>(gridMovieViewModel)).Returns(movieDbModel);
            mapperMock.Setup(x => x.Map <GridMovieViewModel>(movieDbModel)).Returns(gridMovieViewModel);

            // Act
            var moviesGridController =
                new MoviesGridController(movieServiceMock.Object, fileConverterMock.Object, mapperMock.Object);
            var picture = moviesGridController.GetImage(pictureId);

            // Assert
            Assert.IsNotNull(picture);
        }