public void ChildBindingWithNameShouldUpdateProperly()
        {
            var item    = new BindObject();
            var binding = Eto.Forms.Binding.Property <int>("ChildBindObject.IntProperty");

            int changed = 0;

            binding.AddValueChangedHandler(item, (sender, e) => changed++);

            BindObject oldChild;

            item.ChildBindObject = oldChild = new BindObject();
            Assert.AreEqual(1, changed);
            Assert.AreEqual(0, binding.GetValue(item));

            item.ChildBindObject.IntProperty = 2;
            Assert.AreEqual(2, changed);
            Assert.AreEqual(2, binding.GetValue(item));

            item.ChildBindObject = new BindObject {
                IntProperty = 3
            };
            Assert.AreEqual(3, changed);
            Assert.AreEqual(3, binding.GetValue(item));

            oldChild.IntProperty = 4;             // we should not be hooked into change events of the old child, since we have a new one now!
            Assert.AreEqual(3, changed);
            Assert.AreEqual(3, binding.GetValue(item));
        }
Exemple #2
0
        public void DoublePropertyShouldUpdate()
        {
            var bindObject = new BindObject {
                DoubleProperty = 0
            };
            var binding = new ObjectBinding <double>(bindObject, "DoubleProperty");

            Assert.AreEqual(binding.DataValue, bindObject.DoubleProperty, "Data value should equal object value");
            binding.DataValue = 1.2;
            Assert.AreEqual(binding.DataValue, bindObject.DoubleProperty, "Data value should equal object value");
        }
Exemple #3
0
        public void IntPropertyShouldUpdate()
        {
            var bindObject = new BindObject {
                IntProperty = 0
            };
            var binding = new ObjectBinding <int>(bindObject, "IntProperty");

            Assert.AreEqual(binding.DataValue, bindObject.IntProperty, "Data value should equal object value");
            binding.DataValue = 1;
            Assert.AreEqual(binding.DataValue, bindObject.IntProperty, "Data value should equal object value");
        }
Exemple #4
0
        public void StringPropertyShouldUpdate()
        {
            var bindObject = new BindObject {
                StringProperty = "Initial Value"
            };
            var binding = new ObjectBinding <string>(bindObject, "StringProperty");

            Assert.AreEqual(binding.DataValue, bindObject.StringProperty, "Data value should equal object value");
            binding.DataValue = "Other Value";
            Assert.AreEqual(binding.DataValue, bindObject.StringProperty, "Data value should equal object value");
            binding.DataValue = null;
            Assert.AreEqual(binding.DataValue, bindObject.StringProperty, "Data value should equal object value");
        }
Exemple #5
0
        public void BoolPropertyShouldUpdate()
        {
            var bindObject = new BindObject {
                BoolProperty = true
            };
            var binding = new ObjectBinding <bool>(bindObject, "BoolProperty");

            Assert.AreEqual(binding.DataValue, bindObject.BoolProperty, "Data value should equal object value");
            binding.DataValue = false;
            Assert.AreEqual(binding.DataValue, bindObject.BoolProperty, "Data value should equal object value");
            binding.DataValue = true;
            Assert.AreEqual(binding.DataValue, bindObject.BoolProperty, "Data value should equal object value");
        }
        public void NonExistantPropertyShouldNotCrash()
        {
            var item    = new BindObject();
            var binding = Eto.Forms.Binding.Property <int?>("SomePropertyThatDoesntExist");

            int changed = 0;
            EventHandler <EventArgs> valueChanged = (sender, e) => changed++;
            var changeReference = binding.AddValueChangedHandler(item, valueChanged);

            Assert.AreEqual(0, changed);
            Assert.AreEqual(null, binding.GetValue(item));
            Assert.DoesNotThrow(() => binding.SetValue(item, 123));
            binding.RemoveValueChangedHandler(changeReference, valueChanged);
        }
        public void InternalPropertyShouldBeAccessible()
        {
            var item = new BindObject {
                InternalStringProperty = "some value"
            };
            var binding = Eto.Forms.Binding.Property <string>("InternalStringProperty");

            int changed = 0;
            EventHandler <EventArgs> valueChanged = (sender, e) => changed++;
            var changeReference = binding.AddValueChangedHandler(item, valueChanged);

            Assert.AreEqual(0, changed);
            Assert.AreEqual("some value", binding.GetValue(item));
            Assert.DoesNotThrow(() => binding.SetValue(item, "some other value"));
            Assert.AreEqual(1, changed);
            Assert.AreEqual("some other value", binding.GetValue(item));
            binding.RemoveValueChangedHandler(changeReference, valueChanged);
        }
        public void BindingWithNameShouldUpdateProperly()
        {
            var item    = new BindObject();
            var binding = Eto.Forms.Binding.Property <int>("IntProperty");

            int changed = 0;

            binding.AddValueChangedHandler(item, (sender, e) => changed++);

            Assert.AreEqual(0, changed);
            Assert.AreEqual(0, binding.GetValue(item));

            item.IntProperty = 2;
            Assert.AreEqual(1, changed);
            Assert.AreEqual(2, binding.GetValue(item));

            item.IntProperty = 4;
            Assert.AreEqual(2, changed);
            Assert.AreEqual(4, binding.GetValue(item));
        }