Esempio n. 1
0
        void InvalidPathBindingOperationTest2()
        {
            var source = new SimpleClass1();

            var target = new SimpleClass1
            {
                Child = new SimpleClass1
                {
                    Child = new SimpleClass1
                    {
                        LastName = "A"
                    }
                }
            };

            new BindingInfo
            {
                BindingMode = BindingMode.TwoWay,
                Source      = source,
                SourcePath  = "Child.Child.LastName",

                Target     = target,
                TargetPath = "Child.Child.LastName"
            }.Connect();


            MustEqualByReference(null, source.Child);

            target.Child.Child.LastName = "B";

            MustEqualByReference(null, source.Child);

            source.Child = new SimpleClass1
            {
                Child = new  SimpleClass1
                {
                    LastName = "C"
                }
            };


            MustEqual("C", target.Child.Child.LastName);
        }
Esempio n. 2
0
        public void TwoWayCircularBindingBetweenThreeItemsMustbeSupport()
        {
            var simpleClass1 = new SimpleClass1();
            var simpleClass2 = new SimpleClass1();
            var simpleClass3 = new SimpleClass1();

            new BindingInfo
            {
                BindingMode = BindingMode.TwoWay,
                SourcePath  = LastName,
                Source      = simpleClass1,
                Target      = simpleClass2,
                TargetPath  = LastName
            }.Connect();

            new BindingInfo
            {
                BindingMode = BindingMode.TwoWay,
                SourcePath  = LastName,
                Source      = simpleClass2,
                Target      = simpleClass3,
                TargetPath  = LastName
            }.Connect();

            new BindingInfo
            {
                BindingMode = BindingMode.TwoWay,
                SourcePath  = LastName,
                Source      = simpleClass3,
                Target      = simpleClass1,
                TargetPath  = LastName
            }.Connect();

            simpleClass1.LastName = "Alex1";
            MustEqual("Alex1", simpleClass2.LastName);
            MustEqual("Alex1", simpleClass3.LastName);

            simpleClass2.LastName = "Alex3";

            MustEqual("Alex3", simpleClass1.LastName);
            MustEqual("Alex3", simpleClass3.LastName);
        }
Esempio n. 3
0
        static void simpleBindingfor_src(Assert Assert)
        {
            var simpleClass1 = new SimpleClass1();

            var img             = DOM.CreateElement("img");
            var htmlBindingInfo = new HTMLBindingInfo
            {
                Source      = simpleClass1,
                SourcePath  = "LastName",
                Target      = img,
                TargetPath  = "src",
                BindingMode = BindingMode.OneWay
            };

            htmlBindingInfo.Connect();

            simpleClass1.LastName = TestHelper.SampleImageUrl_350_150;

            Assert.AreEqual(TestHelper.SampleImageUrl_350_150, img.Attr("src"));
        }
Esempio n. 4
0
        public void SimpleBind()
        {
            var simpleClass1 = new SimpleClass1();
            var simpleClass2 = new SimpleClass1();

            var bindingInfo = new BindingInfo
            {
                BindingMode = BindingMode.OneWay,
                SourcePath  = LastName,
                Source      = simpleClass1,
                Target      = simpleClass2,
                TargetPath  = LastName
            };

            bindingInfo.Connect();

            simpleClass1.LastName = "Alex1";

            MustEqual("Alex1", simpleClass2.LastName);
        }
