Пример #1
0
        public void TestCreateRelationship()
        {
            ISingleRelationship rel =
                (ISingleRelationship)mRelationshipDef.CreateRelationship(mMockBo, mMockBo.PropCol);

            Assert.AreEqual(mRelationshipDef.RelationshipName, rel.RelationshipName);
            Assert.IsTrue(mMockBo.GetPropertyValue("MockBOProp1") == null);
            Assert.IsFalse(rel.HasRelatedObject(), "Should be false since props are not defaulted in Mock bo");
            mMockBo.SetPropertyValue("MockBOProp1", mMockBo.GetPropertyValue("MockBOID"));
            mMockBo.Save();
            Assert.IsTrue(rel.HasRelatedObject(), "Should be true since prop MockBOProp1 has been set");

            Assert.AreEqual(mMockBo.GetPropertyValue("MockBOProp1"), mMockBo.GetPropertyValue("MockBOID"));
            MockBO ltempBO = (MockBO)rel.GetRelatedObject();

            Assert.IsFalse(ltempBO == null);
            Assert.AreEqual
                (mMockBo.GetPropertyValue("MockBOID"), ltempBO.GetPropertyValue("MockBOID"),
                "The object returned should be the one with the ID = MockBOID");
            Assert.AreEqual
                (mMockBo.GetPropertyValueString("MockBOProp1"), ltempBO.GetPropertyValueString("MockBOID"),
                "The object returned should be the one with the ID = MockBOID");
            Assert.AreEqual
                (mMockBo.GetPropertyValue("MockBOProp1"), ltempBO.GetPropertyValue("MockBOID"),
                "The object returned should be the one with the ID = MockBOID");
            mMockBo.MarkForDelete();
            mMockBo.Save();
        }
Пример #2
0
        public void TestCreateRelationshipHoldRelRef()
        {
            RelationshipDef mRelationshipDef;
            RelKeyDef       mRelKeyDef;
            MockBO          _mMockBO         = GetMockBO(out mRelationshipDef, out mRelKeyDef);
            RelationshipDef lRelationshipDef = new SingleRelationshipDef("Relation1", typeof(MockBO), mRelKeyDef, true,
                                                                         DeleteParentAction.Prevent);
            ISingleRelationship rel =
                (ISingleRelationship)lRelationshipDef.CreateRelationship(_mMockBO, _mMockBO.PropCol);

            Assert.AreEqual(lRelationshipDef.RelationshipName, rel.RelationshipName);
            Assert.IsTrue(_mMockBO.GetPropertyValue("MockBOProp1") == null);
            Assert.IsFalse(rel.HasRelatedObject(), "Should be false since props are not defaulted in Mock bo");
            _mMockBO.SetPropertyValue("MockBOProp1", _mMockBO.GetPropertyValue("MockBOID"));
            _mMockBO.Save();
            Assert.IsTrue(rel.HasRelatedObject(), "Should be true since prop MockBOProp1 has been set");

            Assert.AreEqual(_mMockBO.GetPropertyValue("MockBOProp1"), _mMockBO.GetPropertyValue("MockBOID"));
            MockBO ltempBO = (MockBO)rel.GetRelatedObject();

            Assert.IsFalse(ltempBO == null);
            Assert.AreEqual(_mMockBO.GetPropertyValue("MockBOID"), ltempBO.GetPropertyValue("MockBOID"),
                            "The object returned should be the one with the ID = MockBOID");
            Assert.AreEqual(_mMockBO.GetPropertyValueString("MockBOProp1"), ltempBO.GetPropertyValueString("MockBOID"),
                            "The object returned should be the one with the ID = MockBOID");
            Assert.AreEqual(_mMockBO.GetPropertyValue("MockBOProp1"), ltempBO.GetPropertyValue("MockBOID"),
                            "The object returned should be the one with the ID = MockBOID");

            Assert.IsTrue(ReferenceEquals(ltempBO, rel.GetRelatedObject()));
            FixtureEnvironment.ClearBusinessObjectManager();
            Assert.IsTrue(ReferenceEquals(ltempBO, rel.GetRelatedObject()));
            _mMockBO.MarkForDelete();
            _mMockBO.Save();
        }
