public void ShouldNotEditAuthorNameToAnExsitingOne() { var author1 = new Author() { Name = "Author1", Biography = "Biography1", PictureUrl = "myPicture1.jpg", CreatedAt = DateTime.UtcNow }; var author2 = new Author() { Name = "Author2", Biography = "Biography2", PictureUrl = "myPicture2.jpg", CreatedAt = DateTime.UtcNow }; UsingSession((session) => { var controller = new AuthorsController(new Repository(session)); controller.Create(author1); controller.Create(author2); }); UsingSession((session) => { WaitForTheLastWrite<Author>(session); var author = session.Query<Author>().First(a => a.Name == author2.Name); author.Name = author1.Name; var controller = new AuthorsController(new Repository(session)); var viewResult = (System.Web.Mvc.ViewResult)(controller.Edit(author)); Assert.AreEqual("An author with this name already exists", controller.TempData["flashError"]); Assert.AreEqual("", viewResult.MasterName); }); }
public void ShouldRetrieveTheAuthorToEdit() { var author1 = new Author() { Name = "Author1", Biography = "Biography1", PictureUrl = "myPicture1.jpg", CreatedAt = DateTime.UtcNow }; UsingSession((session) => { var controller = new AuthorsController(new Repository(session)); controller.Create(author1); }); UsingSession((session) => { var author = WaitForTheLastWrite<Author>(session); var controller = new AuthorsController(new Repository(session)); var viewResult = controller.Edit(author.Id); var authorInView = (Author)(viewResult.Model); AuthorsContollerTestHelper.AssertEqual(author1, authorInView); }); }
public void ShouldEditAuthor() { var author1 = new Author() { Name = "Author1", Biography = "Biography1", PictureUrl = "myPicture1.jpg", CreatedAt = DateTime.UtcNow }; UsingSession((session) => { var controller = new AuthorsController(new Repository(session)); controller.Create(author1); }); Author updatedAuthorInfo = null; UsingSession((session) => { var author = WaitForTheLastWrite<Author>(session); updatedAuthorInfo = new Author() { Id = author.Id, Name = "Author updated", Biography = "Biography updated", PictureUrl = "myPictureupdated.jpg", }; var controller = new AuthorsController(new Repository(session)); var actionResult = (RedirectToRouteResult)(controller.Edit(updatedAuthorInfo)); Assert.AreEqual("Authors", actionResult.RouteValues["controller"]); Assert.AreEqual("Details", actionResult.RouteValues["action"]); Assert.AreEqual(author.Id, actionResult.RouteValues["id"]); }); UsingSession((session) => { var updatedAuthor = WaitForTheLastWrite<Author>(session); AuthorsContollerTestHelper.AssertEqual(updatedAuthorInfo, updatedAuthor); }); }