Esempio n. 5
0
        void SimpleBind_with_Different_primitive_types()
        {
            var simpleClass1 = new SimpleClass1();
            var simpleClass2 = new SimpleClass1();

            var bindingInfo = new BindingInfo
            {
                BindingMode = BindingMode.OneWay,
                SourcePath  = LastName,
                Source      = simpleClass1,
                Target      = simpleClass2,
                TargetPath  = Year
            };

            bindingInfo.Connect();

            simpleClass1.LastName = "56";

            MustEqual(56, simpleClass2.Year);
        }
        void LogicalTreeTest2()
        {
            var model = new SimpleClass1
            {
                LastName = "A",
                Child    = new SimpleClass1
                {
                    LastName = "B",

                    Child = new SimpleClass1
                    {
                        LastName = "C"
                    }
                }
            };

            var userControl = UIBuilder.Create <UserControl2>();

            userControl.DataContext = model;

            UIBuilder.LoadComponent(userControl,
                                    "<div id='0' class='{LastName}'> " +
                                    "    <div id='1' class='{Child.LastName}'> " +
                                    "        <div id='2' class='{Child.Child.LastName}' />" +
                                    "    </div>" +
                                    "</div>");



            var ui = userControl.GetLogicalChildAt(0);

            MustEqual(1, ui.LogicalChilderen.Count);

            MustEqual("A", ui._root.Attr("class"));

            MustEqual("B", ui.GetLogicalChildAt(0)._root.Attr("class"));

            MustEqual(1, ui.GetLogicalChildAt(0).LogicalChilderen.Count);

            MustEqual("C", ui.GetLogicalChildAt(0).GetLogicalChildAt(0)._root.Attr("class"));
        }
        void ComponentCreationTest()
        {
            Component123.DefineForBuilder();

            var model = new SimpleClass1
            {
                LastName = "X",
                Child    = new SimpleClass1
                {
                    LastName = "Y",

                    Child = new SimpleClass1
                    {
                        LastName = "Z"
                    }
                }
            };

            var fe = new FrameworkElement
            {
                DataContext = model
            };

            UIBuilder.LoadComponent(fe, "<Component123  StringProperty0 = '{LastName}' StringProperty1 = '{Child.LastName}' StringProperty2 = '{Child.Child.LastName}' />");

            var ui = (Component123)fe.GetLogicalChildAt(0);

            MustEqualByReference(model, ui.DataContext);

            MustEqual(model.LastName, ui.StringProperty0);
            MustEqual(model.Child.LastName, ui.StringProperty1);
            MustEqual(model.Child.Child.LastName, ui.StringProperty2);

            model.LastName             = "1";
            model.Child.LastName       = "2";
            model.Child.Child.LastName = "3";

            MustEqual(model.LastName, ui.StringProperty0);
            MustEqual(model.Child.LastName, ui.StringProperty1);
            MustEqual(model.Child.Child.LastName, ui.StringProperty2);
        }
        void InputTypeHidden()
        {
            var model = new SimpleClass1
            {
                LastName = "Neşet Ertaş"
            };

            var htmlString = "<input id='A' type='hidden' value='{LastName,Mode=TwoWay}' />";

            var ui = BuildAndGetFirstLogicalChild(htmlString, model);

            MustEqual("<input id='A' type='hidden' value='Neşet Ertaş'>", ui._el.AsHtmlString());

            model.LastName = "Qwr";

            MustEqual("<input id='A' type='hidden' value='Qwr'>", ui._el.AsHtmlString());

            ui._root.Val("xyZ").Change();

            MustEqual("xyZ", model.LastName);
        }
        void LogicalTreeTest()
        {
            var model = new SimpleClass1
            {
                LastName = "A",
                Child    = new SimpleClass1
                {
                    LastName = "B",

                    Child = new SimpleClass1
                    {
                        LastName = "C"
                    }
                }
            };

            var fe = new HtmlElement
            {
                DataContext = model
            };

            UIBuilder.LoadComponent(fe, "<div class='{LastName}'> " +
                                    "    <div class='{Child.LastName}'> " +
                                    "        <div class='{Child.Child.LastName}' />" +
                                    "    </div>" +
                                    "</div>");

            var ui = fe.GetLogicalChildAt(0);

            MustEqual(1, ui.LogicalChilderen.Count);

            MustEqual("A", ui.Attr("class"));

            MustEqual("B", ui.GetLogicalChildAt(0).Attr("class"));

            MustEqual(1, ui.GetLogicalChildAt(0).LogicalChilderen.Count);

            MustEqual("C", ui.GetLogicalChildAt(0).GetLogicalChildAt(0).Attr("class"));
        }
        void class_attribute_must_support_binding()
        {
            var model = new SimpleClass1
            {
                LastName = "B"
            };

            var fe = new FrameworkElement
            {
                DataContext = model
            };

            UIBuilder.LoadComponent(fe, "<div class = '{LastName}' />");

            var ui = fe.GetLogicalChildAt(0);

            MustEqual("B", ui.Attr("class"));

            model.LastName = "A";

            MustEqual("A", ui.Attr("class"));
        }