Пример #3
0
        public void Test_MarkForDelete_WhenSingle_WhenDeleteRelated_WhenHasRelatedBO_ShouldDoNothing()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            ClassDef.ClassDefs.Clear();
            IClassDef classDef = MyBO.LoadClassDefWithRelationship();

            MyRelatedBo.LoadClassDef();
            MyBO bo = (MyBO)classDef.CreateNewBusinessObject();

            bo.Save();
            ReflectionUtilities.SetPropertyValue(bo.Status, "IsDeleted", true);
            ISingleRelationship relationship = (ISingleRelationship)bo.Relationships["MyRelationship"];
            MyRelatedBo         myRelatedBO  = new MyRelatedBo();

            relationship.SetRelatedObject(myRelatedBO);
            SetDeleteRelatedAction(relationship, DeleteParentAction.DeleteRelated);


            //---------------Assert Precondition----------------
            Assert.IsTrue(bo.Status.IsDeleted);
            Assert.IsFalse(myRelatedBO.Status.IsDeleted);
            Assert.IsNotNull(relationship.GetRelatedObject());
            Assert.AreEqual(DeleteParentAction.DeleteRelated, relationship.DeleteParentAction);
            //---------------Execute Test ----------------------
            relationship.MarkForDelete();
            //---------------Test Result -----------------------
            Assert.IsTrue(bo.Status.IsDeleted);
            Assert.IsTrue(myRelatedBO.Status.IsDeleted);
        }
        public void Test_ResetParent_NewChild_SetToNull()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO  organisation            = OrganisationTestBO.CreateSavedOrganisation();
            ISingleRelationship compositionRelationship = (ISingleRelationship)organisation.Relationships["ContactPerson"];
            RelationshipDef     relationshipDef         = (RelationshipDef)compositionRelationship.RelationshipDef;

            relationshipDef.RelationshipType = RelationshipType.Composition;
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateUnsavedContactPerson();

            contactPerson.Organisation = organisation;
            //---------------Assert Precondition----------------
            Assert.IsNotNull(contactPerson.Organisation);

            //---------------Execute Test ----------------------
            //try
            //{
            contactPerson.Organisation = null;
            //    Assert.Fail("expected Err");
            //}
            //---------------Test Result -----------------------
            //catch (HabaneroDeveloperException ex)
            //{
            //    StringAssert.Contains
            //        ("The " + compositionRelationship.RelationshipDef.RelatedObjectClassName, ex.Message);
            //    StringAssert.Contains
            //        ("could not be removed since the " + compositionRelationship.RelationshipName
            //         + " relationship is set up as ", ex.Message);
            //}
            Assert.IsNull(contactPerson.Organisation);
        }
        public void Test_RemoveMethod()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO  organisation            = OrganisationTestBO.CreateSavedOrganisation();
            ISingleRelationship compositionRelationship = (ISingleRelationship)organisation.Relationships["ContactPerson"];
            RelationshipDef     relationshipDef         = (RelationshipDef)compositionRelationship.RelationshipDef;

            relationshipDef.RelationshipType = RelationshipType.Composition;
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateUnsavedContactPerson();

            compositionRelationship.SetRelatedObject(contactPerson);

            //---------------Assert Precondition----------------
            Assert.AreEqual(contactPerson.OrganisationID, organisation.OrganisationID);
            Assert.AreSame(organisation.ContactPerson, contactPerson);
            Assert.AreEqual(RelationshipType.Composition, compositionRelationship.RelationshipDef.RelationshipType);

            //---------------Execute Test ----------------------
            //try
            //{
            compositionRelationship.SetRelatedObject(null);
            //    Assert.Fail("expected Err");
            //}
            ////---------------Test Result -----------------------
            //catch (HabaneroDeveloperException ex)
            //{
            //    StringAssert.Contains("The " + compositionRelationship.RelationshipDef.RelatedObjectClassName, ex.Message);
            //    StringAssert.Contains("could not be removed since the " + compositionRelationship.RelationshipName + " relationship is set up as ", ex.Message);
            //}
            Assert.IsNull(compositionRelationship.GetRelatedObject());
        }
