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 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); }
private void RemoveRelatedObject(TBusinessObject bo) { ISingleRelationship reverseRelationship = GetReverseRelationship(bo) as ISingleRelationship; if (reverseRelationship != null) { reverseRelationship.SetRelatedObject(null); } }
/// <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); }
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()); }
/// <summary> /// Sets the property value to that provided. If the property value /// is invalid, the error provider will be given the reason why the /// value is invalid. /// </summary> protected virtual void SetRelatedBusinessObject(IBusinessObject value) { if (_businessObject == null) { return; } try { if (_singleRelationship != null) { _singleRelationship.SetRelatedObject(value); } } catch (HabaneroIncorrectTypeException) { ////TODO Brett 24 Mar 2009: Write tests and implement this.ErrorProvider.SetError(Control, ex.Message); return; } UpdateErrorProviderErrorMessage(); }
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); } }
/// <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); }