コード例 #1
0
        public void Should_Return_MergedOptionsAndValuesSuccessfully()
        {
            var option1 = TestDataProvider.CreateNewLayoutOption();
            var option2 = TestDataProvider.CreateNewLayoutOption();
            var option3 = TestDataProvider.CreateNewLayoutOption();
            var option4 = TestDataProvider.CreateNewLayoutOption();
            var option5 = TestDataProvider.CreateNewLayoutOption();

            var optionValue1 = TestDataProvider.CreateNewPageOption();
            var optionValue2 = TestDataProvider.CreateNewPageOption();
            var optionValue3 = TestDataProvider.CreateNewPageOption();
            var optionValue4 = TestDataProvider.CreateNewPageOption();
            var optionValue5 = TestDataProvider.CreateNewPageOption();

            optionValue1.Key  = option1.Key;
            optionValue2.Key  = option2.Key;
            option1.Type      = option2.Type = option3.Type = option4.Type = option5.Type = OptionType.Text;
            optionValue1.Type = optionValue2.Type = optionValue3.Type = optionValue4.Type = optionValue5.Type = OptionType.Text;

            option3.DefaultValue = null;
            optionValue4.Value   = null;
            var service      = CreateOptionService();
            var optionValues = new List <IOptionValueEntity> {
                optionValue1, optionValue2, optionValue3, optionValue4, optionValue5
            };
            var options = new List <IOptionEntity> {
                option1, option2, option3, option4, option5
            };

            var result = service.GetMergedOptionValues(options, optionValues);

            Assert.NotNull(result);
            Assert.AreEqual(result.Count, 8);
            Assert.AreEqual(6, result.Count(o => o.Value != null));
        }
コード例 #2
0
ファイル: PageMapTest.cs プロジェクト: dziedrius/BetterCMS
        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));
            });
        }
コード例 #3
0
        public void Should_Return_MergedOptionsAndValues_ForEdit_Successfully()
        {
            var option1 = TestDataProvider.CreateNewLayoutOption();
            var option2 = TestDataProvider.CreateNewLayoutOption();
            var option3 = TestDataProvider.CreateNewLayoutOption();
            var option4 = TestDataProvider.CreateNewLayoutOption();
            var option5 = TestDataProvider.CreateNewLayoutOption();

            var optionValue1 = TestDataProvider.CreateNewPageOption();
            var optionValue2 = TestDataProvider.CreateNewPageOption();
            var optionValue3 = TestDataProvider.CreateNewPageOption();
            var optionValue4 = TestDataProvider.CreateNewPageOption();
            var optionValue5 = TestDataProvider.CreateNewPageOption();

            optionValue1.Key  = option1.Key;
            optionValue2.Key  = option2.Key;
            option1.Type      = option2.Type = option3.Type = option4.Type = option5.Type = OptionType.Text;
            optionValue1.Type = optionValue2.Type = optionValue3.Type = optionValue4.Type = optionValue5.Type = OptionType.Text;

            option3.DefaultValue = null;
            optionValue4.Value   = null;

            var service      = CreateOptionService();
            var optionValues = new List <IOptionValueEntity> {
                optionValue1, optionValue2, optionValue3, optionValue4, optionValue5
            };
            var options = new List <IOptionEntity> {
                option1, option2, option3, option4, option5
            };

            var result = service.GetMergedOptionValuesForEdit(options, optionValues);

            Assert.NotNull(result);
            Assert.AreEqual(result.Count, 8);
            // 3 of 5 values has no equivalent option, so they can be edited
            Assert.AreEqual(result.Count(o => o.CanEditOption), 3);
            // 4 of 5 options has default values
            Assert.AreEqual(result.Count(o => o.OptionDefaultValue == null), 4);
            // 4 of 5 option values has default values
            Assert.AreEqual(result.Count(o => o.OptionValue == o.OptionDefaultValue), 4);
            // 1 option and option value are equal
            Assert.AreEqual(result.Count(o => o.OptionKey == option1.Key &&
                                         o.OptionDefaultValue == option1.DefaultValue &&
                                         o.OptionValue == optionValue1.Value), 1);
            // 2 option and option value are equal
            Assert.AreEqual(result.Count(o => o.OptionKey == option2.Key &&
                                         o.OptionDefaultValue == option2.DefaultValue &&
                                         o.OptionValue == optionValue2.Value), 1);
        }
コード例 #4
0
        public void Should_Return_MergedOptions_ForEdit_Successfully()
        {
            var optionValue1 = TestDataProvider.CreateNewPageOption();
            var optionValue2 = TestDataProvider.CreateNewPageOption();
            var optionValue3 = TestDataProvider.CreateNewPageOption();

            optionValue1.Type  = optionValue2.Type = optionValue3.Type = OptionType.Text;
            optionValue3.Value = null;

            var service      = CreateOptionService();
            var optionValues = new List <IOptionValueEntity> {
                optionValue1, optionValue2, optionValue3
            };
            var options = new List <IOptionEntity>();

            var result = service.GetMergedOptionValuesForEdit(options, optionValues);

            Assert.NotNull(result);
            Assert.AreEqual(result.Count, 3);
        }
コード例 #5
0
        public void Should_Return_MergedOptionsSuccessfully()
        {
            var optionValue1 = TestDataProvider.CreateNewPageOption();
            var optionValue2 = TestDataProvider.CreateNewPageOption();
            var optionValue3 = TestDataProvider.CreateNewPageOption();

            optionValue1.Type = optionValue2.Type = optionValue3.Type = OptionType.Text;

            optionValue3.Value = null;

            var service      = new DefaultOptionService(null, new HttpRuntimeCacheService());
            var optionValues = new List <IOption> {
                optionValue1, optionValue2, optionValue3
            };
            var options = new List <IOption>();

            var result = service.GetMergedOptionValues(options, optionValues);

            Assert.NotNull(result);
            Assert.AreEqual(result.Count, 3);
            Assert.AreEqual(2, result.Count(o => o.Value != null));
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        public void Should_Insert_And_Retrieve_PageOption_Successfully()
        {
            var entity = TestDataProvider.CreateNewPageOption();

            RunEntityMapTestsInTransaction(entity);
        }