Пример #6
0
        /// <summary>
        /// Returns the business object that is related to this object
        /// through the specified relationship (eg. would return a father
        /// if the relationship was called "father").  This method is to be
        /// used in the case of single relationships.
        /// </summary>
        /// <param name="relationshipName">The name of the relationship</param>
        /// <returns>Returns a business object</returns>
        /// <exception cref="InvalidRelationshipAccessException">Thrown if
        /// the relationship specified is a multiple relationship, when a
        /// single one was expected</exception>
        public IBusinessObject GetRelatedObject(string relationshipName)
        {
            ArgumentValidationHelper.CheckStringArgumentNotEmpty(relationshipName, "relationshipName");
            ISingleRelationship relationship = GetSingle(relationshipName);

            return(relationship.GetRelatedObject());
        }
Пример #7
0
        private bool MustCreateSinglePropValue(ISingleRelationship singleRelationship)
        {
            var singleValueDef = singleRelationship.RelationshipDef as ISingleValueDef;

            return((singleRelationship.RelationshipDef.IsCompulsory && SetCompulsorySingleRelationships) ||
                   _defaultValueRegistry.IsRegistered(singleRelationship.RelationshipName) ||
                   _validValueGenRegistry.IsRegistered(singleValueDef));
        }
Пример #8
0
 /// <summary>
 /// Loads a business object using the relationship given. The relationship will be converted into a
 /// Criteria object that defines the relationship and this will be used to load the related object.
 /// </summary>
 /// <param name="relationship">The relationship to use to load the object</param>
 /// <returns>An object of the type defined by the relationship if one was found, otherwise null</returns>
 public IBusinessObject GetRelatedBusinessObject(ISingleRelationship relationship)
 {
     if (_businessObjectLoaders.ContainsKey(relationship.RelatedObjectClassDef.ClassType))
     {
         return(_businessObjectLoaders[relationship.RelatedObjectClassDef.ClassType].GetRelatedBusinessObject(relationship));
     }
     return(_defaultBusinessObjectLoader.GetRelatedBusinessObject(relationship));
 }
Пример #9
0
        private void RemoveRelatedObject(TBusinessObject bo)
        {
            ISingleRelationship reverseRelationship = GetReverseRelationship(bo) as ISingleRelationship;

            if (reverseRelationship != null)
            {
                reverseRelationship.SetRelatedObject(null);
            }
        }
Пример #10
0
        /// <summary>
        /// Loads a business object using the relationship given. The relationship will be converted into a
        /// Criteria object that defines the relationship and this will be used to load the related object.
        /// </summary>
        /// <param name="relationship">The relationship to use to load the object</param>
        /// <returns>An object of the type defined by the relationship if one was found, otherwise null</returns>
        public IBusinessObject GetRelatedBusinessObject(ISingleRelationship relationship)
        {
            RelationshipDef relationshipDef = (RelationshipDef)relationship.RelationshipDef;

            if (relationshipDef.RelatedObjectClassDef != null)
            {
                return(GetBusinessObject(relationshipDef.RelatedObjectClassDef, Criteria.FromRelationship(relationship)));
            }
            return(null);
        }
Пример #11
0
        public void TestCreateSingleRelationship()
        {
            ISingleRelationship rel =
                (ISingleRelationship)_singleRelationshipDef.CreateRelationship(_fakeBO, _fakeBO.Props);

            //-------------Execute Test ------------------------
            bool hasRelatedObject = rel.HasRelatedObject();

            //-------------Test Result -------------------------
            Assert.IsTrue(hasRelatedObject);
        }
