public void Test_Construct()
 {
     //---------------Set up test pack-------------------
     string relationshipName = TestUtil.GetRandomString();
     //---------------Assert Precondition----------------
     //---------------Execute Test ----------------------
     BORelationshipMapper boRelationshipMapper = new BORelationshipMapper(relationshipName);
     //---------------Test Result -----------------------
     Assert.AreEqual(relationshipName, boRelationshipMapper.RelationshipName);
     Assert.IsNull(boRelationshipMapper.BusinessObject);
     Assert.IsNull(boRelationshipMapper.Relationship);
 }       
 ///<summary>
 /// Creates a BORelationshipMapper for the specified relationship name/path.
 ///</summary>
 ///<param name="relationshipName">The name of the relationship 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="relationshipName"/> is null or empty.</exception>
 public BORelationshipMapper(string relationshipName)
 {
     if (String.IsNullOrEmpty(relationshipName)) throw new ArgumentNullException("relationshipName");
     RelationshipName = relationshipName;
     if (RelationshipName.Contains("."))
     {
         string[] parts = RelationshipName.Split('.');
         string localRelationshipName = parts[0];
         _localBoRelationshipMapper = new BORelationshipMapper(localRelationshipName);
         string remainingPath = String.Join(".", parts, 1, parts.Length - 1);
         _childBoRelationshipMapper = new BORelationshipMapper(remainingPath);
         _childBoRelationshipMapper.RelationshipChanged += (sender, e) => FireRelationshipChanged();
     }
 }
Exemple #3
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();
     }
 }
Exemple #4
0
 ///<summary>
 /// Creates a BORelationshipMapper for the specified relationship name/path.
 ///</summary>
 ///<param name="relationshipName">The name of the relationship 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="relationshipName"/> is null or empty.</exception>
 public BORelationshipMapper(string relationshipName)
 {
     if (String.IsNullOrEmpty(relationshipName))
     {
         throw new ArgumentNullException("relationshipName");
     }
     RelationshipName = relationshipName;
     if (RelationshipName.Contains("."))
     {
         string[] parts = RelationshipName.Split('.');
         string   localRelationshipName = parts[0];
         _localBoRelationshipMapper = new BORelationshipMapper(localRelationshipName);
         string remainingPath = String.Join(".", parts, 1, parts.Length - 1);
         _childBoRelationshipMapper = new BORelationshipMapper(remainingPath);
         _childBoRelationshipMapper.RelationshipChanged += (sender, e) => FireRelationshipChanged();
     }
 }
 public void Test_BusinessObject_GetAndSet()
 {
     //---------------Set up test pack-------------------
     ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
     const string relationshipName = "Organisation";
     BORelationshipMapper boRelationshipMapper = new BORelationshipMapper(relationshipName);
     //---------------Assert Precondition----------------
     Assert.IsNull(boRelationshipMapper.BusinessObject);
     //---------------Execute Test ----------------------
     boRelationshipMapper.BusinessObject = contactPersonTestBO;
     //---------------Test Result -----------------------
     Assert.AreSame(contactPersonTestBO, boRelationshipMapper.BusinessObject);
 }
 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 innerRelationshipName = "ContactPersonTestBO";
     const string outerRelationshipName = "Addresses";
     const string relationshipName = outerRelationshipName + "." + innerRelationshipName;
     BORelationshipMapper boRelationshipMapper = new BORelationshipMapper(relationshipName);
     //---------------Assert Precondition----------------
     Assert.IsNull(boRelationshipMapper.BusinessObject);
     Assert.IsNull(boRelationshipMapper.Relationship);
     //---------------Execute Test ----------------------
     try
     {
         boRelationshipMapper.BusinessObject = contactPersonTestBO;
         Assert.Fail("Expected to throw a HabaneroDeveloperException");
     }
     //---------------Test Result -----------------------
     catch (HabaneroDeveloperException 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(boRelationshipMapper.BusinessObject);
         Assert.IsNull(boRelationshipMapper.Relationship);
     }
 }
        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 innerRelationshipName = "Addresses";
            const string outerRelationshipName = "NonExistingRelationship";
            const string relationshipName = outerRelationshipName + "." + innerRelationshipName;
            BORelationshipMapper boRelationshipMapper = new BORelationshipMapper(relationshipName);
            //---------------Assert Precondition----------------
            Assert.IsNull(boRelationshipMapper.BusinessObject);
            Assert.IsNull(boRelationshipMapper.Relationship);
            //---------------Execute Test ----------------------
            try
            {
                boRelationshipMapper.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(boRelationshipMapper.BusinessObject);
                Assert.IsNull(boRelationshipMapper.Relationship);
            }
        }
 public void Test_ChangeRelatedBO_WhenSetToNull_HavingRelationshipOnRelatedBO_ShouldChangeRelationshipToNull()
 {
     //---------------Set up test pack-------------------
     ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
     OrganisationTestBO oldOrganisationTestBO = new OrganisationTestBO();
     contactPersonTestBO.Organisation = oldOrganisationTestBO;
     const string innerRelationshipName = "ContactPeople";
     const string relationshipName = "Organisation." + innerRelationshipName;
     BORelationshipMapper boRelationshipMapper = new BORelationshipMapper(relationshipName);
     boRelationshipMapper.BusinessObject = contactPersonTestBO;
     //---------------Assert Precondition----------------
     Assert.AreSame(contactPersonTestBO, boRelationshipMapper.BusinessObject);
     Assert.AreSame(oldOrganisationTestBO.Relationships[innerRelationshipName], boRelationshipMapper.Relationship);
     //---------------Execute Test ----------------------
     contactPersonTestBO.Organisation = null;
     //---------------Test Result -----------------------
     Assert.AreSame(contactPersonTestBO, boRelationshipMapper.BusinessObject);
     Assert.IsNull(boRelationshipMapper.Relationship);
 }
 public void Test_BusinessObject_WhenSetToNull_HavingRelationshipOnRelatedBO_ShouldReturnNullRelationship()
 {
     //---------------Set up test pack-------------------
     const string innerRelationshipName = "ContactPeople";
     const string relationshipName = "Organisation." + innerRelationshipName;
     BORelationshipMapper boRelationshipMapper = new BORelationshipMapper(relationshipName);
     ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO { Organisation = new OrganisationTestBO() };
     boRelationshipMapper.BusinessObject = contactPersonTestBO;
     //---------------Assert Precondition----------------
     Assert.IsNotNull(boRelationshipMapper.BusinessObject);
     Assert.IsNotNull(boRelationshipMapper.Relationship);
     Assert.IsNotNull(contactPersonTestBO.Organisation);
     //---------------Execute Test ----------------------
     boRelationshipMapper.BusinessObject = null;
     //---------------Test Result -----------------------
     Assert.IsNull(boRelationshipMapper.BusinessObject);
     Assert.IsNull(boRelationshipMapper.Relationship);
 }
 public void Test_BusinessObject_WhenSetWithBONotHavingSpecifiedRelationship_ShouldNotFireRelationshipChangedEvent()
 {
     //---------------Set up test pack-------------------
     ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
     const string relationshipName = "SomeNonExistentRelationship";
     BORelationshipMapper boRelationshipMapper = new BORelationshipMapper(relationshipName);
     bool eventFired = false;
     boRelationshipMapper.RelationshipChanged += (sender, e) => eventFired = true;
     //---------------Assert Precondition----------------
     Assert.IsNull(boRelationshipMapper.BusinessObject);
     Assert.IsNull(boRelationshipMapper.Relationship);
     Assert.IsFalse(eventFired);
     //---------------Execute Test ----------------------
     try
     {
         boRelationshipMapper.BusinessObject = contactPersonTestBO;
         Assert.Fail("Expected to throw an Exception");
     }
     //---------------Test Result -----------------------
     catch (Exception)
     {
         Assert.IsNull(boRelationshipMapper.BusinessObject);
         Assert.IsNull(boRelationshipMapper.Relationship);
         Assert.IsFalse(eventFired);
     }
 }
 public void Test_BusinessObject_WhenSetToNull_ShouldFireRelationshipChangedEvent()
 {
     //---------------Set up test pack-------------------
     ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
     const string relationshipName = "Organisation";
     BORelationshipMapper boRelationshipMapper = new BORelationshipMapper(relationshipName);
     boRelationshipMapper.BusinessObject = contactPersonTestBO;
     bool eventFired = false;
     boRelationshipMapper.RelationshipChanged += (sender, e) => eventFired = true;
     //---------------Assert Precondition----------------
     Assert.IsNotNull(boRelationshipMapper.BusinessObject);
     Assert.IsNotNull(boRelationshipMapper.Relationship);
     Assert.IsFalse(eventFired);
     //---------------Execute Test ----------------------
     boRelationshipMapper.BusinessObject = null;
     //---------------Test Result -----------------------
     Assert.IsNull(boRelationshipMapper.BusinessObject);
     Assert.IsNull(boRelationshipMapper.Relationship);
     Assert.IsTrue(eventFired);
 }
        public void Test_BusinessObject_WhenSetWithBONotHavingSpecifiedRelationship_ShouldThrowError()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
            const string relationshipName = "SomeNonExistentRelationship";
            BORelationshipMapper boRelationshipMapper = new BORelationshipMapper(relationshipName);
            //---------------Assert Precondition----------------
            Assert.IsNull(boRelationshipMapper.BusinessObject);
            Assert.IsNull(boRelationshipMapper.Relationship);
            //---------------Execute Test ----------------------
            try
            {
                boRelationshipMapper.BusinessObject = contactPersonTestBO;
                Assert.Fail("Expected to throw a HabaneroDeveloperException");
            }
            //---------------Test Result -----------------------
            catch (RelationshipNotFoundException ex)
            {
                StringAssert.Contains("The relationship '" + relationshipName + "' on '"
                     + contactPersonTestBO.ClassDef.ClassName + "' cannot be found. Please contact your system administrator.", ex.Message);
/*                StringAssert.Contains("The relationship '" + relationshipName + "' does not exist on the BusinessObject '"
                     + contactPersonTestBO.ClassDef.ClassNameFull + "'", ex.DeveloperMessage);*/
                Assert.IsNull(boRelationshipMapper.BusinessObject);
                Assert.IsNull(boRelationshipMapper.Relationship);
            }
        }   
 public void Test_BusinessObject_WhenSetToNull_ShouldReturnNullRelationship()
 {
     //---------------Set up test pack-------------------
     ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
     const string relationshipName = "Organisation";
     BORelationshipMapper boRelationshipMapper = new BORelationshipMapper(relationshipName);
     boRelationshipMapper.BusinessObject = contactPersonTestBO;
     //---------------Assert Precondition----------------
     Assert.IsNotNull(boRelationshipMapper.BusinessObject);
     Assert.IsNotNull(boRelationshipMapper.Relationship);
     //---------------Execute Test ----------------------
     boRelationshipMapper.BusinessObject = null;
     //---------------Test Result -----------------------
     Assert.IsNull(boRelationshipMapper.BusinessObject);
     Assert.IsNull(boRelationshipMapper.Relationship);
 }
 public void Test_BusinessObject_WhenSetWithBOHavingSpecifiedRelationship_ShouldReturnCorrectRelationship()
 {
     //---------------Set up test pack-------------------
     ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
     const string relationshipName = "Organisation";
     BORelationshipMapper boRelationshipMapper = new BORelationshipMapper(relationshipName);
     //---------------Assert Precondition----------------
     Assert.IsNull(boRelationshipMapper.BusinessObject);
     Assert.IsNull(boRelationshipMapper.Relationship);
     //---------------Execute Test ----------------------
     boRelationshipMapper.BusinessObject = contactPersonTestBO;
     //---------------Test Result -----------------------
     Assert.AreSame(contactPersonTestBO, boRelationshipMapper.BusinessObject);
     Assert.AreSame(contactPersonTestBO.Relationships[relationshipName], boRelationshipMapper.Relationship);
 }        
 public void Test_ChangeRelatedBO_WhenSetToDifferentBo_HavingRelationshipOnRelatedBO_ShouldFireRelationshipChangedEvent()
 {
     //---------------Set up test pack-------------------
     ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
     OrganisationTestBO oldOrganisationTestBO = new OrganisationTestBO();
     contactPersonTestBO.Organisation = oldOrganisationTestBO;
     const string innerRelationshipName = "ContactPeople";
     const string relationshipName = "Organisation." + innerRelationshipName;
     BORelationshipMapper boRelationshipMapper = new BORelationshipMapper(relationshipName);
     boRelationshipMapper.BusinessObject = contactPersonTestBO;
     OrganisationTestBO newOrganisationTestBO = new OrganisationTestBO();
     bool eventFired = false;
     boRelationshipMapper.RelationshipChanged += (sender, e) => eventFired = true;
     //---------------Assert Precondition----------------
     Assert.IsFalse(eventFired);
     //---------------Execute Test ----------------------
     contactPersonTestBO.Organisation = newOrganisationTestBO;
     //---------------Test Result -----------------------
     Assert.IsTrue(eventFired);
 }
 ///<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();
     }
 }
        /// <summary>
        /// Constructs a <see cref="RelationshipComboBoxMapper"/> with the <paramref name="comboBox"/>
        ///  <paramref name="relationshipName"/>
        /// </summary>
        /// <param name="comboBox">The combo box that is being mapped to</param>
        /// <param name="relationshipName">The name of the relation that is being mapped to</param>
        /// <param name="isReadOnly">Whether the Combo box can be used to edit from or whether it is only viewable</param>
        /// <param name="controlFactory">A control factory that is used to create control mappers etc</param>
        public RelationshipComboBoxMapper
            (IComboBox comboBox, string relationshipName, bool isReadOnly, IControlFactory controlFactory)
        {
            if (comboBox == null) throw new ArgumentNullException("comboBox");
            if (relationshipName == null) throw new ArgumentNullException("relationshipName");
            if (controlFactory == null) throw new ArgumentNullException("controlFactory");

            IsReadOnly = isReadOnly;
            ControlFactory = controlFactory;
            Control = comboBox;
            RelationshipName = relationshipName;
            _boRelationshipMapper = new BORelationshipMapper(relationshipName);
            _boRelationshipMapper.RelationshipChanged += (sender, e) => OnMappedRelationshipChanged();
            
            _mapperStrategy = ControlFactory.CreateLookupComboBoxDefaultMapperStrategy();
            _mapperStrategy.AddHandlers(this);
            UpdateIsEditable();
            _comboBoxCollectionSelector = new ComboBoxCollectionSelector(comboBox, controlFactory, false)
                                              {PreserveSelectedItem = true};
            this.IncludeBlankItem = true;
        }