예제 #1
0
        public void CallGenreServiceUpdateGenre_WhenPassedGridGenreViewModel()
        {
            // Arrange
            var genreServiceMock = new Mock <IGenreService>();
            var mapperMock       = new Mock <IMapper>();

            var gridGenreViewModel = new GridGenreViewModel()
            {
                Name = "Genre"
            };

            var genreDbModel = new Genre()
            {
                Name = gridGenreViewModel.Name
            };

            var genresList = new List <Genre>()
            {
                genreDbModel
            };

            genreServiceMock.Setup(gs => gs.GetAllGenres()).Returns(genresList);

            mapperMock.Setup(x => x.Map <Genre>(gridGenreViewModel)).Returns(genreDbModel);

            // Act
            var genresGridController = new GenresGridController(genreServiceMock.Object, mapperMock.Object);

            genresGridController.EditGenre(gridGenreViewModel);

            // Assert
            genreServiceMock.Verify(gs => gs.UpdateGenre(genreDbModel), Times.Once);
        }
예제 #2
0
        public void NotCallGenreServiceUpdateGenre_WhenPassedNullGridGenreViewModel()
        {
            // Arrange
            var genreServiceMock = new Mock <IGenreService>();
            var mapperMock       = new Mock <IMapper>();

            // Act
            var genresGridController = new GenresGridController(genreServiceMock.Object, mapperMock.Object);

            genresGridController.EditGenre(null);

            // Assert
            genreServiceMock.Verify(gs => gs.UpdateGenre(It.IsAny <Genre>()), Times.Never);
        }