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); }); }
protected void FillPageContentWithOptions(Content content, PageContent pageContent) { var po1 = TestDataProvider.CreateNewPageContentOption(pageContent); po1.Key = content.ContentOptions[0].Key; po1.Type = OptionType.Text; var po2 = TestDataProvider.CreateNewPageContentOption(pageContent); po2.Key = content.ContentOptions[1].Key; po2.Type = OptionType.Text; var po3 = TestDataProvider.CreateNewPageContentOption(pageContent); po3.Key = Guid.NewGuid().ToString(); po3.Type = OptionType.Text; var po4 = TestDataProvider.CreateNewPageContentOption(pageContent); po4.Key = Guid.NewGuid().ToString(); po4.Type = OptionType.Text; pageContent.Options = new List <PageContentOption>(); pageContent.Options.Add(po1); pageContent.Options.Add(po2); pageContent.Options.Add(po3); pageContent.Options.Add(po4); }
public void Should_Insert_And_Retrieve_PageContent_PageContentOptions_Successfully() { var pageContent = TestDataProvider.CreateNewPageContent(); var pageContentOptions = new[] { TestDataProvider.CreateNewPageContentOption(pageContent), TestDataProvider.CreateNewPageContentOption(pageContent) }; pageContent.Options = pageContentOptions; SaveEntityAndRunAssertionsInTransaction( pageContent, result => { Assert.AreEqual(pageContent, result); Assert.AreEqual(pageContentOptions.OrderBy(f => f.Id), result.Options.OrderBy(f => f.Id)); }); }
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_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_And_Retrieve_PageContentOption_Successfully() { var entity = TestDataProvider.CreateNewPageContentOption(); RunEntityMapTestsInTransaction(entity); }
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)); }); }