public void Should_By_Xml_And_Binary_Serializable() { var pageContent = TestDataProvider.CreateNewPageContent(); pageContent.Content = TestDataProvider.CreateNewHtmlContent(); pageContent.Options = new[] { TestDataProvider.CreateNewPageContentOption(pageContent), TestDataProvider.CreateNewPageContentOption(pageContent), TestDataProvider.CreateNewPageContentOption(pageContent) }; var cmsConfiguration = new Mock <ICmsConfiguration>(); var optionService = new DefaultOptionService(null, new HttpRuntimeCacheService(), cmsConfiguration.Object); var optionValues = optionService.GetMergedOptionValues(pageContent.Options, null); var original = new PageContentProjection( pageContent, pageContent.Content, new HtmlContentAccessor((HtmlContent)pageContent.Content, optionValues)); RunSerializationAndDeserialization(original, projection => { Assert.AreEqual(original.ContentId, projection.ContentId); Assert.AreEqual(original.Order, projection.Order); Assert.AreEqual(original.RegionId, projection.RegionId); }); }
public void Should_Insert_And_Retrieve_Page_PageContents_Successfully() { var page = TestDataProvider.CreateNewPage(); var pageContents = new[] { TestDataProvider.CreateNewPageContent(null, page), TestDataProvider.CreateNewPageContent(null, page), TestDataProvider.CreateNewPageContent(null, page) }; page.PageContents = pageContents; var pageOptions = new[] { TestDataProvider.CreateNewPageOption(page), TestDataProvider.CreateNewPageOption(page), TestDataProvider.CreateNewPageOption(page) }; page.Options = pageOptions; SaveEntityAndRunAssertionsInTransaction( page, result => { Assert.AreEqual(page, result); Assert.AreEqual(pageContents.OrderBy(f => f.Id), result.PageContents.OrderBy(f => f.Id)); }); }
public void Should_Delete_Page_Content() { RunActionInTransaction(session => { // Create content var content = TestDataProvider.CreateNewHtmlContent(); var pageContent = TestDataProvider.CreateNewPageContent(content); session.SaveOrUpdate(pageContent); session.Flush(); session.Clear(); // Delete page content var request = new DeletePageContentCommandRequest { PageContentId = pageContent.Id, PageContentVersion = pageContent.Version, ContentVersion = content.Version }; var unitOfWork = new DefaultUnitOfWork(session); var command = new DeletePageContentCommand(); command.UnitOfWork = unitOfWork; command.Repository = new DefaultRepository(unitOfWork); var result = command.Execute(request); Assert.IsTrue(result); }); }
public void Should_Delete_Page_Content() { RunActionInTransaction(session => { // Create content var content = TestDataProvider.CreateNewHtmlContent(); var pageContent = TestDataProvider.CreateNewPageContent(content); session.SaveOrUpdate(pageContent); session.Flush(); session.Clear(); // Delete page content var request = new DeletePageContentCommandRequest { PageContentId = pageContent.Id, PageContentVersion = pageContent.Version, ContentVersion = content.Version }; var unitOfWork = new DefaultUnitOfWork(session); var repository = new DefaultRepository(unitOfWork); var securityService = new Mock <ISecurityService>().Object; var optionService = new Mock <IOptionService>().Object; var childContentService = new Mock <IChildContentService>().Object; var contentService = new DefaultContentService(securityService, repository, optionService, childContentService); var command = new DeletePageContentCommand(contentService); command.UnitOfWork = unitOfWork; command.Repository = repository; var result = command.Execute(request); Assert.IsTrue(result); }); }
public void Should_Return_Page_Content_Options_Successfully() { RunActionInTransaction(session => { var content = TestDataProvider.CreateNewContent(); var pageContent = TestDataProvider.CreateNewPageContent(content); FillContentWithOptions(content); FillPageContentWithOptions(content, pageContent); session.SaveOrUpdate(pageContent); session.Flush(); session.Clear(); // Create command var unitOfWork = new DefaultUnitOfWork(session); var command = new GetPageContentOptionsCommand(); var repository = new DefaultRepository(unitOfWork); command.UnitOfWork = unitOfWork; command.Repository = repository; command.CmsConfiguration = Container.Resolve <ICmsConfiguration>(); command.OptionService = new DefaultOptionService(repository, new HttpRuntimeCacheService(), command.CmsConfiguration); // Execute command var result = command.Execute(pageContent.Id); // Should return 4 options: 2 with assigned values, 1 without parent option and 1 unassigned Assert.IsNotNull(result); Assert.IsNotNull(result.OptionValues); Assert.AreEqual(result.OptionValues.Count, 5); Assert.IsNotNull(result.OptionValues.FirstOrDefault(o => o.OptionKey == content.ContentOptions[0].Key && o.OptionValue == pageContent.Options[0].Value && o.OptionDefaultValue == content.ContentOptions[0].DefaultValue && !o.UseDefaultValue && !o.CanEditOption)); Assert.IsNotNull(result.OptionValues.FirstOrDefault(o => o.OptionKey == content.ContentOptions[1].Key && o.OptionValue == pageContent.Options[1].Value && o.OptionDefaultValue == content.ContentOptions[1].DefaultValue && !o.UseDefaultValue && !o.CanEditOption)); Assert.IsNotNull(result.OptionValues.FirstOrDefault(o => o.OptionKey == content.ContentOptions[2].Key && o.OptionValue == content.ContentOptions[2].DefaultValue && o.OptionDefaultValue == content.ContentOptions[2].DefaultValue && o.UseDefaultValue && !o.CanEditOption)); Assert.IsNotNull(result.OptionValues.FirstOrDefault(o => o.OptionKey == pageContent.Options[2].Key && o.OptionValue == pageContent.Options[2].Value && o.OptionDefaultValue == null && o.CanEditOption)); Assert.IsNotNull(result.OptionValues.FirstOrDefault(o => o.OptionKey == pageContent.Options[3].Key && o.OptionValue == pageContent.Options[3].Value && o.OptionDefaultValue == null && o.CanEditOption)); }); }
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 Should_Insert_HtmlWidget_To_Page_Successfully() { // Create html content var widget = TestDataProvider.CreateNewHtmlContentWidget(); widget.Status = ContentStatus.Published; var page = TestDataProvider.CreateNewPage(); var region = TestDataProvider.CreateNewRegion(); var pageContent = TestDataProvider.CreateNewPageContent(widget, page, region); pageContent.Order = TestDataProvider.ProvideRandomNumber(1, 99999); // Mock var repository = new Mock <IRepository>(); repository .Setup(r => r.AsProxy <Page>(It.IsAny <Guid>())) .Returns(TestDataProvider.CreateNewPage()); repository .Setup(r => r.AsProxy <Region>(It.IsAny <Guid>())) .Returns(TestDataProvider.CreateNewRegion()); repository .Setup(r => r.AsQueryable <PageContent>()) .Returns(new List <PageContent> { pageContent }.AsQueryable()); repository .Setup(r => r.Save(It.IsAny <PageContent>())) .Callback <PageContent>(pc => { Assert.AreEqual(pc.Order, pageContent.Order + 1); }); // Create command var command = new InsertContentToPageCommand(); command.UnitOfWork = new Mock <IUnitOfWork>().Object; command.Repository = repository.Object; // Execute var request = new InsertContentToPageRequest { ContentId = widget.Id, PageId = page.Id, RegionId = region.Id }; var result = command.Execute(request); Assert.IsNotNull(result); Assert.IsTrue(result); }
public void Should_Return_Page_Html_Content() { // Create html content var htmlContent = TestDataProvider.CreateNewHtmlContent(); var pageContent = TestDataProvider.CreateNewPageContent(htmlContent); htmlContent.Status = ContentStatus.Published; // Create command var command = new GetPageHtmlContentCommand(); command.UnitOfWork = new Mock <IUnitOfWork>().Object; command.Repository = new Mock <IRepository>().Object; command.Configuration = Container.Resolve <ICmsConfiguration>(); command.Context = new Mock <ICommandContext>().Object; // Mock security service var securityMock = new Mock <ISecurityService>(); securityMock.Setup(s => s.IsAuthorized(It.IsAny <IPrincipal>(), It.IsAny <string>())).Returns(true); command.SecurityService = securityMock.Object; // Mock content service var serviceMock = new Mock <IContentService>(); serviceMock .Setup(f => f.GetPageContentForEdit(pageContent.Id)) .Returns(new Tuple <PageContent, Content>(pageContent, htmlContent)); command.ContentService = serviceMock.Object; // Execute command var result = command.Execute(pageContent.Id); Assert.IsNotNull(result); Assert.AreEqual(result.Id, pageContent.Id); Assert.AreEqual(result.ContentId, htmlContent.Id); Assert.AreEqual(result.ContentName, htmlContent.Name); Assert.AreEqual(result.ContentVersion, htmlContent.Version); Assert.AreEqual(result.CurrentStatus, htmlContent.Status); Assert.AreEqual(result.PageId, pageContent.Page.Id); Assert.AreEqual(result.RegionId, pageContent.Region.Id); Assert.AreEqual(result.LiveFrom, htmlContent.ActivationDate); Assert.AreEqual(result.LiveTo, htmlContent.ExpirationDate); }
public void Should_Insert_And_Retrieve_Content_PageContents_Successfully() { var content = TestDataProvider.CreateNewContent(); var pageContents = new[] { TestDataProvider.CreateNewPageContent(content), TestDataProvider.CreateNewPageContent(content) }; content.PageContents = pageContents; SaveEntityAndRunAssertionsInTransaction( content, result => { Assert.AreEqual(content, result); Assert.AreEqual(pageContents.OrderBy(f => f.Id), result.PageContents.OrderBy(f => f.Id)); }); }
public void Should_Insert_And_Retrieve_Region_PageContentOptions_Successfully() { var region = TestDataProvider.CreateNewRegion(); var pageContents = new[] { TestDataProvider.CreateNewPageContent(null, null, region) }; region.PageContents = pageContents; SaveEntityAndRunAssertionsInTransaction( region, result => { Assert.AreEqual(region, result); Assert.AreEqual(pageContents.OrderBy(f => f.Id), result.PageContents.OrderBy(f => f.Id)); }); }
public void Should_Return_Page_Content_Options_Successfully() { RunActionInTransaction(session => { var content = TestDataProvider.CreateNewContent(); var pageContent = TestDataProvider.CreateNewPageContent(content); FillContentWithOptions(content); FillPageContentWithOptions(content, pageContent); session.SaveOrUpdate(pageContent); session.Flush(); session.Clear(); // Create command var unitOfWork = new DefaultUnitOfWork(session); var command = new GetPageContentOptionsCommand(); command.UnitOfWork = unitOfWork; command.Repository = new DefaultRepository(unitOfWork); // Execute command var result = command.Execute(pageContent.Id); // Should return 4 options: 2 with assigned values, 1 without parent option and 1 unassigned Assert.IsNotNull(result); Assert.IsNotNull(result.WidgetOptions); Assert.AreEqual(result.WidgetOptions.Count, 4); Assert.IsNotNull(result.WidgetOptions.FirstOrDefault(o => o.OptionKey == content.ContentOptions[0].Key && o.OptionValue == pageContent.Options[0].Value && o.OptionDefaultValue == content.ContentOptions[0].DefaultValue)); Assert.IsNotNull(result.WidgetOptions.FirstOrDefault(o => o.OptionKey == content.ContentOptions[1].Key && o.OptionValue == pageContent.Options[1].Value && o.OptionDefaultValue == content.ContentOptions[1].DefaultValue)); Assert.IsNotNull(result.WidgetOptions.FirstOrDefault(o => o.OptionKey == content.ContentOptions[2].Key && o.OptionValue == null && o.OptionDefaultValue == content.ContentOptions[2].DefaultValue)); Assert.IsNotNull(result.WidgetOptions.FirstOrDefault(o => o.OptionKey == pageContent.Options[2].Key && o.OptionValue == pageContent.Options[2].Value && o.OptionDefaultValue == null)); }); }
public void Should_By_Xml_And_Binary_Serializable() { var pageContent = TestDataProvider.CreateNewPageContent(); pageContent.Content = TestDataProvider.CreateNewHtmlContent(); pageContent.Options = new[] { TestDataProvider.CreateNewPageContentOption(pageContent), TestDataProvider.CreateNewPageContentOption(pageContent), TestDataProvider.CreateNewPageContentOption(pageContent) }; PageContentProjection original = new PageContentProjection( pageContent, pageContent.Content, new HtmlContentAccessor((HtmlContent)pageContent.Content, pageContent.Options.Cast <IOption>().ToList())); RunSerializationAndDeserialization(original, projection => { Assert.AreEqual(original.ContentId, projection.ContentId); Assert.AreEqual(original.Order, projection.Order); Assert.AreEqual(original.RegionId, projection.RegionId); }); }
public void Should_Insert_And_Retrieve_PageContent_Successfully() { var entity = TestDataProvider.CreateNewPageContent(); RunEntityMapTestsInTransaction(entity); }
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); }); }
public void Should_Save_Page_Content_Options_Successfully() { RunActionInTransaction(session => { // Create page content with options var content = TestDataProvider.CreateNewContent(); var pageContent = TestDataProvider.CreateNewPageContent(content); FillContentWithOptions(content); FillPageContentWithOptions(content, pageContent); session.SaveOrUpdate(pageContent); session.Flush(); session.Clear(); // Random option value var randomOptionValue = TestDataProvider.CreateNewPageContentOption(); // Create request var request = new PageContentOptionsViewModel { OptionValues = new List <OptionValueEditViewModel> { new OptionValueEditViewModel { // Must be updated OptionKey = pageContent.Options[0].Key, OptionValue = content.ContentOptions[0].DefaultValue, UseDefaultValue = false }, new OptionValueEditViewModel { // Must be deleted OptionKey = pageContent.Options[1].Key, OptionValue = null, UseDefaultValue = true }, new OptionValueEditViewModel { // Must be updated OptionKey = pageContent.Options[2].Key, OptionValue = null, UseDefaultValue = false }, new OptionValueEditViewModel { // Must be created OptionValue = randomOptionValue.Value, OptionKey = randomOptionValue.Key, Type = OptionType.Text } }, PageContentId = pageContent.Id }; // Create command var unitOfWork = new DefaultUnitOfWork(session); var repository = new DefaultRepository(unitOfWork); var command = new SavePageContentOptionsCommand(); command.UnitOfWork = unitOfWork; command.Repository = repository; command.OptionService = new DefaultOptionService(repository, new HttpRuntimeCacheService()); var result = command.Execute(request); Assert.IsTrue(result); // Check results: one of page content values must be deleted after save var results = repository .AsQueryable <PageContentOption>(pco => pco.PageContent.Id == pageContent.Id && !pco.IsDeleted && !pco.PageContent.IsDeleted) .ToList(); Assert.AreEqual(results.Count, 3); Assert.IsNotNull(results.FirstOrDefault(pco => { return(pco.Key == pageContent.Options[0].Key && pco.Value == content.ContentOptions[0].DefaultValue); })); Assert.IsNotNull(results.FirstOrDefault(pco => { return(pco.Key == pageContent.Options[2].Key && pco.Value == null); })); Assert.IsNotNull(results.FirstOrDefault(pco => pco.Key == randomOptionValue.Key && pco.Value == randomOptionValue.Value)); }); }
public void Should_Insert_HtmlWidget_To_Page_Successfully() { // Create html content var widget = TestDataProvider.CreateNewHtmlContentWidget(); widget.Status = ContentStatus.Published; var page = TestDataProvider.CreateNewPage(); var region = TestDataProvider.CreateNewRegion(); var pageContent = TestDataProvider.CreateNewPageContent(widget, page, region); pageContent.Order = TestDataProvider.ProvideRandomNumber(1, 99999); pageContent.Id = Guid.NewGuid(); pageContent.Version = 10; widget.Version = 20; // Mock content Service var contentService = new Mock <IContentService>(); contentService .Setup(r => r.GetPageContentNextOrderNumber(It.IsAny <Guid>(), It.IsAny <Guid?>())) .Returns(pageContent.Order + 1); // Mock var repository = new Mock <IRepository>(); repository .Setup(r => r.AsProxy <Page>(It.IsAny <Guid>())) .Returns(TestDataProvider.CreateNewPage()); repository .Setup(r => r.AsProxy <Region>(It.IsAny <Guid>())) .Returns(TestDataProvider.CreateNewRegion()); repository .Setup(r => r.AsQueryable <PageContent>()) .Returns(new List <PageContent> { pageContent }.AsQueryable()); repository .Setup(r => r.AsQueryable <Content>()) .Returns(new List <Content> { widget }.AsQueryable()); repository .Setup(r => r.Save(It.IsAny <PageContent>())) .Callback <PageContent>(pc => { Assert.AreEqual(pc.Order, pageContent.Order + 1); pc.Id = pageContent.Id; pc.Version = pageContent.Version; }); // Create command var command = new InsertContentToPageCommand(contentService.Object, new FakePageContentProjectionFactory(null, null), new Mock <IWidgetService>().Object); command.UnitOfWork = new Mock <IUnitOfWork>().Object; command.Repository = repository.Object; // Execute var request = new InsertContentToPageRequest { ContentId = widget.Id, PageId = page.Id, RegionId = region.Id }; var result = command.Execute(request); Assert.IsNotNull(result); Assert.AreEqual(result.PageContentId, pageContent.Id); Assert.AreEqual(result.PageId, page.Id); Assert.AreEqual(result.ContentId, widget.Id); Assert.AreEqual(result.ContentType, "html-widget"); Assert.AreEqual(result.ContentVersion, widget.Version); Assert.AreEqual(result.PageContentVersion, pageContent.Version); Assert.AreEqual(result.Title, widget.Name); Assert.AreEqual(result.RegionId, region.Id); Assert.AreEqual(result.DesirableStatus, widget.Status); }
protected override SavePageContentModel GetCreateModel(ISession session) { var parentContent = TestDataProvider.CreateNewHtmlContent(20); var parentRegion = TestDataProvider.CreateNewRegion(); var parentPageContent = TestDataProvider.CreateNewPageContent(parentContent, page, parentRegion); var content = TestDataProvider.CreateNewHtmlContent(20); var region = TestDataProvider.CreateNewRegion(); var contentOption = new ContentOption { Content = content, DefaultValue = TestDataProvider.ProvideRandomString(100), Key = TestDataProvider.ProvideRandomString(100), Type = BetterCms.Core.DataContracts.Enums.OptionType.Text }; session.SaveOrUpdate(parentContent); session.SaveOrUpdate(parentRegion); session.SaveOrUpdate(parentPageContent); session.SaveOrUpdate(content); session.SaveOrUpdate(region); session.SaveOrUpdate(contentOption); var model = new SavePageContentModel { Order = 100, ContentId = content.Id, RegionId = region.Id, ParentPageContentId = hasParentContent ? parentPageContent.Id : (Guid?)null }; if (setOptions) { model.Options = new List <OptionValueModel> { new OptionValueModel { DefaultValue = TestDataProvider.ProvideRandomString(100), Value = TestDataProvider.ProvideRandomString(100), Key = TestDataProvider.ProvideRandomString(100), Type = OptionType.Text, UseDefaultValue = false }, new OptionValueModel { DefaultValue = Guid.NewGuid().ToString(), Value = Guid.NewGuid().ToString(), Key = TestDataProvider.ProvideRandomString(100), Type = OptionType.Custom, CustomTypeIdentifier = MediaManagerFolderOptionProvider.Identifier, UseDefaultValue = false }, new OptionValueModel { DefaultValue = contentOption.DefaultValue, Value = TestDataProvider.ProvideRandomString(100), Key = contentOption.Key, Type = (OptionType)(int)contentOption.Type, UseDefaultValue = true }, }; } return(model); }
public void Should_Save_Page_Content_Options_Successfully() { RunActionInTransaction(session => { // Create page content with options var content = TestDataProvider.CreateNewContent(); var pageContent = TestDataProvider.CreateNewPageContent(content); FillContentWithOptions(content); FillPageContentWithOptions(content, pageContent); session.SaveOrUpdate(pageContent); session.Flush(); session.Clear(); // Random option value var randomOptionValue = TestDataProvider.CreateNewPageContentOption(); // Create request var request = new PageContentOptionsViewModel { WidgetOptions = new List <PageContentOptionViewModel> { new PageContentOptionViewModel { // Will be deleted because of default value OptionValue = content.ContentOptions[0].DefaultValue, OptionKey = pageContent.Options[0].Key, OptionDefaultValue = content.ContentOptions[0].DefaultValue }, new PageContentOptionViewModel { // Will be deleted because of null value OptionValue = null, OptionKey = pageContent.Options[1].Key }, new PageContentOptionViewModel { OptionValue = pageContent.Options[2].Value, OptionKey = pageContent.Options[2].Key }, new PageContentOptionViewModel { // Random value OptionValue = randomOptionValue.Value, OptionKey = randomOptionValue.Key } }, PageContentId = pageContent.Id }; // Create command var unitOfWork = new DefaultUnitOfWork(session); var repository = new DefaultRepository(unitOfWork); var command = new SavePageContentOptionsCommand(); command.UnitOfWork = unitOfWork; command.Repository = repository; var result = command.Execute(request); Assert.IsTrue(result); // Check results: one of page content values must be deleted after save var results = repository .AsQueryable <PageContentOption>(pco => pco.PageContent.Id == pageContent.Id && !pco.IsDeleted && !pco.PageContent.IsDeleted) .ToList(); Assert.AreEqual(results.Count, 2); Assert.IsNotNull(results.FirstOrDefault(pco => pco.Key == pageContent.Options[2].Key && pco.Value == pageContent.Options[2].Value)); Assert.IsNotNull(results.FirstOrDefault(pco => pco.Key == randomOptionValue.Key && pco.Value == randomOptionValue.Value)); }); }
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); }); }