Esempio n. 1
0
        public void Set2WayBindingsWithUpdateSourceEventInBindingObject()
        {
            var platformView = new MockPlatformView();

            Assert.AreEqual(null, platformView.Baz);

            var vm = new MockVMForPlatformBinding();

            platformView.SetBindingContext(vm);

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

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

            vm.FFoo = "foo";
            Assert.AreEqual("foo", platformView.Baz);
            Assert.AreEqual("foo", vm.FFoo);
        }
Esempio n. 2
0
        public void Set2WayBindings()
        {
            var platformView = new MockPlatformView();

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

            var vm = new MockVMForPlatformBinding();

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

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

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

            vm.FFoo = "foo";
            vm.BBar = 42;
            Assert.AreEqual("foo", platformView.Foo);
            Assert.AreEqual(42, platformView.Bar);
            Assert.AreEqual("foo", vm.FFoo);
            Assert.AreEqual(42, vm.BBar);
        }
Esempio n. 3
0
        public void TestConverterDoesNotThrow()
        {
            var platformView = new MockPlatformView();

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

            platformView.SetBinding("SelectedColor", new Binding("CColor", converter: converter));
            Assert.DoesNotThrow(() => platformView.SetBindingContext(vm));
        }
Esempio n. 4
0
        public void OneWayToSourceAppliedOnSetBC()
        {
            var platformView = new MockPlatformView {
                Foo = "foobar"
            };

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

            platformView.SetBindingContext(vm);
            Assert.AreEqual("foobar", vm.FFoo);
        }
Esempio n. 5
0
        public void TestConverterWorks()
        {
            var platformView = new MockPlatformView();

            Assert.AreEqual(null, platformView.Foo);
            Assert.AreEqual(0, platformView.Bar);
            var vm = new MockVMForPlatformBinding();

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

            platformView.SetBinding("SelectedColor", new Binding("CColor", converter: converter));
            platformView.SetBindingContext(vm);
            Assert.AreEqual(vm.CColor, platformView.SelectedColor.FormsColor);
        }
Esempio n. 6
0
        public void Binding2WayWithConvertersDoNotLoop()
        {
            var platformView = new MockPlatformView();
            int count        = 0;

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

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

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

            Assert.AreEqual(count, 1);
        }
Esempio n. 7
0
        public void SetBindingContextToSubviews()
        {
            var platformView = new MockPlatformView {
                SubViews = new List <MockPlatformView>()
            };
            var platformViewChild = new MockPlatformView();

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

            platformView.SubViews.Add(platformViewChild);

            var vm = new MockVMForPlatformBinding();

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

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

            platformView.SetBindingContext(new { FFoo = "Foo", BBar = 42 }, v => v.SubViews);
            Assert.AreEqual("Foo", platformViewChild.Foo);
            Assert.AreEqual(42, platformViewChild.Bar);
        }
Esempio n. 8
0
        public void TestConverter2WayWorks()
        {
            var platformView = new MockPlatformView();

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

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

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

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

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

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