public ActionResult Add(string title, string location) { string url = UrlGenerator.GenerateUrl(location); var viewModel = new PageViewModel {Title = title, Url = url}; return PartialView(viewModel); }
public ActionResult Save(PageViewModel viewModel) { if (ModelState.IsValid) { var page = Mapper.Map<Page>(viewModel); RavenSession.Store(page); return PartialView("Success"); } return PartialView("Failure"); }
public void Save_IsNotValid_DoesNotStore() { //Arrange var controller = new PageController { RavenSession = _documentStore.OpenSession() }; var viewModel = new PageViewModel { Id = 1, Body = "My page", Url = "about-us/team/managment" }; controller.ModelState.AddModelError("Body", "Body is too long"); //Act var result = controller.Save(viewModel); controller.RavenSession.SaveChanges(); //Assert using (var session = _documentStore.OpenSession()) { var content = session.Load<Page>(1); Assert.IsNull(content); } }
public void Save_IsNotValid_ReturnsFailureView() { //Arrange var controller = new PageController { RavenSession = _documentStore.OpenSession() }; var viewModel = new PageViewModel { Id = 1, Body = "My page", Url = "about-us/team/managment" }; controller.ModelState.AddModelError("Body", "Body is too long"); //Act var result = (PartialViewResult)controller.Save(viewModel); //Assert result.ViewName.ShouldBe("Failure"); }
public void Save_IsValid_StoresInDatabase() { //Arrange var controller = new PageController { RavenSession = _documentStore.OpenSession() }; var viewModel = new PageViewModel { Id = 1, Body = "My page", Url = "about-us/team/managment" }; //Act controller.Save(viewModel); controller.RavenSession.SaveChanges(); //Assert using (var session = _documentStore.OpenSession()) { var page = session.Load<Page>(1); Assert.AreEqual("My page", page.Body); Assert.AreEqual("about-us/team/managment", page.Path); } }
public void Save_IsValid_ReturnsSuccessView() { //Arrange var controller = new PageController { RavenSession = _documentStore.OpenSession() }; var viewModel = new PageViewModel { Id = 1, Body = "My page", Url = "about-us/team/managment" }; //Act var result = (PartialViewResult)controller.Save(viewModel); //Assert result.ViewName.ShouldBe("Success"); }