public void CurrentGenres_Should_Redirect_Back_When_Genre_Exists() { bookService.Setup(x => x.Genres()).Returns(new List <BookGenreOutputModel>() { new BookGenreOutputModel() { GenreName = "Horror" }, new BookGenreOutputModel() { GenreName = "Fantasy" } }); var genreName = "asd"; adminService.Setup(x => x.AddGenre(genreName)).Returns(GlobalConstants.Failed); var adminController = new BookCreatorApp.Areas.Administration.Controllers.AdminsController(adminService.Object, bookService.Object); var result = adminController.CurrentGenres(genreName); string expected = string.Join(GlobalConstants.AlreadyExistsInDb, genreName); result.As <ViewResult>().ViewData.ContainsKey(GlobalConstants.Error).Equals(expected); }
public async Task DeleteBook_Error_MissingRole() { var user = new Mock <ClaimsPrincipal>(); user.Setup(x => x.IsInRole(It.IsAny <string>())).Returns(false); var adminsController = new BookCreatorApp.Areas.Administration.Controllers.AdminsController(adminService.Object, bookService.Object) { ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext { User = user.Object } } }; var id = "1"; var result = await adminsController.DeleteBook(id); Assert.AreEqual(((RedirectToActionResult)result).ActionName, nameof(HomeController.Error)); }
public void CurrentGenres_Should_Return_Correct_View_With_Empty_String_On_Post() { bookService.Setup(x => x.Genres()).Returns(new List <BookGenreOutputModel>() { new BookGenreOutputModel() { GenreName = "Horror" }, new BookGenreOutputModel() { GenreName = "Fantasy" } }); var adminController = new BookCreatorApp.Areas.Administration.Controllers.AdminsController(adminService.Object, bookService.Object); var result = adminController.CurrentGenres(null); result.As <ViewResult>().ViewData .ContainsKey(GlobalConstants.Error) .Equals(GlobalConstants.NullName); }
public async Task DeleteBook_Success_RedirectTo_AllBooks() { var username = "******"; var user = new Mock <ClaimsPrincipal>(); user.Setup(x => x.IsInRole(It.IsAny <string>())).Returns(true); user.Setup(x => x.Identity.Name).Returns(username); var adminsController = new BookCreatorApp.Areas.Administration.Controllers.AdminsController(adminService.Object, bookService.Object) { ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext { User = user.Object } } }; string id = "1"; var result = await adminsController.DeleteBook(id); Assert.AreEqual(((RedirectToActionResult)result).ActionName, nameof(BookCreatorApp.Areas.Administration.Controllers.AdminsController.CurrentBooks)); }