Пример #12
0
        /// <summary>
        /// Sets the Value of the <see cref="ISingleRelationship"/> to a valid value.
        /// </summary>
        /// <param name="singleRelationship"></param>
        public virtual void SetRelationshipToValidValue(ISingleRelationship singleRelationship)
        {
            if (singleRelationship.GetRelatedObject() != null &&
                !_defaultValueRegistry.IsRegistered(singleRelationship.RelationshipName))
            {
                return;
            }
            IBusinessObject validBusinessObject = this.GetValidRelationshipValue(singleRelationship.RelationshipDef as ISingleValueDef);

            singleRelationship.SetRelatedObject(validBusinessObject);
        }
Пример #13
0
        private bool IsForeignKeySetup(TBusinessObject bo)
        {
            ISingleRelationship reverseRelationship = GetReverseRelationship(bo) as ISingleRelationship;

            if (reverseRelationship != null)
            {
                IBusinessObject relatedObject = reverseRelationship.GetRelatedObject();
                return(relatedObject == this._relationship.OwningBO);
            }
            return(false);
        }
Пример #14
0
        private void UpdateChildProperty()
        {
            DeRegisterForChildRelationshipEvents();
            IRelationship childRelationship = _relationshipPathMapper.Relationship;

            if (childRelationship != null && !(childRelationship is ISingleRelationship))
            {
                IClassDef classDef = childRelationship.OwningBO.ClassDef;
                throw new RelationshipNotFoundException("The relationship '" + _relationshipPathMapper.RelationshipName + "' on '"
                                                        + classDef.ClassName + "' is not a Single Relationship. Please contact your system administrator.");
            }
            _childRelationship = (ISingleRelationship)childRelationship;
            RegisterForChildRelationshipEvents();
            UpdateChildPropertyBO();
        }
        public void Test_SetChild_NewChild()
        {
            //A new Brain can be set as the brain of a person.  This is allowed in Habanero for flexibility, but
            // it is rather recommended that the Person creates the Brain.
            //---------------Set up test pack-------------------
            OrganisationTestBO  organisation            = OrganisationTestBO.CreateSavedOrganisation();
            ISingleRelationship compositionRelationship = GetCompositionRelationship(organisation);

            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateUnsavedContactPerson();

            //---------------Execute Test ----------------------
            compositionRelationship.SetRelatedObject(contactPerson);

            //---------------Test Result -----------------------
            Assert.AreSame(contactPerson, compositionRelationship.GetRelatedObject());
        }
        public void Test_SetParent_NewChild()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO  organisation            = OrganisationTestBO.CreateSavedOrganisation();
            ISingleRelationship compositionRelationship = (ISingleRelationship)organisation.Relationships["ContactPerson"];
            RelationshipDef     relationshipDef         = (RelationshipDef)compositionRelationship.RelationshipDef;

            relationshipDef.RelationshipType = RelationshipType.Composition;
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateUnsavedContactPerson();

            //---------------Execute Test ----------------------
            contactPerson.Organisation = organisation;

            //---------------Test Result -----------------------
            Assert.AreSame(contactPerson, organisation.ContactPerson);
            Assert.AreSame(organisation, contactPerson.Organisation);
        }
Пример #17
0
        private void UpdateChildRelationship()
        {
            DeRegisterForChildRelationshipEvents();
            IRelationship childRelationship = _localBoRelationshipMapper.Relationship;

            if (childRelationship != null && !(childRelationship is ISingleRelationship))
            {
                IClassDef classDef = childRelationship.OwningBO.ClassDef;
                throw new HabaneroDeveloperException("The relationship '" + _localBoRelationshipMapper.RelationshipName + "' on '"
                                                     + classDef.ClassName + "' is not a Single Relationship. Please contact your system administrator.",
                                                     "The relationship '" + _localBoRelationshipMapper.RelationshipName + "' on the BusinessObject '"
                                                     + classDef.ClassNameFull + "' is not a Single Relationship therefore cannot be traversed.");
            }
            _childRelationship = (ISingleRelationship)childRelationship;
            RegisterForChildRelationshipEvents();
            UpdateChildRelationshipBO();
        }
