Ejemplo n.º 1
0
        public void IntContainerToConvertedDP_ConverterOnIntClass_SetNullOnDestination()
        {
            // If the destination is set to null on a two-way binding we don't invoke the type converter
            var source = new IntPropClassConverterContainer {
                Value = new IntPropClassConverter {
                    IntProperty = 5
                }
            };
            var target = new ConvertedObjectDPNoConverter {
            };

            HookedConverter.ConvertFromFunc = (descriptor, culture, value) =>
            {
                Assert.Fail("Should not be invoked");
                return(null);
            };
            HookedConverter.ConvertToFunc = (descriptor, culture, value, type) =>
            {
                Assert.IsInstanceOfType <IntPropClassConverter>(value, "#3");
                Assert.AreEqual(typeof(ConvertedObject), type, "#4");
                return(new ConvertedObject {
                    Value = ((IntPropClassConverter)value).IntProperty
                });
            };

            BindingOperations.SetBinding(target, ConvertedObjectDPNoConverter.ConvertedObjectProperty, new Binding("Value")
            {
                Mode = BindingMode.TwoWay, Source = source
            });

            target.ConvertedObject = null;
            Assert.AreEqual(null, source.Value, "#1");
        }
Ejemplo n.º 2
0
        public void IntContainerToConvertedDP_ConverterOnIntClass()
        {
            // The field Value of type 'IntPropClassConverter' has a class level type converter, so we use that
            var source = new IntPropClassConverterContainer {
                Value = new IntPropClassConverter {
                    IntProperty = 5
                }
            };
            var target = new ConvertedObjectDPNoConverter {
            };

            HookedConverter.CanConvertFromFunc = (descriptor, type) => {
                Assert.AreEqual(typeof(ConvertedObject), type, "#1");
                return(true);
            };
            HookedConverter.CanConvertToFunc = (descriptor, type) => {
                Assert.AreEqual(typeof(ConvertedObject), type, "#2");
                return(true);
            };
            HookedConverter.ConvertFromFunc = (descriptor, culture, value) => {
                Assert.IsInstanceOfType <ConvertedObject>(value, "#3");
                return(new IntPropClassConverter {
                    IntProperty = (int)((ConvertedObject)value).Value
                });
            };
            HookedConverter.ConvertToFunc = (descriptor, culture, value, type) => {
                Assert.IsInstanceOfType <IntPropClassConverter>(value, "#3");
                Assert.AreEqual(typeof(ConvertedObject), type, "#4");
                return(new ConvertedObject {
                    Value = ((IntPropClassConverter)value).IntProperty
                });
            };

            BindingOperations.SetBinding(target, ConvertedObjectDPNoConverter.ConvertedObjectProperty, new Binding("Value")
            {
                Mode = BindingMode.TwoWay, Source = source
            });
            Assert.AreEqual(5, target.ConvertedObject.Value, "#5");

            target.ConvertedObject = new ConvertedObject {
                Value = 6
            };
            Assert.AreEqual(6, source.Value.IntProperty, "#6");
        }
Ejemplo n.º 3
0
        public void IntContainerToConvertedDP_ConverterOnIntClass_NullInitialSource()
        {
            // If the source is initially null, we set null on the target without invoking the converter.
            // We don't even create one.
            var source = new IntPropClassConverterContainer {
                Value = null
            };
            var target = new ConvertedObjectDPNoConverter {
                ConvertedObject = new ConvertedObject()
            };

            HookedConverter.ConstructorFunc = () => Assert.Fail("Not invoked", "#ctor");

            BindingOperations.SetBinding(target, ConvertedObjectDPNoConverter.ConvertedObjectProperty, new Binding("Value")
            {
                Mode = BindingMode.TwoWay, Source = source
            });
            Assert.AreEqual(null, target.ConvertedObject, "#1");
        }
Ejemplo n.º 4
0
		public void IntContainerToConvertedDP_ConverterOnIntClass_SetNullOnDestination()
		{
			// If the destination is set to null on a two-way binding we don't invoke the type converter
			var source = new IntPropClassConverterContainer { Value = new IntPropClassConverter { IntProperty = 5 } };
			var target = new ConvertedObjectDPNoConverter { };

			HookedConverter.ConvertFromFunc = (descriptor, culture, value) =>
			{
				Assert.Fail ("Should not be invoked");
				return null;
			};
			HookedConverter.ConvertToFunc = (descriptor, culture, value, type) =>
			{
				Assert.IsInstanceOfType<IntPropClassConverter>(value, "#3");
				Assert.AreEqual(typeof(ConvertedObject), type, "#4");
				return new ConvertedObject { Value = ((IntPropClassConverter)value).IntProperty };
			};

			BindingOperations.SetBinding(target, ConvertedObjectDPNoConverter.ConvertedObjectProperty, new Binding("Value") { Mode = BindingMode.TwoWay, Source = source });

			target.ConvertedObject = null;
			Assert.AreEqual(null, source.Value, "#1");
		}
Ejemplo n.º 5
0
		public void IntContainerToConvertedDP_ConverterOnIntClass_NullInitialSource()
		{
			// If the source is initially null, we set null on the target without invoking the converter.
			// We don't even create one.
			var source = new IntPropClassConverterContainer { Value = null };
			var target = new ConvertedObjectDPNoConverter { ConvertedObject = new ConvertedObject() };

			HookedConverter.ConstructorFunc = () => Assert.Fail("Not invoked", "#ctor");

			BindingOperations.SetBinding(target, ConvertedObjectDPNoConverter.ConvertedObjectProperty, new Binding("Value") { Mode = BindingMode.TwoWay, Source = source });
			Assert.AreEqual(null, target.ConvertedObject, "#1");
		}
Ejemplo n.º 6
0
		public void IntContainerToConvertedDP_ConverterOnIntClass()
		{
			// The field Value of type 'IntPropClassConverter' has a class level type converter, so we use that
			var source = new IntPropClassConverterContainer { Value = new IntPropClassConverter { IntProperty = 5 } };
			var target = new ConvertedObjectDPNoConverter { };

			HookedConverter.CanConvertFromFunc = (descriptor, type) => {
				Assert.AreEqual (typeof(ConvertedObject), type, "#1");
				return true;
			};
			HookedConverter.CanConvertToFunc = (descriptor, type) => {
				Assert.AreEqual (typeof (ConvertedObject), type, "#2");
				return true;
			};
			HookedConverter.ConvertFromFunc = (descriptor, culture, value) => {
				Assert.IsInstanceOfType<ConvertedObject>(value, "#3");
				return new IntPropClassConverter { IntProperty = (int) ((ConvertedObject)value).Value };
			};
			HookedConverter.ConvertToFunc = (descriptor, culture, value, type) => {
				Assert.IsInstanceOfType<IntPropClassConverter>(value, "#3");
				Assert.AreEqual(typeof (ConvertedObject), type, "#4");
				return new ConvertedObject { Value = ((IntPropClassConverter)value).IntProperty };
			};

			BindingOperations.SetBinding(target, ConvertedObjectDPNoConverter.ConvertedObjectProperty, new Binding("Value") { Mode = BindingMode.TwoWay, Source = source });
			Assert.AreEqual(5, target.ConvertedObject.Value, "#5");

			target.ConvertedObject = new ConvertedObject { Value = 6 };
			Assert.AreEqual(6, source.Value.IntProperty, "#6");
		}