Esempio n. 11
0
        public void LongPropertyPathForSource()
        {
            var simpleClass1 = new SimpleClass1
            {
                Child = new SimpleClass1()
            };
            var simpleClass2 = new SimpleClass1();

            var bindingInfo = new BindingInfo
            {
                BindingMode = BindingMode.OneWay,
                SourcePath  = nameof(simpleClass1.Child) + "." + LastName,
                Source      = simpleClass1,
                Target      = simpleClass2,
                TargetPath  = LastName
            };

            bindingInfo.Connect();

            simpleClass1.Child.LastName = "Alex0";

            MustEqual("Alex0", simpleClass2.LastName);
        }
        void FieldBindingTest()
        {
            var model = new SimpleClass1
            {
                Child = new SimpleClass1
                {
                    BeginDate = DateTime.Today
                }
            };

            var template = "<div>" +
                           "    <field>" +
                           "        <DatePicker  Value='{Child.BeginDate}' />" +
                           "	</field>"+
                           "</div>";

            var ui = BuildAndGetFirstLogicalChild(template, model);

            var field      = (Field)ui.GetLogicalChildAt(0);
            var datePicker = (DatePicker)field.GetLogicalChildAt(0);

            Assert.True(datePicker.Value.HasValue);

            Assert.True(datePicker.Value == DateTime.Today);


            model.Child.BeginDate = DateTime.Today.AddDays(-1);

            Assert.True(datePicker.Value == DateTime.Today.AddDays(-1));


            datePicker.Value = DateTime.Today.AddDays(2);


            Assert.True(model.Child.BeginDate == DateTime.Today.AddDays(2));
        }
Esempio n. 13
0
        public void BindingInBag()
        {
            var simpleClass1 = new SimpleClass1();
            var bag          = new Bag();

            var bindingInfo = new BindingInfo
            {
                BindingMode = BindingMode.TwoWay,
                SourcePath  = LastName,
                Source      = simpleClass1,
                Target      = bag,
                TargetPath  = LastName
            };

            bindingInfo.Connect();

            simpleClass1.LastName = "Alex1";

            MustEqual("Alex1", (string)bag[LastName]);

            bag[LastName] = "Alex3";

            MustEqual("Alex3", simpleClass1.LastName);
        }
        void VisualTreeTest_TemplateControl()
        {
            var model = new SimpleClass1
            {
                LastName = "X",
                Child    = new SimpleClass1
                {
                    LastName = "Y",

                    Child = new SimpleClass1
                    {
                        LastName = "Z"
                    }
                }
            };

            var xml = "<div class='A' >" +
                      "     <div class='B' />" +
                      "     <div class='C' />" +
                      "     <div class='D' />" +
                      "</div>";
            var template = Template.CreateFromXml(xml);

            UIBuilder.Register("x_r_t_t_6", () =>
            {
                var fe = new HtmlElement();

                UIBuilder.BuildControlTemplate(template, fe);

                MustEqual(1, fe.VisualChilderenCount);
                MustEqual(3, fe.GetVisualChildAt(0).VisualChilderenCount);

                MustEqual("B", fe.GetVisualChildAt(0, 0).Attr("class"));
                MustEqual("C", fe.GetVisualChildAt(0, 1).Attr("class"));
                MustEqual("D", fe.GetVisualChildAt(0, 2).Attr("class"));

                return(fe);
            });

            var containerElement = new HtmlElement
            {
                DataContext = model
            };

            UIBuilder.LoadComponent(containerElement, "<x_r_t_t_6> " +
                                    "   <s class='sf'/>" +
                                    "</x_r_t_t_6>");

            var containerElementAsHtmlString = containerElement._el.AsHtmlString();

            MustEqual(
                "<div>" +
                "<div class='A'>" +
                "<div class='B'></div>" +
                "<div class='C'></div>" +
                "<div class='D'></div>" +
                "<s class='sf'></s>" +
                "</div>" +
                "</div>"
                , containerElementAsHtmlString);

            containerElement = new HtmlElement
            {
                DataContext = model
            };

            UIBuilder.LoadComponent(containerElement, "<div>" +
                                    "   <div> " +
                                    "       <x_r_t_t_6>  " +
                                    "           <s class='sf'/>  " +
                                    "       </x_r_t_t_6>  " +
                                    "   </div>" +
                                    "</div>");

            containerElementAsHtmlString = containerElement._el.AsHtmlString();

            MustEqual(
                "<div>" +
                "<div>" +
                "<div>" +
                "<div class='A'>" +
                "<div class='B'></div>" +
                "<div class='C'></div>" +
                "<div class='D'></div>" +
                "<s class='sf'></s>" +
                "</div>" +
                "</div>" +
                "</div>" +
                "</div>"
                , containerElementAsHtmlString);
        }