Beispiel #1
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();
        }
        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());
        }
        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();
        }
Beispiel #4
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);
        }
Beispiel #5
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());
        }
Beispiel #6
0
        private void UpdateChildPropertyBO()
        {
            IBusinessObject relatedObject = null;

            if (_childRelationship != null)
            {
                relatedObject = _childRelationship.GetRelatedObject();
            }
            _childBoPropertyMapper.BusinessObject = relatedObject;
        }
Beispiel #7
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);
        }
Beispiel #8
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);
        }
Beispiel #9
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_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());
        }
 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 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);
         }
     }
 }
 /// <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);
 }
 /// <summary>
 /// Returns the property value of the business object being mapped
 /// </summary>
 /// <returns>Returns the property value in appropriate object form</returns>
 protected internal IBusinessObject GetRelatedBusinessObject()
 {
     return(_singleRelationship == null ? null : _singleRelationship.GetRelatedObject());
 }