Пример #18
0
        public void TestGetSingle()
        {
            //---------------Set up test pack-------------------
            IClassDef classDef = MyBO.LoadClassDefWithRelationship();

            MyRelatedBo.LoadClassDef();
            MyBO   bo1 = (MyBO)classDef.CreateNewBusinessObject();
            string relationshipName = "MyRelationship";

            //---------------Execute Test ----------------------
            ISingleRelationship relationship = bo1.Relationships.GetSingle(relationshipName);

            //---------------Test Result -----------------------

            Assert.IsNotNull(relationship);
            Assert.AreEqual(relationshipName, relationship.RelationshipName);
        }
        public void Test_SetParentNull()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO  organisation            = OrganisationTestBO.CreateSavedOrganisation();
            ISingleRelationship compositionRelationship = (ISingleRelationship)organisation.Relationships["ContactPerson"];
            RelationshipDef     relationshipDef         = (RelationshipDef)compositionRelationship.RelationshipDef;

            relationshipDef.RelationshipType = RelationshipType.Composition;
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateUnsavedContactPerson();

            //---------------Assert Precondition----------------
            Assert.IsNull(contactPerson.Organisation);

            //---------------Execute Test ----------------------
            contactPerson.Organisation = null;

            //---------------Test Result -----------------------
            Assert.IsNull(contactPerson.Organisation);
        }
Пример #20
0
        public void TestGetSingle_Fail()
        {
            //---------------Set up test pack-------------------
            IClassDef classDef = MyBO.LoadClassDefWithRelationship();

            MyRelatedBo.LoadClassDef();
            MyBO   bo1 = (MyBO)classDef.CreateNewBusinessObject();
            string relationshipName = "MyMultipleRelationship";

            //---------------Execute Test ----------------------
            try
            {
                ISingleRelationship relationship = bo1.Relationships.GetSingle(relationshipName);
                Assert.Fail("Should have failed because we're accessing a multiple relationship as a single.");
                //---------------Test Result -----------------------
            }
            catch (InvalidRelationshipAccessException)
            {
            }
        }
Пример #21
0
        public void Test_UpdateRelatedObject_ShouldRaiseEvent()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse();
            OrganisationTestBO.LoadDefaultClassDef();
            OrganisationTestBO  organisationTestBO  = OrganisationTestBO.CreateSavedOrganisation();
            ContactPersonTestBO contactPersonTestBO = ContactPersonTestBO.CreateUnsavedContactPerson();
            ISingleRelationship relationship        = (ISingleRelationship)contactPersonTestBO.Relationships["Organisation"];
            bool eventCalled = false;

            relationship.RelKey.RelatedPropValueChanged += delegate { eventCalled = true; };
            //---------------Assert Precondition----------------
            Assert.IsTrue(contactPersonTestBO.Relationships.GetSingle <OrganisationTestBO>("Organisation").OwningBOHasForeignKey);
            Assert.IsFalse(eventCalled);
            //---------------Execute Test ----------------------
            contactPersonTestBO.Organisation = organisationTestBO;
            //---------------Test Result -----------------------
            Assert.IsTrue(eventCalled);
        }
