public void DataContainerBase_SetBinding_MustBindOneWay()
        {
            const string PROP_NAME = "IntProperty";
            const int    VALUE     = 42;
            const int    NEW_VALUE = 14;

            IPropertyContainer pc = PropertyContainerBuilder.Create()
                                    .Property(PROP_NAME, VALUE)
                                    .Build();

            var bindingTarget = new BindingTestObject();

            Assert.NotEqual(VALUE, bindingTarget.IntProperty);

            pc.SetBinding(PROP_NAME, () => bindingTarget.IntProperty, BindingMode.OneWay);

            Assert.Equal(VALUE, bindingTarget.IntProperty);

            pc.SetValue(PROP_NAME, NEW_VALUE);

            Assert.Equal(NEW_VALUE, bindingTarget.IntProperty);

            bindingTarget.IntProperty = 32;

            int propertyValue = 0;

            pc.GetValue(PROP_NAME, ref propertyValue);

            pc.RemoveBinding(PROP_NAME, () => bindingTarget.IntProperty);

            Assert.NotEqual(32, propertyValue);
            Assert.Equal(NEW_VALUE, propertyValue);
        }
Example #2
0
        public void IDataContainer_ObjectDataObjectRaisesPropertyChangedWhenCLRObjectChanges()
        {
            BindingTestObject obj = new BindingTestObject();

            IDataContainer A = DataContainerBuilder.Create("A")
                               .Data("Obj1", obj, SerializationFormat.Container)
                               .Data("Obj2", obj, SerializationFormat.Xml)
                               .Data("Obj3", obj, SerializationFormat.Json)
                               .Build();

            var listener = new PropertyChangedListener(A);

            obj.IntProperty = 44;

            Assert.Contains("Obj1", listener.PropertiesChanged);
            Assert.Contains("Obj2", listener.PropertiesChanged);
            Assert.Contains("Obj3", listener.PropertiesChanged);
            Assert.Equal("Obj3", listener.LastChangedProperty);
        }