public void Test_03_Clear()
		{
			IActionPropertySet actionProps = GetTestPropertySet();
			ActionPropertyController controller = new ActionPropertyController();

			TextBox edPassword = new TextBox();
			CheckBox cbConvert = new CheckBox();

			IActionProperty propConvert1 = actionProps["Convert"];
			IActionProperty propPassword1 = actionProps["Password"];

			controller.Associate(cbConvert, propConvert1);
			controller.Associate(edPassword, propPassword1);

			edPassword.Text = "Hello";
			Assert.AreEqual("Hello", Convert.ToString(propPassword1.Value), "Should be linked at this stage");
			cbConvert.Checked = false;
			Assert.IsFalse(Convert.ToBoolean(propConvert1.Value), "Should be linked at this stage");

			controller.Clear();

			edPassword.Text = "Excellent";
			Assert.AreEqual("Hello", Convert.ToString(propPassword1.Value), "After Clear() these should no longer be linked");
			cbConvert.Checked = true;
			Assert.IsFalse(Convert.ToBoolean(propConvert1.Value), "After Clear() these should no longer be linked");
		}
		public void Test_02_LinkPropertyToAction_Text()
		{
			IActionPropertySet actionProps = GetTestPropertySet();
			ActionPropertyController controller = new ActionPropertyController();

			TextBox edPassword = new TextBox();
			edPassword.Text = "Rubbish";
			IActionProperty propPassword = actionProps["Password"];
			Assert.AreEqual("", Convert.ToString(propPassword.Value), "This Mock should be \"\" on creation");

			controller.Associate(edPassword, propPassword);
			Assert.AreEqual("", edPassword.Text, "Should initialize immediately on connection");
			Assert.AreEqual("", Convert.ToString(propPassword.Value), "Should initialize immediately on connection");
			edPassword.Text = "Hello";
			Assert.AreEqual("Hello", Convert.ToString(propPassword.Value), "The property seems not to be reference by the UI!");
			edPassword.Text = "";
			Assert.AreEqual("", Convert.ToString(propPassword.Value), "The property seems not to be reference by the UI!");
		}
		public void Test_01_LinkPropertyToAction_Bool()
		{
			IActionPropertySet actionProps = GetTestPropertySet();
			ActionPropertyController controller = new ActionPropertyController();
			
			CheckBox cbConvert = new CheckBox();
			Assert.IsFalse(cbConvert.Checked, "Just created it");
			IActionProperty propConvert = actionProps["Convert"];
			Assert.IsTrue(Convert.ToBoolean(propConvert.Value), "This Mock should be true on creation");

			controller.Associate(cbConvert, propConvert);
			Assert.IsTrue(cbConvert.Checked, "Should initialize immediately on connection");
			Assert.IsTrue(Convert.ToBoolean(propConvert.Value), "Should initialize immediately on connection");
			cbConvert.Checked = false;
			Assert.IsFalse(Convert.ToBoolean(propConvert.Value), "The property seems not to be reference by the UI!");
			cbConvert.Checked = true;
			Assert.IsTrue(Convert.ToBoolean(propConvert.Value), "The property seems not to be reference by the UI!");
		}
		public void Test_04_AssociateValidator()
		{
			IActionPropertySet actionProps = GetTestPropertySet();
			ActionPropertyController controller = new ActionPropertyController();

			TextBox edPassword = new TextBox();
			TextBox edValidator = new TextBox();

			IActionProperty propPassword1 = actionProps["Password"];

			controller.Associate(edPassword, propPassword1);
			controller.AssociateValidator(edValidator, propPassword1);

			Assert.AreEqual("", edPassword.Text, "The password is not set to start with");
			Assert.AreEqual("", edValidator.Text, "The password is not set to start with");

			edPassword.Text = "Hello";

			Assert.AreEqual("Hello", edPassword.Text, "The password is set but not validated");
			Assert.AreEqual("", edValidator.Text, "The password is set but not validated");
			Assert.AreEqual("", Convert.ToString(propPassword1.Value), "The password is set but not validated");

			edValidator.Text = "Hello";
			Assert.AreEqual("Hello", edPassword.Text, "The password is now validated");
			Assert.AreEqual("Hello", edValidator.Text, "The password is now validated");
			Assert.AreEqual("Hello", Convert.ToString(propPassword1.Value), "The password is now validated");

			edPassword.Text = "Hello2";
			Assert.AreEqual("Hello2", edPassword.Text, "The password has been invalidated");
			Assert.AreEqual("Hello", edValidator.Text, "The password has been invalidated");
			Assert.AreEqual("", Convert.ToString(propPassword1.Value), "The password has been invalidated");

			edValidator.Text = "Hello2";
			Assert.AreEqual("Hello2", edPassword.Text, "The password has been re-validated");
			Assert.AreEqual("Hello2", edValidator.Text, "The password has been re-validated");
			Assert.AreEqual("Hello2", Convert.ToString(propPassword1.Value), "The password has been re-validated");
		}
        public void Test_10_LinkPropertyToAction_Text()
        {
            IActionPropertySet actionProps = GetTestPropertySet();
            ActionPropertyController controller = new ActionPropertyController();

            LabeledTextBox ledCustProps = new LabeledTextBox();
            ledCustProps.Text = "CustProp";
            IActionProperty propCustom = actionProps["CustomProperties"];
            Assert.AreEqual("", Convert.ToString(propCustom.Value), "This Mock should be \"\" on creation");

            controller.Associate(ledCustProps, propCustom);
            Assert.AreEqual("", ledCustProps.Text, "Should initialize immediately on connection");
            Assert.AreEqual("", Convert.ToString(propCustom.Value), "Should initialize immediately on connection");
            ledCustProps.Text = "Another";
            Assert.AreEqual("Another", Convert.ToString(propCustom.Value), "The property seems not to be reference by the UI!");
            ledCustProps.Text = "";
            Assert.AreEqual("", Convert.ToString(propCustom.Value), "The property seems not to be reference by the UI!");
        }
        public void Test_09_LinkPropertyToAction_Bool()
        {
            IActionPropertySet actionProps = GetTestPropertySet();
            ActionPropertyController controller = new ActionPropertyController();

            LinkCheckBox lcbExclude = new LinkCheckBox();
            Assert.IsFalse(lcbExclude.Checked, "Just created it");
            IActionProperty propExclude = actionProps["ExcludeStuff"];
            Assert.IsTrue(Convert.ToBoolean(propExclude.Value), "This Mock should be true on creation");

            controller.Associate(lcbExclude, propExclude);
            Assert.IsTrue(lcbExclude.Checked, "Should initialize immediately on connection");
            Assert.IsTrue(Convert.ToBoolean(propExclude.Value), "Should initialize immediately on connection");
            lcbExclude.Checked = false;
            Assert.IsFalse(Convert.ToBoolean(propExclude.Value), "The property seems not to be reference by the UI!");
            lcbExclude.Checked = true;
            Assert.IsTrue(Convert.ToBoolean(propExclude.Value), "The property seems not to be reference by the UI!");
        }
        public void Test_08_Associate_NonSupportedControl()
        {
            MockActionProperty prop =
                new MockActionProperty("SomeProperty", typeof(bool), PropertyDisplayType.Checkbox, true,
                                       true);

            ActionPropertyController controller = new ActionPropertyController();
            Button button = new Button();
            bool bCatch = false;
            try
            {
                controller.Associate( button, prop);    
            }
            catch(Exception)
            {
                bCatch = true;
            }

            Assert.IsTrue(bCatch, "Expected to catch an exception when passing in an unsuitable control.");
            bCatch = false;

            try
            {
                controller.AssociateValidator(button, prop);
            }
            catch (Exception)
            {
                bCatch = true;
            }
            Assert.IsTrue(bCatch, "Expected to catch an exception when passing in an unsuitable control.");

        }
        public void Test_07_Associate_NonOverridableProperty()
        {
            MockActionProperty prop =
                new MockActionProperty("IAmNotOverridableByTheUser", typeof (bool), PropertyDisplayType.Checkbox, true,
                                       true);

            prop.Override = false;

            CheckBox checkBox = new CheckBox();
            checkBox.Enabled = true;

            ActionPropertyController controller = new ActionPropertyController();
            controller.Associate(checkBox, prop);
            Assert.IsFalse( checkBox.Enabled, "If the property is read-only it is not overridable, so the checkbox should be disabled.");

            
            controller = new ActionPropertyController();
            TextBox validationControl = new TextBox();
            checkBox.Enabled = true;
            controller.AssociateValidator(validationControl, prop);
            Assert.IsFalse(validationControl.Enabled, "If the property is read-only it is not overridable, so the checkbox should be disabled.");
        }
        public void Test_06_ApplyToAll_TextControl()
        {
            ApplyToAllHandler handler = new ApplyToAllHandler();
            IActionPropertySet actionProps = GetTestPropertySet();

            ActionPropertyController controller = new ActionPropertyController();
            controller.ApplyToAll += handler.HandleApplyToAll;

            TextBox txtPassword = new TextBox();
            IActionProperty pwdProp = actionProps["Password"];
            controller.Associate(txtPassword, pwdProp);
            txtPassword.Text = "Blue";

            CheckBox cbApply_All = new CheckBox();
            cbApply_All.Checked = false;
            IActionProperty applyProp = actionProps[ActionPropertyController.APPLY_TO_ALL];
            controller.Associate(cbApply_All, applyProp);

            Assert.AreEqual("Blue", pwdProp.Value, "Initially we expect the property value to be false.");
            txtPassword.Text = "Red";
            Assert.AreEqual("Red", pwdProp.Value, "After checking the box, we expect the value to be true.");
            Assert.AreEqual(0, handler.ApplyToAllHandled, "Do not expect to have raised the apply all event yet.");

            cbApply_All.Checked = true;
            Assert.AreEqual(0, handler.ApplyToAllHandled);

            controller.AssociateApplyToAll(applyProp);
            txtPassword.Text = "Blue";
            Assert.AreEqual(1, handler.ApplyToAllHandled);

            cbApply_All.Checked = false; //make the property value false.
            txtPassword.Text = "Red";
            Assert.AreEqual(1, handler.ApplyToAllHandled);

            cbApply_All.Checked = true;
            Assert.AreEqual(2, handler.ApplyToAllHandled);

            controller.AssociateApplyToAll(null);
            txtPassword.Text = "Blue";
            Assert.AreEqual(2, handler.ApplyToAllHandled);
        }
        public void Test_05_ApplyToAll_CheckBoxControl()
        {
            ApplyToAllHandler handler = new ApplyToAllHandler();
            IActionPropertySet actionProps = GetTestPropertySet();

            ActionPropertyController controller = new ActionPropertyController();
            controller.ApplyToAll += handler.HandleApplyToAll;

            CheckBox cbConvert = new CheckBox();
            IActionProperty convertProp = actionProps["Convert"];
            controller.Associate(cbConvert,convertProp);
            cbConvert.Checked = false;

            CheckBox cbApply_All = new CheckBox();
            cbApply_All.Checked = false;
            IActionProperty applyProp = actionProps[ActionPropertyController.APPLY_TO_ALL];
            controller.Associate(cbApply_All, applyProp);

            Assert.AreEqual(false,(bool)convertProp.Value, "Initially we expect the property value to be false.");
            cbConvert.Checked = true;
            Assert.AreEqual(true, (bool)convertProp.Value, "After checking the box, we expect the value to be true.");
            Assert.AreEqual(0, handler.ApplyToAllHandled, "Do not expect to have raised the apply all event yet.");

            cbApply_All.Checked = true;
            Assert.AreEqual(0, handler.ApplyToAllHandled);

            controller.AssociateApplyToAll(applyProp);
            cbConvert.Checked = false;
            Assert.AreEqual(1, handler.ApplyToAllHandled);

            cbApply_All.Checked = false; //make the property value false.
            cbConvert.Checked = true;
            Assert.AreEqual(1, handler.ApplyToAllHandled);

            cbApply_All.Checked = true;
            Assert.AreEqual(2, handler.ApplyToAllHandled);

            controller.AssociateApplyToAll(null);
            cbConvert.Checked = false;
            Assert.AreEqual(2, handler.ApplyToAllHandled);
        }