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); }
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 = Color.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 = Color.Blue; var newColor = new MockNativeColor(newFormsColor); nativeView.SelectedColor = newColor; inpc.FireINPC(nativeView, nameof(nativeView.SelectedColor)); Assert.AreEqual(newFormsColor, vm.CColor); }