示例#1
0
        public void Set2WayBindingsWithUpdateSourceEventInBindingObject()
        {
            var nativeView = new MockNativeView();

            Assert.AreEqual(null, nativeView.Baz);

            var vm = new MockVMForNativeBinding();

            nativeView.SetBindingContext(vm);

            nativeView.SetBinding("Baz", new Binding("FFoo", mode: BindingMode.TwoWay)
            {
                UpdateSourceEventName = "BazChanged"
            });
            Assert.AreEqual(null, nativeView.Baz);
            Assert.AreEqual(null, vm.FFoo);

            nativeView.Baz = "oof";
            nativeView.FireBazChanged();
            Assert.AreEqual("oof", nativeView.Baz);
            Assert.AreEqual("oof", vm.FFoo);

            vm.FFoo = "foo";
            Assert.AreEqual("foo", nativeView.Baz);
            Assert.AreEqual("foo", vm.FFoo);
        }
示例#2
0
        public void Set2WayBindings()
        {
            var nativeView = new MockNativeView();

            Assert.AreEqual(null, nativeView.Foo);
            Assert.AreEqual(0, nativeView.Bar);

            var vm = new MockVMForNativeBinding();

            nativeView.SetBindingContext(vm);
            var inpc = new MockINPC();

            nativeView.SetBinding("Foo", new Binding("FFoo", mode: BindingMode.TwoWay), inpc);
            nativeView.SetBinding("Bar", new Binding("BBar", mode: BindingMode.TwoWay), inpc);
            Assert.AreEqual(null, nativeView.Foo);
            Assert.AreEqual(0, nativeView.Bar);
            Assert.AreEqual(null, vm.FFoo);
            Assert.AreEqual(0, vm.BBar);

            nativeView.Foo = "oof";
            inpc.FireINPC(nativeView, "Foo");
            nativeView.Bar = -42;
            inpc.FireINPC(nativeView, "Bar");
            Assert.AreEqual("oof", nativeView.Foo);
            Assert.AreEqual(-42, nativeView.Bar);
            Assert.AreEqual("oof", vm.FFoo);
            Assert.AreEqual(-42, vm.BBar);

            vm.FFoo = "foo";
            vm.BBar = 42;
            Assert.AreEqual("foo", nativeView.Foo);
            Assert.AreEqual(42, nativeView.Bar);
            Assert.AreEqual("foo", vm.FFoo);
            Assert.AreEqual(42, vm.BBar);
        }
示例#3
0
        public void TestConverterDoesNotThrow()
        {
            var nativeView = new MockNativeView();

            Assert.AreEqual(null, nativeView.Foo);
            Assert.AreEqual(0, nativeView.Bar);
            var vm        = new MockVMForNativeBinding();
            var converter = new MockCustomColorConverter();

            nativeView.SetBinding("SelectedColor", new Binding("CColor", converter: converter));
            Assert.DoesNotThrow(() => nativeView.SetBindingContext(vm));
        }
示例#4
0
        public void OneWayToSourceAppliedOnSetBC()
        {
            var nativeView = new MockNativeView {
                Foo = "foobar"
            };

            nativeView.SetBinding("Foo", new Binding("FFoo", BindingMode.OneWayToSource));
            var vm = new MockVMForNativeBinding {
                FFoo = "qux"
            };

            nativeView.SetBindingContext(vm);
            Assert.AreEqual("foobar", vm.FFoo);
        }
示例#5
0
        public void TestConverterWorks()
        {
            var nativeView = new MockNativeView();

            Assert.AreEqual(null, nativeView.Foo);
            Assert.AreEqual(0, nativeView.Bar);
            var vm = new MockVMForNativeBinding();

            vm.CColor = Colors.Red;
            var converter = new MockCustomColorConverter();

            nativeView.SetBinding("SelectedColor", new Binding("CColor", converter: converter));
            nativeView.SetBindingContext(vm);
            Assert.AreEqual(vm.CColor, nativeView.SelectedColor.FormsColor);
        }
示例#6
0
        public void Binding2WayWithConvertersDoNotLoop()
        {
            var nativeView = new MockNativeView();
            int count      = 0;

            nativeView.SelectedColorChanged += (o, e) =>
            {
                if (++count > 5)
                {
                    Assert.Fail("Probable loop detected");
                }
            };

            var vm = new MockVMForNativeBinding {
                CColor = Colors.Red
            };

            nativeView.SetBinding("SelectedColor", new Binding("CColor", BindingMode.TwoWay, new MockCustomColorConverter()), "SelectedColorChanged");
            nativeView.SetBindingContext(vm);

            Assert.AreEqual(count, 1);
        }
示例#7
0
        public void SetBindingContextToSubviews()
        {
            var nativeView = new MockNativeView {
                SubViews = new List <MockNativeView>()
            };
            var nativeViewChild = new MockNativeView();

            nativeViewChild.SetBinding("Foo", new Binding("FFoo", mode: BindingMode.OneWay));
            nativeViewChild.SetBinding("Bar", new Binding("BBar", mode: BindingMode.OneWay));

            nativeView.SubViews.Add(nativeViewChild);

            var vm = new MockVMForNativeBinding();

            nativeView.SetBindingContext(vm, v => v.SubViews);

            Assert.AreEqual(null, nativeViewChild.Foo);
            Assert.AreEqual(0, nativeViewChild.Bar);

            nativeView.SetBindingContext(new { FFoo = "Foo", BBar = 42 }, v => v.SubViews);
            Assert.AreEqual("Foo", nativeViewChild.Foo);
            Assert.AreEqual(42, nativeViewChild.Bar);
        }
示例#8
0
        public void TestConverter2WayWorks()
        {
            var nativeView = new MockNativeView();

            Assert.AreEqual(null, nativeView.Foo);
            Assert.AreEqual(0, nativeView.Bar);
            var inpc = new MockINPC();
            var vm   = new MockVMForNativeBinding();

            vm.CColor = Colors.Red;
            var converter = new MockCustomColorConverter();

            nativeView.SetBinding("SelectedColor", new Binding("CColor", BindingMode.TwoWay, converter), inpc);
            nativeView.SetBindingContext(vm);
            Assert.AreEqual(vm.CColor, nativeView.SelectedColor.FormsColor);

            var newFormsColor = Colors.Blue;
            var newColor      = new MockNativeColor(newFormsColor);

            nativeView.SelectedColor = newColor;
            inpc.FireINPC(nativeView, nameof(nativeView.SelectedColor));

            Assert.AreEqual(newFormsColor, vm.CColor);
        }