Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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));
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }