This is a mapper class that handles the mapping of a property name to a specific property for a specified IBusinessObject. The property name can be specified as a path through single relationships on the IBusinessObject and its' relationship tree. For Example:
For the ContactPerson BusinessObject when the propertyName is "FirstName", the returned IBOProp will be the "FirstName" property on ContactPerson.
If the propertyName was "Organisation.Name" then the Organisation relationship on the contact person will be traversed and monitored and return the corresponding "Name" IBOProp for the ContactPerson's current Organisation.
Inheritance: IBOPropertyMapper
 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);
 }
Beispiel #2
0
 ///<summary>
 /// Creates a BOPropertyMapper for the specified property name/path.
 ///</summary>
 ///<param name="propertyName">The name of the property to be mapped (this could also be in the form of a path through single relationships on the BO).</param>
 ///<exception cref="ArgumentNullException">This is thrown if <paramref name="propertyName"/> is null or empty.</exception>
 public BOPropertyMapper(string propertyName)
 {
     if (String.IsNullOrEmpty(propertyName))
     {
         throw new ArgumentNullException("propertyName");
     }
     PropertyName = propertyName;
     if (PropertyName.Contains(RELATIONSHIP_SEPARATOR))
     {
         string[] parts            = PropertyName.Split('.');
         string   relationshipPath = String.Join(RELATIONSHIP_SEPARATOR, parts, 0, parts.Length - 1);
         _relationshipPathMapper = new BORelationshipMapper(relationshipPath);
         string childPropertyName = parts[parts.Length - 1];
         _childBoPropertyMapper = new BOPropertyMapper(childPropertyName);
         _childBoPropertyMapper.PropertyChanged += (sender, e) => FirePropertyChanged();
     }
 }
        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_GetPropertyValue_ShouldSetBOPropsValue()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
            const string propName = "Surname";
            BOPropertyMapper boPropertyMapper = new BOPropertyMapper(propName) { BusinessObject = contactPersonTestBO };
            var expectedPropValue = RandomValueGen.GetRandomString();
            boPropertyMapper.Property.Value = expectedPropValue;
            //---------------Assert Precondition----------------
            Assert.IsNotNull(boPropertyMapper.Property);
            Assert.AreEqual(expectedPropValue, boPropertyMapper.Property.Value);
            //---------------Execute Test ----------------------

            object actualValue = boPropertyMapper.GetPropertyValue();
            //---------------Test Result -----------------------
            Assert.AreEqual(expectedPropValue, actualValue);
            Assert.AreEqual(expectedPropValue, contactPersonTestBO.Surname);
        }
        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_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_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);
 }
 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_BusinessObject_WhenSetToNull_HavingPropertyOnRelatedBO_ShouldReturnNullProperty()
 {
     //---------------Set up test pack-------------------
     const string innerPropertyName = "Name";
     const string propertyName = "Organisation." + innerPropertyName;
     BOPropertyMapper boPropertyMapper = new BOPropertyMapper(propertyName);
     ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO{Organisation = new OrganisationTestBO()};
     boPropertyMapper.BusinessObject = contactPersonTestBO;
     //---------------Assert Precondition----------------
     Assert.IsNotNull(boPropertyMapper.BusinessObject);
     Assert.IsNotNull(boPropertyMapper.Property);
     Assert.IsNotNull(contactPersonTestBO.Organisation);
     //---------------Execute Test ----------------------
     boPropertyMapper.BusinessObject = null;
     //---------------Test Result -----------------------
     Assert.IsNull(boPropertyMapper.BusinessObject);
     Assert.IsNull(boPropertyMapper.Property);
 }
 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_WhenSetToNull_ShouldFirePropertyChangedEvent()
 {
     //---------------Set up test pack-------------------
     ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
     const string propertyName = "FirstName";
     BOPropertyMapper boPropertyMapper = new BOPropertyMapper(propertyName);
     boPropertyMapper.BusinessObject = contactPersonTestBO;
     bool eventFired = false;
     boPropertyMapper.PropertyChanged += (sender, e) => eventFired = true;
     //---------------Assert Precondition----------------
     Assert.IsNotNull(boPropertyMapper.BusinessObject);
     Assert.IsNotNull(boPropertyMapper.Property);
     Assert.IsFalse(eventFired);
     //---------------Execute Test ----------------------
     boPropertyMapper.BusinessObject = null;
     //---------------Test Result -----------------------
     Assert.IsNull(boPropertyMapper.BusinessObject);
     Assert.IsNull(boPropertyMapper.Property);
     Assert.IsTrue(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_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_ChangeRelatedBO_WhenSetToNull_HavingPropertyOnRelatedBO_ShouldChangePropertyToNull()
 {
     //---------------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;
     //---------------Assert Precondition----------------
     Assert.AreSame(contactPersonTestBO, boPropertyMapper.BusinessObject);
     Assert.AreSame(oldOrganisationTestBO.Props[innerPropertyName], boPropertyMapper.Property);
     //---------------Execute Test ----------------------
     contactPersonTestBO.Organisation = null;
     //---------------Test Result -----------------------
     Assert.AreSame(contactPersonTestBO, boPropertyMapper.BusinessObject);
     Assert.IsNull(boPropertyMapper.Property);
 }
Beispiel #17
0
 ///<summary>
 /// Creates a BOPropertyMapper for the specified property name/path.
 ///</summary>
 ///<param name="propertyName">The name of the property to be mapped (this could also be in the form of a path through single relationships on the BO).</param>
 ///<exception cref="ArgumentNullException">This is thrown if <paramref name="propertyName"/> is null or empty.</exception>
 public BOPropertyMapper(string propertyName)
 {
     if (String.IsNullOrEmpty(propertyName)) throw new ArgumentNullException("propertyName");
     PropertyName = propertyName;
     if (PropertyName.Contains(RELATIONSHIP_SEPARATOR))
     {
         string[] parts = PropertyName.Split('.');
         string relationshipPath = String.Join(RELATIONSHIP_SEPARATOR, parts, 0, parts.Length - 1);
         _relationshipPathMapper = new BORelationshipMapper(relationshipPath);
         string childPropertyName = parts[parts.Length - 1];
         _childBoPropertyMapper = new BOPropertyMapper(childPropertyName);
         _childBoPropertyMapper.PropertyChanged += (sender, e) => FirePropertyChanged();
     }
 }
 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);
 }