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 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(); }
public void TestCreateSingleRelationship() { ISingleRelationship rel = (ISingleRelationship)_singleRelationshipDef.CreateRelationship(_fakeBO, _fakeBO.Props); //-------------Execute Test ------------------------ bool hasRelatedObject = rel.HasRelatedObject(); //-------------Test Result ------------------------- Assert.IsTrue(hasRelatedObject); }
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(); }
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); }