Пример #22
0
 private void LoadRelationshipNode(IRelationship relationship, ITreeNodeCollection nodes)
 {
     if (relationship is IMultipleRelationship)
     {
         IMultipleRelationship     multipleRelationship = (IMultipleRelationship)relationship;
         IBusinessObjectCollection children             = multipleRelationship.BusinessObjectCollection;
         foreach (IBusinessObject businessObject in children.Clone())
         {
             AddBusinessObjectNode(nodes, businessObject);
         }
     }
     else
     {
         ISingleRelationship singleRelationship = (ISingleRelationship)relationship;
         IBusinessObject     businessObject     = singleRelationship.GetRelatedObject();
         if (businessObject != null)
         {
             AddBusinessObjectNode(nodes, businessObject);
         }
     }
 }
        private void SetupSingleRelationship()
        {
            var relationship = _boRelationshipMapper.Relationship;

            if (relationship == null)
            {
                _singleRelationship = null;
            }
            else if (relationship is ISingleRelationship)
            {
                _singleRelationship   = (ISingleRelationship)relationship;
                RelatedObjectClassDef = _singleRelationship.RelatedObjectClassDef;
            }
            else
            {
                string standardMessage = string.Format("The relationship '{0}' on '{1}' is not a single relationship. ",
                                                       RelationshipName, ClassDef.ClassNameFull);
                throw new HabaneroDeveloperException(standardMessage + "Please contact your System Administrator.",
                                                     standardMessage +
                                                     "The 'RelationshipComboBoxMapper' can only be used for single relationships");
            }
        }
        public void Test_SetChild_PersistedChild()
        {
            //An already persi`sted Brain cannot be set as the brain of a person.
            //---------------Set up test pack-------------------
            OrganisationTestBO  organisation            = OrganisationTestBO.CreateSavedOrganisation();
            ISingleRelationship compositionRelationship = GetCompositionRelationship(organisation);

            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateSavedContactPerson();

            //---------------Execute Test ----------------------
            try
            {
                compositionRelationship.SetRelatedObject(contactPerson);
                Assert.Fail("expected Err");
            }
            //---------------Test Result -----------------------
            catch (HabaneroDeveloperException ex)
            {
                StringAssert.Contains("The " + compositionRelationship.RelationshipDef.RelatedObjectClassName, ex.Message);
                StringAssert.Contains("could not be added since the " + compositionRelationship.RelationshipName + " relationship is set up as ", ex.Message);
            }
        }
Пример #25
0
 private void RemoveRelationshipNode(IRelationship relationship)
 {
     this.RelationshipNodes.Remove(relationship);
     if (relationship is IMultipleRelationship)
     {
         IMultipleRelationship     multipleRelationship = (IMultipleRelationship)relationship;
         IBusinessObjectCollection children             = multipleRelationship.BusinessObjectCollection;
         ChildCollectionNodes.Remove(children);
         foreach (IBusinessObject businessObject in children.Clone())
         {
             RemoveBusinessObjectNode(businessObject);
         }
     }
     else
     {
         ISingleRelationship singleRelationship = (ISingleRelationship)relationship;
         IBusinessObject     businessObject     = singleRelationship.GetRelatedObject();
         if (businessObject != null)
         {
             RemoveBusinessObjectNode(businessObject);
         }
     }
 }
Пример #26
0
        public void Test_UpdatePropValue_ShouldRaiseEvent()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse();
            OrganisationTestBO.LoadDefaultClassDef();
            ContactPersonTestBO contactPersonTestBO = ContactPersonTestBO.CreateUnsavedContactPerson();
            ISingleRelationship relationship        = (ISingleRelationship)contactPersonTestBO.Relationships["Organisation"];
            bool eventCalled = false;

            IRelKey  key     = relationship.RelKey;
            IRelProp relProp = key[0];
            IBOProp  prop    = relProp.BOProp;

            relProp.PropValueUpdated += delegate { eventCalled = true; };
            //---------------Assert Precondition----------------
            Assert.IsTrue(contactPersonTestBO.Relationships.GetSingle <OrganisationTestBO>("Organisation").OwningBOHasForeignKey);
            Assert.IsFalse(eventCalled);
            //---------------Execute Test ----------------------
            prop.Value = Guid.NewGuid();
            //---------------Test Result -----------------------
            Assert.IsTrue(eventCalled);
        }
