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)); }
public void ShouldRedirect() { var moqGenresService = new Mock <IGenreService>(); var sut = new GenresController(moqGenresService.Object); sut .WithCallTo(c => c.Index()) .ShouldRedirectTo(x => x.Create); }
public void ReturnsDefaultView() { // Arrange var genreSvMock = new Mock <IGenreService>(); var sut = new GenresController(genreSvMock.Object); // Act & Assert sut .WithCallTo(c => c.Create()) .ShouldRenderDefaultView(); }
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(); }