示例#1
0
        public void BindRobotToComputer_SetComputer()
        {
            string failure       = null;
            bool   computerFirst = false;

            ComputerConverter.ConstructorFunc = () => {
                computerFirst = true;
            };
            RobotConverter.ConstructorFunc = () => {
                if (!computerFirst)
                {
                    failure = failure ?? "#1";
                }
            };
            ComputerConverter.CanConvertFromFunc = (context, type) => {
                if (typeof(Robot) != type)
                {
                    failure = failure ?? "#2";
                }
            };
            ComputerConverter.CanConvertToFunc = (context, type) => {
                if (typeof(Robot) != type)
                {
                    failure = failure ?? "#3";
                }
            };
            ComputerConverter.ConvertFromFunc = (context, culture, value) => {
                if (!(value is Robot))
                {
                    failure = failure ?? "#4";
                }
            };

            var h = new Hybrid();

            BindingOperations.SetBinding(h, Hybrid.ComputerProperty, new Binding("Robot")
            {
                Source = h, Mode = BindingMode.TwoWay
            });
            h.Computer = new Computer {
                Name = "A"
            };

            if (failure != null)
            {
                Assert.Fail(failure);
            }

            Assert.IsNotNull(h.Robot, "#5");
            Assert.AreEqual("A", h.Robot.Name, "#6");
        }
示例#2
0
        public void BindComputerToRobot_SetRobot()
        {
            string failure = null;

            RobotConverter.ConstructorFunc = () => {
                failure = failure ?? "#1";
            };
            ComputerConverter.CanConvertFromFunc = (context, type) => {
                if (typeof(Robot) != type)
                {
                    failure = failure ?? "#2";
                }
            };
            ComputerConverter.CanConvertToFunc = (context, type) => {
                if (typeof(Robot) != type)
                {
                    failure = failure ?? "#3";
                }
            };
            ComputerConverter.ConvertToFunc = (context, culture, value, type) => {
                if (!(value is Computer))
                {
                    failure = failure ?? "#4";
                }

                if (typeof(Robot) != type)
                {
                    failure = failure ?? "#5";
                }
            };

            var h = new Hybrid();

            BindingOperations.SetBinding(h, Hybrid.RobotProperty, new Binding("Computer")
            {
                Source = h
            });
            h.Computer = new Computer {
                Name = "A"
            };

            if (failure != null)
            {
                Assert.Fail(failure);
            }

            Assert.IsNotNull(h.Robot, "#1");
            Assert.AreEqual("A", h.Robot.Name, "#2");
        }
示例#3
0
		public void BindRobotToComputer_SetComputer ()
		{
			string failure = null;
			bool computerFirst = false;
			ComputerConverter.ConstructorFunc = () => {
				computerFirst = true;
			};
			RobotConverter.ConstructorFunc = () => {
				if (!computerFirst)
					failure = failure ?? "#1";
			};
			ComputerConverter.CanConvertFromFunc = (context, type) => {
				if (typeof (Robot) != type)
					failure = failure ?? "#2";
			};
			ComputerConverter.CanConvertToFunc = (context, type) => {
				if (typeof (Robot) != type)
					failure = failure ?? "#3";
			};
			ComputerConverter.ConvertFromFunc = (context, culture, value) => {
				if (!(value is Robot))
					failure = failure ?? "#4";
			};

			var h = new Hybrid ();
			BindingOperations.SetBinding (h, Hybrid.ComputerProperty, new Binding ("Robot") { Source = h, Mode = BindingMode.TwoWay });
			h.Computer = new Computer { Name = "A" };

			if (failure != null)
				Assert.Fail (failure);

			Assert.IsNotNull (h.Robot, "#5");
			Assert.AreEqual ("A", h.Robot.Name, "#6");
		}
示例#4
0
		public void BindComputerToRobot_SetRobot ()
		{
			string failure = null;
			RobotConverter.ConstructorFunc = () => {
				failure = failure ?? "#1";
			};
			ComputerConverter.CanConvertFromFunc = (context, type) => {
				if (typeof (Robot) != type)
					failure = failure ?? "#2";
			};
			ComputerConverter.CanConvertToFunc = (context, type) => {
				if (typeof (Robot) != type)
					failure = failure ?? "#3";
			};
			ComputerConverter.ConvertToFunc = (context, culture, value, type) => {
				if (!(value is Computer))
					failure = failure ?? "#4";

				if (typeof (Robot) != type)
					failure = failure ?? "#5";
			};

			var h = new Hybrid ();
			BindingOperations.SetBinding (h, Hybrid.RobotProperty, new Binding ("Computer") { Source = h });
			h.Computer = new Computer { Name = "A" };

			if (failure != null)
				Assert.Fail (failure);

			Assert.IsNotNull (h.Robot, "#1");
			Assert.AreEqual ("A", h.Robot.Name, "#2");
		}