Пример #1
0
        public void Should_ThrowValidationException_AboutNonDeletableOption()
        {
            RunActionInTransaction(session =>
            {
                var unitOfWork = new DefaultUnitOfWork(session);
                var repository = new DefaultRepository(unitOfWork);

                var optionService = new DefaultOptionService(repository, new HttpRuntimeCacheService());

                // Create layout with options
                var layout           = TestDataProvider.CreateNewLayout();
                layout.LayoutOptions = new List <LayoutOption>();

                var option1         = TestDataProvider.CreateNewLayoutOption(layout);
                option1.Type        = OptionType.Text;
                option1.IsDeletable = false;
                layout.LayoutOptions.Add(option1);

                session.SaveOrUpdate(layout);
                session.Flush();
                session.Clear();

                optionService.SetOptions <LayoutOption, Layout>(layout, new List <IOption>());
                unitOfWork.Commit();
            });
        }
Пример #2
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));
        }
        public void Should_Save_Options_Successfully()
        {
            RunActionInTransaction(session =>
            {
                var unitOfWork = new DefaultUnitOfWork(session);
                var repository = new DefaultRepository(unitOfWork);

                var cmsConfiguration = new Mock <ICmsConfiguration>();
                var optionService    = new DefaultOptionService(repository, new HttpRuntimeCacheService(), cmsConfiguration.Object);

                // Create layout with options
                var layout           = TestDataProvider.CreateNewLayout();
                layout.LayoutOptions = new List <LayoutOption>();

                var option1  = TestDataProvider.CreateNewLayoutOption(layout);
                option1.Type = OptionType.Text;
                layout.LayoutOptions.Add(option1);

                var option2  = TestDataProvider.CreateNewLayoutOption(layout);
                option2.Type = OptionType.Text;
                layout.LayoutOptions.Add(option2);

                var option3  = TestDataProvider.CreateNewLayoutOption(layout);
                option3.Type = OptionType.Text;
                layout.LayoutOptions.Add(option3);

                session.SaveOrUpdate(layout);
                session.Flush();
                session.Clear();

                // Create fake options:
                // 1 should be kept
                // 2 should be updated
                // 3 should be inserted
                // option2 should be deleted
                var newOption1 = new LayoutOption {
                    Key = option1.Key, Type = option1.Type, DefaultValue = option1.DefaultValue
                };
                var newOption2 = new LayoutOption {
                    Key = option2.Key, Type = option2.Type, DefaultValue = TestDataProvider.ProvideRandomString(100)
                };
                var newOption3 = new LayoutOption {
                    Key = TestDataProvider.ProvideRandomString(100), Type = OptionType.Text, DefaultValue = TestDataProvider.ProvideRandomString(100)
                };
                var newOptions = new List <IOptionEntity> {
                    newOption1, newOption2, newOption3
                };

                optionService.SetOptions <LayoutOption, Layout>(layout, newOptions);
                unitOfWork.Commit();

                // Load all options
                var options = repository.AsQueryable <LayoutOption>(lo => lo.Layout == layout).ToList();

                Assert.AreEqual(options.Count, 3);
                Assert.IsTrue(options.Any(o => o.Key == option1.Key && o.DefaultValue == option1.DefaultValue && o.Type == option1.Type));
                Assert.IsTrue(options.Any(o => o.Key == option2.Key && o.DefaultValue == newOption2.DefaultValue && o.Type == option2.Type));
                Assert.IsTrue(options.Any(o => o.Key == newOption3.Key && o.DefaultValue == newOption3.DefaultValue && o.Type == newOption3.Type));
            });
        }
Пример #4
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);
        }
Пример #5
0
        public void Should_Return_Null_Values_Not_ConvertedToDateTime()
        {
            var service      = CreateOptionService();
            var optionValues = new List <IOptionValueEntity>();
            var options      = new List <IOptionEntity>();

            var option = TestDataProvider.CreateNewLayoutOption();

            option.DefaultValue = "not-datetime";
            option.Type         = OptionType.DateTime;
            options.Add(option);

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

            Assert.NotNull(result);
            Assert.IsNull(result[0].Value);
        }
