public void Test_BusinessObject_WhenSetWithBONotHavingSpecifiedProperty_ShouldNotFirePropertyChangedEvent()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
            const string        propertyName        = "SomeNonExistentProperty";
            BOPropertyMapper    boPropertyMapper    = new BOPropertyMapper(propertyName);
            bool eventFired = false;

            boPropertyMapper.PropertyChanged += (sender, e) => eventFired = true;
            //---------------Assert Precondition----------------
            Assert.IsNull(boPropertyMapper.BusinessObject);
            Assert.IsNull(boPropertyMapper.Property);
            Assert.IsFalse(eventFired);
            //---------------Execute Test ----------------------
            try
            {
                boPropertyMapper.BusinessObject = contactPersonTestBO;
                Assert.Fail("Expected to throw an Exception");
            }
            //---------------Test Result -----------------------
            catch (Exception)
            {
                Assert.IsNull(boPropertyMapper.BusinessObject);
                Assert.IsNull(boPropertyMapper.Property);
                Assert.IsFalse(eventFired);
            }
        }
        public void Test_BusinessObject_WhenSetWithBONotHavingSpecifiedProperty_ShouldThrowError()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
            const string        propertyName        = "SomeNonExistentProperty";
            BOPropertyMapper    boPropertyMapper    = new BOPropertyMapper(propertyName);

            //---------------Assert Precondition----------------
            Assert.IsNull(boPropertyMapper.BusinessObject);
            Assert.IsNull(boPropertyMapper.Property);
            //---------------Execute Test ----------------------
            try
            {
                boPropertyMapper.BusinessObject = contactPersonTestBO;
                Assert.Fail("Expected to throw a HabaneroDeveloperException");
            }
            //---------------Test Result -----------------------
            catch (InvalidPropertyException ex)
            {
                StringAssert.Contains("The property '" + propertyName + "' on '"
                                      + contactPersonTestBO.ClassDef.ClassName + "' cannot be found. Please contact your system administrator.", ex.Message);

/*                StringAssert.Contains("The property '" + propertyName + "' does not exist on the BusinessObject '"
 + contactPersonTestBO.ClassDef.ClassNameFull + "'", ex.DeveloperMessage);*/
                Assert.IsNull(boPropertyMapper.BusinessObject);
                Assert.IsNull(boPropertyMapper.Property);
            }
        }
        public void Test_BusinessObject_WhenSet_HavingExistingNonSingleRelationshipOnRelatedBO_ShouldThrowError()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            AddressTestBO.LoadDefaultClassDef();
            IClassDef           contactPersonClassDef = ContactPersonTestBO.LoadClassDefWithAddressesRelationship_DeleteRelated();
            ContactPersonTestBO contactPersonTestBO   = new ContactPersonTestBO();
            const string        outerRelationshipName = "Addresses";
            const string        innerPropertyName     = "ContactPersonTestBO";
            string           propertyName             = outerRelationshipName + _relationshipPathSeperator + innerPropertyName;
            BOPropertyMapper boPropertyMapper         = new BOPropertyMapper(propertyName);

            //---------------Assert Precondition----------------
            Assert.IsNull(boPropertyMapper.BusinessObject);
            Assert.IsNull(boPropertyMapper.Property);
            //---------------Execute Test ----------------------
            try
            {
                boPropertyMapper.BusinessObject = contactPersonTestBO;
                Assert.Fail("Expected to throw a HabaneroDeveloperException");
            }
            //---------------Test Result -----------------------
            catch (RelationshipNotFoundException ex)
            {
                StringAssert.Contains("The relationship '" + outerRelationshipName + "' on '"
                                      + contactPersonClassDef.ClassName + "' is not a Single Relationship. Please contact your system administrator.", ex.Message);

/*
 *              StringAssert.Contains("The relationship '" + outerRelationshipName + "' on the BusinessObject '"
 + contactPersonClassDef.ClassNameFull + "' is not a Single Relationship therefore cannot be traversed.", ex.DeveloperMessage);
 */
                Assert.IsNull(boPropertyMapper.BusinessObject);
                Assert.IsNull(boPropertyMapper.Property);
            }
        }
        public void Test_BusinessObject_WhenSet_HavingNonExistingChildRelationshipForRelatedBo_ShouldThrowError()
        {
            //---------------Set up test pack-------------------
            IClassDef           contactPersonClassDef = ClassDef.Get <ContactPersonTestBO>();
            ContactPersonTestBO contactPersonTestBO   = new ContactPersonTestBO();

            contactPersonTestBO.Organisation = new OrganisationTestBO();
            const string     outerRelationshipName = "NonExistingRelationship";
            const string     innerPropertyName     = "Name";
            string           propertyName          = outerRelationshipName + _relationshipPathSeperator + innerPropertyName;
            BOPropertyMapper boPropertyMapper      = new BOPropertyMapper(propertyName);

            //---------------Assert Precondition----------------
            Assert.IsNull(boPropertyMapper.BusinessObject);
            Assert.IsNull(boPropertyMapper.Property);
            //---------------Execute Test ----------------------
            try
            {
                boPropertyMapper.BusinessObject = contactPersonTestBO;
                Assert.Fail("Expected to throw a HabaneroDeveloperException");
            }
            //---------------Test Result -----------------------
            catch (RelationshipNotFoundException ex)
            {
                StringAssert.Contains("The relationship '" + outerRelationshipName + "' on '"
                                      + contactPersonClassDef.ClassName + "' cannot be found. Please contact your system administrator.", ex.Message);

/*                StringAssert.Contains("The relationship '" + outerRelationshipName + "' does not exist on the BusinessObject '"
 + contactPersonClassDef.ClassNameFull + "'", ex.DeveloperMessage);*/
                Assert.IsNull(boPropertyMapper.BusinessObject);
                Assert.IsNull(boPropertyMapper.Property);
            }
        }
        public void Test_Construct()
        {
            //---------------Set up test pack-------------------
            string propertyName = TestUtil.GetRandomString();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            BOPropertyMapper boPropertyMapper = new BOPropertyMapper(propertyName);

            //---------------Test Result -----------------------
            Assert.AreEqual(propertyName, boPropertyMapper.PropertyName);
            Assert.IsNull(boPropertyMapper.BusinessObject);
            Assert.IsNull(boPropertyMapper.Property);
        }
        public void AssertFakeBONameMappedToTextBox_WhenPropNameNotAPropOfBO_ShouldReturnFalseTest()
        {
            //---------------Set up test pack-------------------

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var boPropertyMapper = new BOPropertyMapper("fdafads");

//            boPropertyMapper.
            //---------------Test Result -----------------------
            Assert.Fail("Test Not Yet Implemented");
        }
        public void Test_BusinessObject_GetAndSet()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
            const string        propertyName        = "FirstName";
            BOPropertyMapper    boPropertyMapper    = new BOPropertyMapper(propertyName);

            //---------------Assert Precondition----------------
            Assert.IsNull(boPropertyMapper.BusinessObject);
            //---------------Execute Test ----------------------
            boPropertyMapper.BusinessObject = contactPersonTestBO;
            //---------------Test Result -----------------------
            Assert.AreSame(contactPersonTestBO, boPropertyMapper.BusinessObject);
        }
        private void AssertPropValueIsFromList(IBusinessObject randomFakeBO, string propName, IList <string> nameList)
        {
            BOPropertyMapper propertyMapper = new BOPropertyMapper(propName)
            {
                BusinessObject = randomFakeBO
            };
            string propertyValue = propertyMapper.GetPropertyValue() as string;
            var    message       = string.Format("The property '{0}' value '{1}' should be from the list of available names",
                                                 propName, propertyValue);

            Assert.IsTrue(nameList.Contains(propertyValue), message);

            //Assert.IsFalse(parsed, message);
        }
        public void Test_BusinessObject_WhenSetWithBOHavingSpecifiedProperty_ShouldReturnCorrectProperty()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
            const string        propertyName        = "FirstName";
            BOPropertyMapper    boPropertyMapper    = new BOPropertyMapper(propertyName);

            //---------------Assert Precondition----------------
            Assert.IsNull(boPropertyMapper.BusinessObject);
            Assert.IsNull(boPropertyMapper.Property);
            //---------------Execute Test ----------------------
            boPropertyMapper.BusinessObject = contactPersonTestBO;
            //---------------Test Result -----------------------
            Assert.AreSame(contactPersonTestBO, boPropertyMapper.BusinessObject);
            Assert.AreSame(contactPersonTestBO.Props[propertyName], boPropertyMapper.Property);
        }
        public void Test_BusinessObject_WhenSetToNull_ShouldReturnNullProperty()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
            const string        propertyName        = "FirstName";
            BOPropertyMapper    boPropertyMapper    = new BOPropertyMapper(propertyName);

            boPropertyMapper.BusinessObject = contactPersonTestBO;
            //---------------Assert Precondition----------------
            Assert.IsNotNull(boPropertyMapper.BusinessObject);
            Assert.IsNotNull(boPropertyMapper.Property);
            //---------------Execute Test ----------------------
            boPropertyMapper.BusinessObject = null;
            //---------------Test Result -----------------------
            Assert.IsNull(boPropertyMapper.BusinessObject);
            Assert.IsNull(boPropertyMapper.Property);
        }
        public void Test_BusinessObject_WhenSet_HavingPropertyOnRelatedBO_ShouldReturnRelatedBOsProperty()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();

            contactPersonTestBO.Organisation = new OrganisationTestBO();
            const string     innerPropertyName = "Name";
            const string     propertyName      = "Organisation." + innerPropertyName;
            BOPropertyMapper boPropertyMapper  = new BOPropertyMapper(propertyName);

            //---------------Assert Precondition----------------
            Assert.IsNull(boPropertyMapper.BusinessObject);
            Assert.IsNull(boPropertyMapper.Property);
            //---------------Execute Test ----------------------
            boPropertyMapper.BusinessObject = contactPersonTestBO;
            //---------------Test Result -----------------------
            Assert.AreSame(contactPersonTestBO, boPropertyMapper.BusinessObject);
            Assert.AreSame(contactPersonTestBO.Organisation.Props[innerPropertyName], boPropertyMapper.Property);
        }
        public void Test_BusinessObject_WhenSetWithBOHavingSpecifiedProperty_ShouldFirePropertyChangedEvent()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
            const string        propertyName        = "FirstName";
            BOPropertyMapper    boPropertyMapper    = new BOPropertyMapper(propertyName);
            bool eventFired = false;

            boPropertyMapper.PropertyChanged += (sender, e) => eventFired = true;
            //---------------Assert Precondition----------------
            Assert.IsNull(boPropertyMapper.BusinessObject);
            Assert.IsNull(boPropertyMapper.Property);
            Assert.IsFalse(eventFired);
            //---------------Execute Test ----------------------
            boPropertyMapper.BusinessObject = contactPersonTestBO;
            //---------------Test Result -----------------------
            Assert.AreSame(contactPersonTestBO, boPropertyMapper.BusinessObject);
            Assert.AreSame(contactPersonTestBO.Props[propertyName], boPropertyMapper.Property);
            Assert.IsTrue(eventFired);
        }
        public void Test_SetPropertyValue_ShouldSetBOPropsValue()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
            const string        propName            = "Surname";
            BOPropertyMapper    boPropertyMapper    = new BOPropertyMapper(propName)
            {
                BusinessObject = contactPersonTestBO
            };

            //---------------Assert Precondition----------------
            Assert.IsNotNull(boPropertyMapper.Property);
            Assert.IsNull(boPropertyMapper.Property.Value);
            //---------------Execute Test ----------------------
            var expectedPropValue = RandomValueGen.GetRandomString();

            boPropertyMapper.SetPropertyValue(expectedPropValue);
            //---------------Test Result -----------------------
            Assert.AreEqual(expectedPropValue, boPropertyMapper.Property.Value);
            Assert.AreEqual(expectedPropValue, contactPersonTestBO.Surname);
        }
        public void Test_SetPropertyDisplayValue_WithIntString_ShouldBeAbleGetString()
        {
            //---------------Set up test pack-------------------

            ClassDef.ClassDefs.Clear();
            MyBO.LoadDefaultClassDef();
            const string propName = "TestProp";
            var          testBo   = new MyBO();
            var          boMapper = new BOPropertyMapper(propName)
            {
                BusinessObject = testBo
            };

            boMapper.SetPropertyValue("7");
            //---------------Assert Precondition----------------
            Assert.AreEqual("7", boMapper.GetPropertyValue().ToString());
            //---------------Execute Test ----------------------
            boMapper.SetPropertyValue("3");
            //---------------Test Result -----------------------
            Assert.AreEqual("3", boMapper.GetPropertyValue().ToString());
            Assert.AreEqual("3", testBo.TestProp);
        }
        public void Test_GetPropertyValue_WhenBONull_ShouldRaiseError()
        {
            //---------------Set up test pack-------------------
            const string     propName         = "Surname";
            BOPropertyMapper boPropertyMapper = new BOPropertyMapper(propName);

            //---------------Assert Precondition----------------
            Assert.IsNull(boPropertyMapper.BusinessObject);
            //---------------Execute Test ----------------------
            try
            {
                boPropertyMapper.GetPropertyValue();
                Assert.Fail("Expected to throw an HabaneroApplicationException");
            }
            //---------------Test Result -----------------------
            catch (HabaneroApplicationException ex)
            {
                string expectedErrorMessage = string.Format(
                    "Tried to GetPropertyValue the BOPropertyMapper for Property '{0}' when the BusinessObject is not set "
                    , propName);
                StringAssert.Contains(expectedErrorMessage, ex.Message);
            }
        }
        public void Test_ChangeRelatedBO_WhenSetToDifferentBo_HavingPropertyOnRelatedBO_ShouldChangeProperty()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO contactPersonTestBO   = new ContactPersonTestBO();
            OrganisationTestBO  oldOrganisationTestBO = new OrganisationTestBO();

            contactPersonTestBO.Organisation = oldOrganisationTestBO;
            const string     innerPropertyName = "Name";
            const string     propertyName      = "Organisation." + innerPropertyName;
            BOPropertyMapper boPropertyMapper  = new BOPropertyMapper(propertyName);

            boPropertyMapper.BusinessObject = contactPersonTestBO;
            OrganisationTestBO newOrganisationTestBO = new OrganisationTestBO();

            //---------------Assert Precondition----------------
            Assert.AreSame(contactPersonTestBO, boPropertyMapper.BusinessObject);
            Assert.AreSame(oldOrganisationTestBO.Props[innerPropertyName], boPropertyMapper.Property);
            //---------------Execute Test ----------------------
            contactPersonTestBO.Organisation = newOrganisationTestBO;
            //---------------Test Result -----------------------
            Assert.AreSame(contactPersonTestBO, boPropertyMapper.BusinessObject);
            Assert.AreSame(newOrganisationTestBO.Props[innerPropertyName], boPropertyMapper.Property);
        }
        public void Test_BusinessObject_WhenSet_HavingPropertyOnRelatedBO_ShouldFirePropertyChangeEvent()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();

            contactPersonTestBO.Organisation = new OrganisationTestBO();
            const string     innerPropertyName = "Name";
            const string     propertyName      = "Organisation." + innerPropertyName;
            BOPropertyMapper boPropertyMapper  = new BOPropertyMapper(propertyName);
            bool             eventFired        = false;

            boPropertyMapper.PropertyChanged += (sender, e) => eventFired = true;
            //---------------Assert Precondition----------------
            Assert.IsNull(boPropertyMapper.BusinessObject);
            Assert.IsNull(boPropertyMapper.Property);
            Assert.IsFalse(eventFired);
            //---------------Execute Test ----------------------
            boPropertyMapper.BusinessObject = contactPersonTestBO;
            //---------------Test Result -----------------------
            Assert.AreSame(contactPersonTestBO, boPropertyMapper.BusinessObject);
            Assert.AreSame(contactPersonTestBO.Organisation.Props[innerPropertyName], boPropertyMapper.Property);
            Assert.IsTrue(eventFired);
        }
        public void Test_ChangeRelatedBO_WhenSetToDifferentBo_HavingPropertyOnRelatedBO_ShouldFirePropertyChangedEvent()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO contactPersonTestBO   = new ContactPersonTestBO();
            OrganisationTestBO  oldOrganisationTestBO = new OrganisationTestBO();

            contactPersonTestBO.Organisation = oldOrganisationTestBO;
            const string     innerPropertyName = "Name";
            const string     propertyName      = "Organisation." + innerPropertyName;
            BOPropertyMapper boPropertyMapper  = new BOPropertyMapper(propertyName)
            {
                BusinessObject = contactPersonTestBO
            };
            OrganisationTestBO newOrganisationTestBO = new OrganisationTestBO();
            bool eventFired = false;

            boPropertyMapper.PropertyChanged += (sender, e) => eventFired = true;
            //---------------Assert Precondition----------------
            Assert.IsFalse(eventFired);
            //---------------Execute Test ----------------------
            contactPersonTestBO.Organisation = newOrganisationTestBO;
            //---------------Test Result -----------------------
            Assert.IsTrue(eventFired);
        }