public void Saving_New_Entity_With_Predefined_Empty_Id_Should_Not_Change_Id() { RunActionInTransaction(session => { var layout = TestDataProvider.CreateNewLayout(); var region = TestDataProvider.CreateNewRegion(); layout.LayoutRegions = new List <LayoutRegion> { TestDataProvider.CreateNewLayoutRegion(layout, region), }; var page = TestDataProvider.CreateNewPageProperties(layout); var pageId = page.Id = Guid.NewGuid(); Assert.AreEqual(page.Id, pageId); session.SaveOrUpdate(page); session.Flush(); session.Clear(); Assert.AreEqual(page.Id, pageId); }); }
public void Should_Return_Page_With_PageContents_Successfully() { string virtualPath = "/test/" + Guid.NewGuid().ToString().Replace("-", string.Empty) + "/"; var layout = TestDataProvider.CreateNewLayout(); var regionA = TestDataProvider.CreateNewRegion(); var regionB = TestDataProvider.CreateNewRegion(); var htmlContent = TestDataProvider.CreateNewHtmlContent(); var serverWidgetContent = TestDataProvider.CreateNewServerControlWidget(); var htmlContentWidget = TestDataProvider.CreateNewHtmlContentWidget(); layout.LayoutRegions = new List <LayoutRegion> { TestDataProvider.CreateNewLayoutRegion(layout, regionA), TestDataProvider.CreateNewLayoutRegion(layout, regionB) }; var page = TestDataProvider.CreateNewPageProperties(layout); page.PageContents = new List <PageContent> { TestDataProvider.CreateNewPageContent(htmlContent, page, regionA), TestDataProvider.CreateNewPageContent(serverWidgetContent, page, regionB), TestDataProvider.CreateNewPageContent(htmlContentWidget, page, regionB) }; page.PageUrl = virtualPath; RunDatabaseActionAndAssertionsInTransaction( page, session => { session.Save(page); session.Flush(); }, (result, session) => { Page pageAlias = null; Layout layoutAlias = null; var entity = session.QueryOver(() => pageAlias) .Inner.JoinAlias(() => pageAlias.Layout, () => layoutAlias) .Where(f => f.PageUrl == virtualPath.ToLowerInvariant()) .Fetch(f => f.Layout).Eager .Fetch(f => f.Layout.LayoutRegions).Eager .Fetch(f => f.PageContents).Eager .Fetch(f => f.PageContents[0].Content).Eager .SingleOrDefault(); Assert.IsNotNull(entity); Assert.AreEqual(page.PageContents.Count(), entity.PageContents.Distinct().Count()); Assert.AreEqual(page.Layout.LayoutRegions.Count(), entity.Layout.LayoutRegions.Distinct().Count()); }); }
public void ShouldMapModelCorrectly() { var entity = TestDataProvider.CreateNewPageProperties(); entity.MasterPage = TestDataProvider.CreateNewPageProperties(); entity.PublishedOn = TestDataProvider.ProvideRandomDateTime(); entity.IsInSitemap = TestDataProvider.ProvideRandomBooleanValue(); var model = new UpdatingPagePropertiesModel(entity); Assert.AreEqual(entity.Title, model.Title); Assert.AreEqual(entity.PageUrl, model.PageUrl); Assert.AreEqual(entity.PageUrlHash, model.PageUrlHash); Assert.AreEqual(entity.Description, model.Description); Assert.AreEqual(entity.CustomCss, model.CustomCss); Assert.AreEqual(entity.CustomJS, model.CustomJS); Assert.AreEqual(entity.MetaTitle, model.MetaTitle); Assert.AreEqual(entity.MetaKeywords, model.MetaKeywords); Assert.AreEqual(entity.MetaDescription, model.MetaDescription); Assert.AreEqual(entity.Status, model.Status); Assert.AreEqual(entity.PublishedOn, model.PublishedOn); Assert.AreEqual(entity.HasSEO, model.HasSEO); Assert.AreEqual(entity.UseCanonicalUrl, model.UseCanonicalUrl); Assert.AreEqual(entity.UseNoFollow, model.UseNoFollow); Assert.AreEqual(entity.UseNoIndex, model.UseNoIndex); Assert.AreEqual(entity.IsMasterPage, model.IsMasterPage); Assert.AreEqual(entity.IsArchived, model.IsArchived); Assert.AreEqual(entity.IsInSitemap, model.IsInSitemap); Assert.AreEqual(entity.Layout.Id, model.LayoutId); Assert.AreEqual(entity.MasterPage.Id, model.MasterPageId); foreach (var category in entity.Categories) { Assert.Contains(category.Id, model.Categories.ToArray()); } Assert.AreEqual(entity.Image.Id, model.MainImageId); Assert.AreEqual(entity.SecondaryImage.Id, model.SecondaryImageId); Assert.AreEqual(entity.FeaturedImage.Id, model.FeaturedImageId); }
public void ShouldMapModelCorrectly_WithNullReferences() { var entity = TestDataProvider.CreateNewPageProperties(); entity.Layout = null; entity.MasterPage = null; entity.Category = null; entity.Image = null; entity.SecondaryImage = null; entity.FeaturedImage = null; var model = new UpdatingPagePropertiesModel(entity); Assert.IsNull(model.LayoutId); Assert.IsNull(model.MasterPageId); Assert.IsNull(model.CategoryId); Assert.IsNull(model.MainImageId); Assert.IsNull(model.SecondaryImageId); Assert.IsNull(model.FeaturedImageId); }
public void Should_Insert_And_Retrieve_PageProperties_PageTags_Successfully() { var page = TestDataProvider.CreateNewPageProperties(); var pageTags = new[] { TestDataProvider.CreateNewPageTag(page), TestDataProvider.CreateNewPageTag(page), TestDataProvider.CreateNewPageTag(page) }; page.PageTags = pageTags; SaveEntityAndRunAssertionsInTransaction( page, result => { Assert.AreEqual(page, result); Assert.AreEqual(pageTags.OrderBy(f => f.Id), result.PageTags.OrderBy(f => f.Id)); }); }
public void Saving_Entity_With_Duplicated_Id_Should_Fail2() { RunActionInTransaction( session => { var layout = TestDataProvider.CreateNewLayout(); var region = TestDataProvider.CreateNewRegion(); layout.LayoutRegions = new List <LayoutRegion> { TestDataProvider.CreateNewLayoutRegion(layout, region), }; var page = TestDataProvider.CreateNewPageProperties(layout); var pageId = page.Id; Assert.AreNotEqual(pageId, Guid.Empty); session.SaveOrUpdate(page); session.Flush(); session.Clear(); Assert.AreEqual(page.Id, pageId); var originalPage = session.Get <Page>(pageId); Assert.AreEqual(page, originalPage); var page2 = TestDataProvider.CreateNewPageProperties(layout); page2.Id = pageId; session.Clear(); Assert.Throws <NHibernate.Exceptions.GenericADOException>( () => { session.SaveOrUpdate(page2); session.Flush(); }); }); }
public void Changing_Saved_Entity_Id_Should_Fail() { RunActionInTransaction( session => { var layout = TestDataProvider.CreateNewLayout(); var region = TestDataProvider.CreateNewRegion(); layout.LayoutRegions = new List <LayoutRegion> { TestDataProvider.CreateNewLayoutRegion(layout, region), }; var page = TestDataProvider.CreateNewPageProperties(layout); var pageId = page.Id; Assert.AreNotEqual(pageId, Guid.Empty); session.SaveOrUpdate(page); session.Flush(); session.Clear(); Assert.AreEqual(page.Id, pageId); var originalPage = session.Get <Page>(pageId); Assert.AreEqual(page, originalPage); var newId = Guid.NewGuid(); originalPage.Id = newId; Assert.Throws <NHibernate.HibernateException>( () => { session.SaveOrUpdate(originalPage); session.Flush(); }); }); }
private void RunTest() { // Attach to events Events.PageEvents.Instance.PageContentInserted += Instance_EntityCreated; Events.PageEvents.Instance.PageContentSorted += Instance_EntityUpdated; Events.PageEvents.Instance.PageContentConfigured += Instance_PageContentConfigured; Events.PageEvents.Instance.PageContentDeleted += Instance_EntityDeleted; contentConfigredCount = 0; RunApiActionInTransaction( (api, session) => { page = TestDataProvider.CreateNewPageProperties(); session.SaveOrUpdate(page); Run(session, api.Pages.Page.Content.Post, api.Pages.Page.Content.Get, api.Pages.Page.Content.Put, api.Pages.Page.Content.Delete); }); // Detach from events Events.PageEvents.Instance.PageContentInserted -= Instance_EntityCreated; Events.PageEvents.Instance.PageContentSorted -= Instance_EntityUpdated; Events.PageEvents.Instance.PageContentConfigured -= Instance_PageContentConfigured; Events.PageEvents.Instance.PageContentDeleted -= Instance_EntityDeleted; }
public void Should_Insert_And_Retrieve_PageProperties_Successfully() { var entity = TestDataProvider.CreateNewPageProperties(); RunEntityMapTestsInTransaction(entity); }
private PageProperties[] CreateNestedOptions(ISession session, int level) { var pages = new PageProperties[3]; // Create layout and options var layout = TestDataProvider.CreateNewLayout(); var lo1 = TestDataProvider.CreateNewLayoutOption(layout); lo1.Type = OptionType.Text; lo1.Key = "l1"; lo1.DefaultValue = "l1"; var lo2 = TestDataProvider.CreateNewLayoutOption(layout); lo2.Type = OptionType.Text; lo2.Key = "l2"; lo2.DefaultValue = "l2"; var lo3 = TestDataProvider.CreateNewLayoutOption(layout); lo3.Type = OptionType.Text; lo3.Key = "l3"; lo3.DefaultValue = "l3"; layout.LayoutOptions = new List <LayoutOption> { lo1, lo2, lo3 }; session.SaveOrUpdate(layout); // Create Master page var page1 = TestDataProvider.CreateNewPageProperties(layout); var o11 = TestDataProvider.CreateNewPageOption(page1); o11.Type = OptionType.Text; o11.Key = "p1"; o11.Value = "p1"; var o12 = TestDataProvider.CreateNewPageOption(page1); o12.Type = OptionType.Text; o12.Key = "l3"; o12.Value = "l3p1"; page1.Options = new List <PageOption> { o11, o12 }; session.SaveOrUpdate(page1); pages[0] = page1; if (level > 1) { // Create First Child With Options var page2 = TestDataProvider.CreateNewPageProperties(); page2.Layout = null; page2.MasterPage = page1; var o21 = TestDataProvider.CreateNewPageOption(page2); o21.Type = OptionType.Text; o21.Key = "p2"; o21.Value = "p2"; var o22 = TestDataProvider.CreateNewPageOption(page2); o22.Type = OptionType.Text; o22.Key = "l3"; o22.Value = "l3p2"; var o23 = TestDataProvider.CreateNewPageOption(page2); o23.Type = OptionType.Text; o23.Key = "l2"; o23.Value = "l2p2"; page2.Options = new List <PageOption> { o21, o22, o23 }; session.SaveOrUpdate(page2); pages[1] = page2; var master21 = new MasterPage { Page = page2, Master = page1 }; session.SaveOrUpdate(master21); if (level > 2) { // Create Second Child With Options var page3 = TestDataProvider.CreateNewPageProperties(); page3.Layout = null; page3.MasterPage = page2; var o31 = TestDataProvider.CreateNewPageOption(page3); o31.Type = OptionType.Text; o31.Key = "l3"; o31.Value = "l3p3"; page3.Options = new List <PageOption> { o31 }; session.SaveOrUpdate(page3); pages[2] = page3; var master31 = new MasterPage { Page = page3, Master = page1 }; session.SaveOrUpdate(master31); var master32 = new MasterPage { Page = page3, Master = page2 }; session.SaveOrUpdate(master32); } } session.Flush(); session.Clear(); return(pages); }
public void Should_Sort_Page_Content_Successfully() { RunActionInTransaction(session => { var layout = TestDataProvider.CreateNewLayout(); var region = TestDataProvider.CreateNewRegion(); layout.LayoutRegions = new List <LayoutRegion> { TestDataProvider.CreateNewLayoutRegion(layout, region), }; var page = TestDataProvider.CreateNewPageProperties(layout); page.PageContents = new[] { TestDataProvider.CreateNewPageContent(TestDataProvider.CreateNewHtmlContent(), page, region), TestDataProvider.CreateNewPageContent(TestDataProvider.CreateNewHtmlContent(), page, region), TestDataProvider.CreateNewPageContent(TestDataProvider.CreateNewHtmlContent(), page, region) }; session.SaveOrUpdate(page); session.Flush(); session.Clear(); IUnitOfWork unitOfWork = new DefaultUnitOfWork(session); SortPageContentCommand command = new SortPageContentCommand(); command.UnitOfWork = unitOfWork; command.Repository = new DefaultRepository(unitOfWork); var request = new PageContentSortViewModel { PageId = page.Id, RegionId = region.Id, PageContents = new List <ContentSortViewModel> { new ContentSortViewModel { Id = page.PageContents[2].Id, Version = page.PageContents[2].Version }, new ContentSortViewModel { Id = page.PageContents[1].Id, Version = page.PageContents[1].Version }, new ContentSortViewModel { Id = page.PageContents[0].Id, Version = page.PageContents[0].Version }, } }; var response = command.Execute(request); Assert.AreEqual(2, response.UpdatedPageContents.Count); session.Flush(); session.Clear(); var updatedPage = command.Repository.AsQueryable <PageContent>(f => f.Page.Id == page.Id).ToList(); Assert.AreEqual(2, updatedPage.FirstOrDefault(f => f.Id == page.PageContents[0].Id).Order); Assert.AreEqual(1, updatedPage.FirstOrDefault(f => f.Id == page.PageContents[1].Id).Order); Assert.AreEqual(0, updatedPage.FirstOrDefault(f => f.Id == page.PageContents[2].Id).Order); }); }
public void Should_Sort_Page_Content_Successfully() { RunActionInTransaction(session => { var layout = TestDataProvider.CreateNewLayout(); var region = TestDataProvider.CreateNewRegion(); layout.LayoutRegions = new List <LayoutRegion> { TestDataProvider.CreateNewLayoutRegion(layout, region), }; var page = TestDataProvider.CreateNewPageProperties(layout); page.PageContents = new[] { TestDataProvider.CreateNewPageContent(TestDataProvider.CreateNewHtmlContent(), page, region), TestDataProvider.CreateNewPageContent(TestDataProvider.CreateNewHtmlContent(), page, region), TestDataProvider.CreateNewPageContent(TestDataProvider.CreateNewHtmlContent(), page, region) }; session.SaveOrUpdate(page); session.Flush(); session.Clear(); IUnitOfWork unitOfWork = new DefaultUnitOfWork(session); var configuration = Container.Resolve <ICmsConfiguration>(); SortPageContentCommand command = new SortPageContentCommand(configuration); command.UnitOfWork = unitOfWork; command.Repository = new DefaultRepository(unitOfWork); command.Context = new Mock <ICommandContext>().Object; var accessControlService = new Mock <IAccessControlService>(); accessControlService.Setup(s => s.DemandAccess(It.IsAny <IPrincipal>(), It.IsAny <string>())); command.AccessControlService = accessControlService.Object; var request = new PageContentSortViewModel { PageId = page.Id, PageContents = new List <ContentSortViewModel> { new ContentSortViewModel { RegionId = region.Id, PageContentId = page.PageContents[2].Id, Version = page.PageContents[2].Version }, new ContentSortViewModel { RegionId = region.Id, PageContentId = page.PageContents[1].Id, Version = page.PageContents[1].Version }, new ContentSortViewModel { RegionId = region.Id, PageContentId = page.PageContents[0].Id, Version = page.PageContents[0].Version }, } }; var response = command.Execute(request); Assert.IsTrue(response); session.Flush(); session.Clear(); var updatedPage = command.Repository.AsQueryable <PageContent>(f => f.Page.Id == page.Id).ToList(); Assert.AreEqual(2, updatedPage.FirstOrDefault(f => f.Id == page.PageContents[0].Id).Order); Assert.AreEqual(1, updatedPage.FirstOrDefault(f => f.Id == page.PageContents[1].Id).Order); Assert.AreEqual(0, updatedPage.FirstOrDefault(f => f.Id == page.PageContents[2].Id).Order); }); }