Пример #6
0
        public void Should_Return_Null_Values_Not_ConvertedToInteger()
        {
            var service      = new DefaultOptionService(null, new HttpRuntimeCacheService());
            var optionValues = new List <IOption>();
            var options      = new List <IOption>();

            var option = TestDataProvider.CreateNewLayoutOption();

            option.DefaultValue = "not-integer";
            option.Type         = OptionType.Integer;
            options.Add(option);

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

            Assert.NotNull(result);
            Assert.IsNull(result[0].Value);
        }
Пример #7
0
        public void Should_Return_Null_Values_Not_ConvertedToFloat()
        {
            var service      = new DefaultOptionService(null);
            var optionValues = new List <IOption>();
            var options      = new List <IOption>();

            var option = TestDataProvider.CreateNewLayoutOption();

            option.DefaultValue = "not-float";
            option.Type         = OptionType.Float;
            options.Add(option);

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

            Assert.NotNull(result);
            Assert.AreEqual(result.Count, 1);
            Assert.IsNull(result[0].Value);
        }
Пример #8
0
        public void Should_Return_ValuesConvertedToFloat()
        {
            var service      = new DefaultOptionService(null, new HttpRuntimeCacheService());
            var optionValues = new List <IOption>();
            var options      = new List <IOption>();

            var option = TestDataProvider.CreateNewLayoutOption();

            option.DefaultValue = "10.5";
            option.Type         = OptionType.Float;
            options.Add(option);

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

            Assert.NotNull(result);
            Assert.AreEqual(result.Count, 1);
            Assert.AreEqual(result[0].Value is decimal, true);
            Assert.AreEqual(result[0].Value, 10.5M);
        }
Пример #9
0
        public void Should_Return_ValuesConvertedToLongInteger()
        {
            var service      = new DefaultOptionService(null, new HttpRuntimeCacheService());
            var optionValues = new List <IOption>();
            var options      = new List <IOption>();

            var option = TestDataProvider.CreateNewLayoutOption();

            option.DefaultValue = "4294967296";
            option.Type         = OptionType.Integer;
            options.Add(option);

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

            Assert.NotNull(result);
            Assert.AreEqual(result.Count, 1);
            Assert.AreEqual(result[0].Value is long, true);
            Assert.AreEqual(result[0].Value, 4294967296);
        }
Пример #10
0
        public void Should_Return_ValuesConvertedToBoolean()
        {
            var service      = new DefaultOptionService(null);
            var optionValues = new List <IOption>();
            var options      = new List <IOption>();

            var option = TestDataProvider.CreateNewLayoutOption();

            option.DefaultValue = "true";
            option.Type         = OptionType.Boolean;
            options.Add(option);

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

            Assert.NotNull(result);
            Assert.AreEqual(result.Count, 1);
            Assert.AreEqual(result[0].Value is bool, true);
            Assert.AreEqual(result[0].Value, true);
        }
Пример #11
0
        public void Should_Return_MergedOptionValues_ForEdit_Successfully()
        {
            var option1 = TestDataProvider.CreateNewLayoutOption();
            var option2 = TestDataProvider.CreateNewLayoutOption();
            var option3 = TestDataProvider.CreateNewLayoutOption();

            option1.Type         = option2.Type = option3.Type = OptionType.Text;
            option3.DefaultValue = null;

            var service      = CreateOptionService();
            var optionValues = new List <IOptionValueEntity>();
            var options      = new List <IOptionEntity> {
                option1, option2, option3
            };

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

            Assert.NotNull(result);
            Assert.AreEqual(result.Count, 3);
        }
Пример #12
0
        public void Should_Return_MergedOptionValuesSuccessfully()
        {
            var option1 = TestDataProvider.CreateNewLayoutOption();
            var option2 = TestDataProvider.CreateNewLayoutOption();
            var option3 = TestDataProvider.CreateNewLayoutOption();

            option1.Type = option2.Type = option3.Type = OptionType.Text;

            option3.DefaultValue = null;

            var service      = new DefaultOptionService(null, new HttpRuntimeCacheService());
            var optionValues = new List <IOption>();
            var options      = new List <IOption> {
                option1, option2, option3
            };

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

            Assert.NotNull(result);
            Assert.AreEqual(result.Count, 3);
            Assert.AreEqual(2, result.Count(o => o.Value != null));
        }
Пример #13
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);
        }
Пример #14
0
        public void Should_Insert_And_Retrieve_LayoutOption_Successfully()
        {
            var layoutOption = TestDataProvider.CreateNewLayoutOption();

            RunEntityMapTestsInTransaction(layoutOption);
        }