Пример #27
0
        private void SetupRelationshipNodeDummy(IRelationship relationship, NodeState nodeState)
        {
            int childCount = 0;

            if (relationship is IMultipleRelationship)
            {
                IMultipleRelationship     multipleRelationship     = (IMultipleRelationship)relationship;
                IBusinessObjectCollection businessObjectCollection = multipleRelationship.BusinessObjectCollection;
                ChildCollectionNodes.Add(businessObjectCollection, nodeState);
                RegisterForBusinessObjectCollectionEvents(businessObjectCollection);
                childCount = businessObjectCollection.Count;
            }
            else
            {
                //TODO: Do something decent with Single Relationship Updated Event
                ISingleRelationship singleRelationship = (ISingleRelationship)relationship;
                if (singleRelationship.HasRelatedObject())
                {
                    childCount = 1;
                }
            }
            UpdateNodeDummy(nodeState, childCount);
        }
Пример #28
0
        public void TestGetRelatedObject()
        {
            RelationshipDef mRelationshipDef;
            RelKeyDef       mRelKeyDef;
            MockBO          _mMockBO         = GetMockBO(out mRelationshipDef, out mRelKeyDef);
            RelationshipDef lRelationshipDef = new SingleRelationshipDef("Relation1", typeof(MockBO), mRelKeyDef, true,
                                                                         DeleteParentAction.Prevent);
            ISingleRelationship rel =
                (ISingleRelationship)lRelationshipDef.CreateRelationship(_mMockBO, _mMockBO.PropCol);

            Assert.AreEqual(lRelationshipDef.RelationshipName, rel.RelationshipName);
            Assert.IsTrue(_mMockBO.GetPropertyValue("MockBOProp1") == null);
            Assert.IsFalse(rel.HasRelatedObject(), "Should be false since props are not defaulted in Mock bo");
            //Set a related object
            _mMockBO.SetPropertyValue("MockBOProp1", _mMockBO.GetPropertyValue("MockBOID"));
            //Save the object, so that the relationship can retrieve the object from the database
            _mMockBO.Save();
            Assert.IsTrue(rel.HasRelatedObject(), "Should have a related object since the relating props have values");
            MockBO ltempBO = (MockBO)rel.GetRelatedObject();

            Assert.IsNotNull(ltempBO, "The related object should exist");
            //Clear the related object
            _mMockBO.SetPropertyValue("MockBOProp1", null);
            Assert.IsFalse(rel.HasRelatedObject(),
                           "Should not have a related object since the relating props have been set to null");
            ltempBO = (MockBO)rel.GetRelatedObject();
            Assert.IsNull(ltempBO, "The related object should now be null");
            //Set a related object again
            _mMockBO.SetPropertyValue("MockBOProp1", _mMockBO.GetPropertyValue("MockBOID"));
            Assert.IsTrue(rel.HasRelatedObject(),
                          "Should have a related object since the relating props have values again");
            ltempBO = (MockBO)rel.GetRelatedObject();
            Assert.IsNotNull(ltempBO, "The related object should exist again");
            _mMockBO.MarkForDelete();
            _mMockBO.Save();
        }
        public void Test_SetParent_PersistedChild()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO  organisation            = OrganisationTestBO.CreateSavedOrganisation();
            ISingleRelationship compositionRelationship = (ISingleRelationship)organisation.Relationships["ContactPerson"];
            RelationshipDef     relationshipDef         = (RelationshipDef)compositionRelationship.RelationshipDef;

            relationshipDef.RelationshipType = RelationshipType.Composition;
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateSavedContactPerson();

            //---------------Execute Test ----------------------
            try
            {
                contactPerson.Organisation = organisation;
                Assert.Fail("expected Err");
            }
            //---------------Test Result -----------------------
            catch (HabaneroDeveloperException ex)
            {
                StringAssert.Contains("The " + compositionRelationship.RelationshipDef.RelatedObjectClassName, ex.Message);
                StringAssert.Contains("could not be added since the " + compositionRelationship.RelationshipName + " relationship is set up as ", ex.Message);
            }
            //---------------Test Result -----------------------
        }
