public void Page_With_Default_Action(string virtualUrl) { // Arrange var pathData = new PathData(); var mapper = new Mock<IControllerMapper>(); var container = new Mock<IContainer>(); mapper.Setup(x => x.GetControllerName(typeof(DummyController))).Returns("Dummy"); container.Setup(x => x.GetInstance<IDocumentSession>()).Returns(_store.OpenSession()); // Act IPathData data; using (var session = _store.OpenSession()) { var content = new StandardPage(); session.Store(content); // create and store a new page model var pageModel = new PageModel { Metadata = { Url = "page" }, ContentReference = content.Id }; session.Store(pageModel); session.SaveChanges(); var resolver = new PathResolver(session, pathData, mapper.Object, container.Object); data = resolver.ResolvePath(new RouteData(), virtualUrl); } // Assert Assert.NotNull(data); Assert.AreEqual("index", data.Action); Assert.AreEqual("Dummy", data.Controller); }
public void Can_Query_Page_Using_AllPages_Index() { // Arrange IPageModel data; // Act using (var session = _store.OpenSession()) { var pageModel = new PageModel { Id = "DummyPages/1", Parent = null, Metadata = { Name = "Foo" } }; session.Store(pageModel); session.SaveChanges(); } using (var session = _store.OpenSession()) { data = session.Query<IPageModel>() .Customize(x => x.WaitForNonStaleResults()) .SingleOrDefault(x => x.Metadata.Name == "Foo"); } // Assert Assert.NotNull(data); }
public virtual ActionResult Save(FormCollection collection) { if (ModelState.IsValid) { var parent = _currentPage as PageModel; // create a new page from the new model var content = Activator.CreateInstance(Type.GetType(Request.Form["AssemblyQualifiedName"])) as dynamic; var page = new PageModel(); if (!TryUpdateModel(page, "NewPageModel", collection)) { var viewModel = new NewPageViewModel { RootModel = _session.Query<IPageModel>().SingleOrDefault(model => model.Parent == null), ParentModel = parent, ContentModel = content, NewPageModel = page, SlugsInUse = parent != null ? Newtonsoft.Json.JsonConvert.SerializeObject(_session.Load<IPageModel>(parent.Children).Select(x => x.Metadata.Slug)) : null }; return View("new", viewModel); } // Update all values UpdateModel(page, "NewPageModel"); // Store the new page _session.Store(page); if (!TryUpdateModel(content, "ContentModel", collection)) { var viewModel = new NewPageViewModel { RootModel = _session.Query<IPageModel>().SingleOrDefault(model => model.Parent == null), ParentModel = parent, ContentModel = content, NewPageModel = page, SlugsInUse = parent != null ? Newtonsoft.Json.JsonConvert.SerializeObject(_session.Load<IPageModel>(parent.Children).Select(x => x.Metadata.Slug)) : null }; return View("new", viewModel); } UpdateModel(content, "ContentModel"); _session.Store(content); page.ContentReference = content.Id; // Set the parent if it's not the start page if (parent != null) { page.Parent = _currentPage; parent.Children.Add(page.Id); var children = _session.Load<IPageModel>(parent.Children); var max = children.Max(x => x.Metadata.SortOrder); page.Metadata.SortOrder = max + 1; } // Set changed date page.Metadata.Changed = DateTime.Now; page.Metadata.ChangedBy = HttpContext.User.Identity.Name; // Add page to repository and save changes _session.SaveChanges(); return RedirectToAction("index", new { model = parent ?? page }); } return null; }
//[Test] public void Can_Query_Page_By_Type() { // Arrange List<StandardPage> data; // Act using (var session = _store.OpenSession()) { var pageModel = new PageModel { Id = "DummyPages/1", Parent = null, Metadata = { Name = "Foo" } }; session.Store(pageModel); session.SaveChanges(); } using (var session = _store.OpenSession()) { data = session.Query<StandardPage>().ToList(); } // Assert Assert.NotNull(data); Assert.AreEqual(1, data.Count); }
/// <summary> /// News the specified new page model. /// </summary> /// <param name="newModel">The new model.</param> /// <param name="collection">The collection.</param> /// <returns></returns> public ActionResult New(NewModel newModel) { if (ModelState.IsValid) { var parent = _currentPage as IPageModel; // create a new page from the selected page model var content = Activator.CreateInstance(Type.GetType(newModel.SelectedPageModel)) as dynamic; var page = new PageModel(); page.Metadata.Url = parent != null ? VirtualPathUtility.AppendTrailingSlash(parent.Metadata.Url) : String.Empty; page.Metadata.Published = DateTime.Now; var viewModel = new NewPageViewModel { RootModel = _session.Query<IPageModel>().SingleOrDefault(model => model.Parent == null), ParentModel = parent, NewPageModel = page, ContentModel = content, SlugsInUse = parent != null ? Newtonsoft.Json.JsonConvert.SerializeObject(_session.Load<IPageModel>(parent.Children).Select(x => x.Metadata.Slug)) : null }; ViewBag.Class = "edit"; return View("new", viewModel); } return PartialView("add", newModel); }