public void Details() { // Arrange CommentController controller = new CommentController(); TestControllerBuilder builder = new TestControllerBuilder(); builder.InitializeController(controller); var id = RepositoryFactory.Command<ICommentData>().GetAllForAdmin() .OrderBy(item => item.Name) .ToPage(1, 1).First().Id; // Act ActionResult result = controller.Details(id); // Assert var model = result.AssertViewRendered().WithViewData<CommentCRUDModel>(); Assert.AreEqual(id, model.Id); }
public void Delete_post_success() { // Arrange CommentController controller = new CommentController(); TestControllerBuilder builder = new TestControllerBuilder(); builder.InitializeController(controller); var data = RepositoryFactory.Command<ICommentData>().GetAllForAdmin() .OrderBy(item => item.Name); var count = data.Count(); var dataModel = RepositoryFactory.Command<ICommentCrud>().FindByPk(data.ToPage(1, 1).First().Id); // Act ActionResult result = controller.Delete(dataModel); // Assert result.AssertActionRedirect().ToAction("Index"); Assert.AreEqual(count - 1, data.Count()); }
public void Index() { // Arrange CommentController controller = new CommentController(); TestControllerBuilder builder = new TestControllerBuilder(); builder.InitializeController(controller); // Act ActionResult result = controller.Index(new PagedModel<CommentForAdminViewModel>()); // Assert var model = result.AssertViewRendered() .WithViewData<PagedModel<CommentForAdminViewModel>>(); Assert.AreEqual(NumberOfGeneratedItems, model.Count); int i = 0; foreach (var comment in model) { Assert.AreEqual("Comment" + i, comment.Name); Assert.AreEqual("Static page" + i, comment.Text); ++i; } Assert.AreEqual(PagedModel<StaticTextViewModel>.DefaultPageItems, i); }
public void Edit_post_success() { // Arrange CommentController controller = new CommentController(); TestControllerBuilder builder = new TestControllerBuilder(); builder.InitializeController(controller); var id = RepositoryFactory.Command<ICommentData>().GetAllForAdmin() .OrderBy(item => item.Name) .ToPage(1, 1).First().Id; var dataModel = RepositoryFactory.Command<ICommentCrud>().FindByPk(id); dataModel.Name = "changed comment"; dataModel.Text = "changed text"; // Act ActionResult result = controller.Edit(dataModel); // Assert result.AssertActionRedirect().ToAction("Index"); var changedItem = RepositoryFactory.Command<ICommentCrud>().FindByPk(id); Assert.IsNotNull(changedItem); Assert.AreEqual(dataModel.Id, changedItem.Id); Assert.AreEqual("changed comment", changedItem.Name); Assert.AreEqual("changed text", changedItem.Text); }