Exemple #1
0
        public void ShouldReturnDefaultViewModelWithNoErrorWhenModelIsValid()
        {
            // Arrange
            var success     = new Result(ResultType.Success);
            var genreSvMock = new Mock <IGenreService>();

            genreSvMock.Setup(x => x.AddGenre(It.IsAny <Genres>())).Returns(success);
            var fakeGenre       = new GenreCreateViewModel();
            var sut             = new GenresController(genreSvMock.Object);
            var fakeHttpContext = new Mock <HttpContextBase>();

            sut.ControllerContext = new ControllerContext
            {
                Controller  = sut,
                HttpContext = fakeHttpContext.Object
            };
            var mapper = new AutoMapperConfig();

            mapper.Execute(Assembly.GetExecutingAssembly());
            Mapper.Initialize(cfg =>
                              cfg.CreateMap <GenreCreateViewModel, Genres>());

            // Act & Assert
            sut
            .WithCallTo(c => c.Create(fakeGenre))
            .ShouldRenderDefaultView()
            .WithModel <GenreCreateViewModel>(x => Assert.AreEqual(x.Result.ResulType, ResultType.Success));
        }
Exemple #2
0
        public void ShouldRedirect()
        {
            var moqGenresService = new Mock <IGenreService>();
            var sut = new GenresController(moqGenresService.Object);

            sut
            .WithCallTo(c => c.Index())
            .ShouldRedirectTo(x => x.Create);
        }
Exemple #3
0
        public void ReturnsDefaultView()
        {
            // Arrange
            var genreSvMock = new Mock <IGenreService>();
            var sut         = new GenresController(genreSvMock.Object);

            // Act & Assert
            sut
            .WithCallTo(c => c.Create())
            .ShouldRenderDefaultView();
        }
Exemple #4
0
        public void ReturnBackWithErrorOnInvalidModel()
        {
            // Arrange
            var genreSvMock     = new Mock <IGenreService>();
            var fakeGenre       = new GenreCreateViewModel();
            var sut             = new GenresController(genreSvMock.Object);
            var fakeHttpContext = new Mock <HttpContextBase>();

            sut.ControllerContext = new ControllerContext
            {
                Controller  = sut,
                HttpContext = fakeHttpContext.Object
            };

            sut.ModelState.AddModelError("Name", "Ivalid genre name");

            // Act & Assert
            sut
            .WithCallTo(c => c.Create(fakeGenre))
            .ShouldRenderDefaultView()
            .WithModel <GenreCreateViewModel>()
            .AndModelErrorFor(m => m.Name);
        }
        public void ShouldReturnAllMoviesNotExpiredNames()
        {
            // Arrange
            ICollection <Genres> fakeGenres = new List <Genres>();

            fakeGenres.Add(new Genres()
            {
                Name = "fakeName"
            });
            fakeGenres.Add(new Genres()
            {
                Name = "shouldShowName"
            });
            var success     = new Result(ResultType.Success);
            var genreSvMock = new Mock <IGenreService>();

            genreSvMock.Setup(x => x.GetAllNotExpired()).Returns(fakeGenres);
            var sut = new GenresController(genreSvMock.Object);

            // Act & Assert
            sut
            .WithCallTo(c => c.GetAllNamesNotExpired())
            .ShouldReturnJson();
        }