Пример #30
0
 private void UpdateChildProperty()
 {
     DeRegisterForChildRelationshipEvents();
     IRelationship childRelationship = _relationshipPathMapper.Relationship;
     if (childRelationship != null && !(childRelationship is ISingleRelationship))
     {
         IClassDef classDef = childRelationship.OwningBO.ClassDef;
         throw new RelationshipNotFoundException("The relationship '" + _relationshipPathMapper.RelationshipName + "' on '"
                                              + classDef.ClassName + "' is not a Single Relationship. Please contact your system administrator.");
     }
     _childRelationship = (ISingleRelationship)childRelationship;
     RegisterForChildRelationshipEvents();
     UpdateChildPropertyBO();
 }
Пример #31
0
 private void UpdateChildRelationship()
 {
     DeRegisterForChildRelationshipEvents();
     IRelationship childRelationship = _localBoRelationshipMapper.Relationship;
     if (childRelationship != null && !(childRelationship is ISingleRelationship))
     {
         IClassDef classDef = childRelationship.OwningBO.ClassDef;
         throw new HabaneroDeveloperException("The relationship '" + _localBoRelationshipMapper.RelationshipName + "' on '"
                                              + classDef.ClassName + "' is not a Single Relationship. Please contact your system administrator.",
                                              "The relationship '" + _localBoRelationshipMapper.RelationshipName + "' on the BusinessObject '"
                                              + classDef.ClassNameFull + "' is not a Single Relationship therefore cannot be traversed.");
     }
     _childRelationship = (ISingleRelationship)childRelationship;
     RegisterForChildRelationshipEvents();
     UpdateChildRelationshipBO();
 }
Пример #32
0
 /// <summary>
 /// Loads a business object using the relationship given. The relationship will be converted into a
 /// Criteria object that defines the relationship and this will be used to load the related object.
 /// </summary>
 /// <param name="relationship">The relationship to use to load the object</param>
 /// <returns>An object of the type defined by the relationship if one was found, otherwise null</returns>
 public static IBusinessObject GetRelatedBusinessObject(ISingleRelationship relationship)
 {
     return(BORegistry.DataAccessor.BusinessObjectLoader.GetRelatedBusinessObject(relationship));
 }
 private void SetupSingleRelationship()
 {
     var relationship = _boRelationshipMapper.Relationship;
     if (relationship == null) _singleRelationship = null;
     else if (relationship is ISingleRelationship)
     {
         _singleRelationship = (ISingleRelationship) relationship;
         RelatedObjectClassDef = _singleRelationship.RelatedObjectClassDef;
     }
     else
     {
         string standardMessage = string.Format("The relationship '{0}' on '{1}' is not a single relationship. ",
                                                RelationshipName, ClassDef.ClassNameFull);
         throw new HabaneroDeveloperException(standardMessage + "Please contact your System Administrator.",
                                              standardMessage +
                                              "The 'RelationshipComboBoxMapper' can only be used for single relationships");
     }
 }
 /// <summary>
 /// Sets the Value of the <see cref="ISingleRelationship"/> to a valid value.
 /// </summary>
 /// <param name="singleRelationship"></param>
 public virtual void SetRelationshipToValidValue(ISingleRelationship singleRelationship)
 {
     if (singleRelationship.GetRelatedObject() != null &&
         !_defaultValueRegistry.IsRegistered(singleRelationship.RelationshipName)) return;
     IBusinessObject validBusinessObject = this.GetValidRelationshipValue(singleRelationship.RelationshipDef as ISingleValueDef);
     singleRelationship.SetRelatedObject(validBusinessObject);
 }
 private bool MustCreateSinglePropValue(ISingleRelationship singleRelationship)
 {
     var singleValueDef = singleRelationship.RelationshipDef as ISingleValueDef;
     return (singleRelationship.RelationshipDef.IsCompulsory && SetCompulsorySingleRelationships)
            || _defaultValueRegistry.IsRegistered(singleRelationship.RelationshipName)
            || _validValueGenRegistry.IsRegistered(singleValueDef);
 }