Exemple #1
0
        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));
        }
		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");
			bindObject.DoubleProperty = 1.2;
			Assert.AreEqual(binding.DataValue, bindObject.DoubleProperty, "Data value should equal object value");
		}
		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");
			bindObject.IntProperty = 1;
			Assert.AreEqual(binding.DataValue, bindObject.IntProperty, "Data value should equal object value");
		}
		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");
			bindObject.StringProperty = "Other Value";
			Assert.AreEqual(binding.DataValue, bindObject.StringProperty, "Data value should equal object value");
			bindObject.StringProperty = null;
			Assert.AreEqual(binding.DataValue, bindObject.StringProperty, "Data value should equal object value");
		}
		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");
			bindObject.BoolProperty = false;
			Assert.AreEqual(binding.DataValue, bindObject.BoolProperty, "Data value should equal object value");
			bindObject.BoolProperty = true;
			Assert.AreEqual(binding.DataValue, bindObject.BoolProperty, "Data value should equal object value");
		}
Exemple #6
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");
            bindObject.DoubleProperty = 1.2;
            Assert.AreEqual(binding.DataValue, bindObject.DoubleProperty, "Data value should equal object value");
        }
Exemple #7
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");
            bindObject.IntProperty = 1;
            Assert.AreEqual(binding.DataValue, bindObject.IntProperty, "Data value should equal object value");
        }
Exemple #8
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");
            bindObject.BoolProperty = false;
            Assert.AreEqual(binding.DataValue, bindObject.BoolProperty, "Data value should equal object value");
            bindObject.BoolProperty = true;
            Assert.AreEqual(binding.DataValue, bindObject.BoolProperty, "Data value should equal object value");
        }
Exemple #9
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");
            bindObject.StringProperty = "Other Value";
            Assert.AreEqual(binding.DataValue, bindObject.StringProperty, "Data value should equal object value");
            bindObject.StringProperty = null;
            Assert.AreEqual(binding.DataValue, bindObject.StringProperty, "Data value should equal object value");
        }
Exemple #10
0
        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);
        }
Exemple #11
0
        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));
        }