예제 #1
0
        public void Test_ResetParent_NewChild_ReverseRelationship_Loaded()
        {
            //An new invoice line can be added to an Invoice
            //(In Habanero a new invoice line can be added to an invoice).
            // This rule is also be applied for the reverse relationship
            // In this case the organisation can be set for myBO since myBO has never
            //   been associated with am organisation.
            //---------------Set up test pack-------------------
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            BusinessObjectCollection <ContactPersonTestBO> cpCol;

            GetCompositionRelationship(out cpCol, organisationTestBO);
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateUnsavedContactPerson(TestUtil.GetRandomString(), TestUtil.GetRandomString());

            util.RegisterForAddedAndRemovedEvents(cpCol);

            //---------------Assert Precondition----------------
            util.AssertAllCollectionsHaveNoItems(cpCol);

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

            //---------------Test Result -----------------------
            Assert.AreEqual(contactPerson.OrganisationID, organisationTestBO.OrganisationID);
            util.AssertOneObjectInCurrentAndCreatedCollection(cpCol);
            Assert.IsTrue(cpCol.Contains(contactPerson));
            util.AssertAddedEventFired();
        }
예제 #2
0
        public void Test_CheckDuplicateIdentifier_WhenTransactionCommitterHasAddedBOAndUpdatedBOWithSameUniqueKey_ShouldReturnError()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO.LoadDefaultClassDefWithKeyOnSurname();
            var surname             = BOTestUtils.RandomString;
            var contactPersonTestBO = ContactPersonTestBO.CreateUnsavedContactPerson(BOTestUtils.RandomString, BOTestUtils.RandomString);

            contactPersonTestBO.Save();
            contactPersonTestBO.Surname = surname;

            var transactionalBusinessObject           = new TransactionalBusinessObject(contactPersonTestBO);
            var newContactPersonTestBOWithSameSurname = ContactPersonTestBO.CreateUnsavedContactPerson(surname, BOTestUtils.RandomString);
            var transactionalBusinessObjectDuplicate  = new TransactionalBusinessObject(newContactPersonTestBOWithSameSurname);
            var pendingTransactions = new List <ITransactional> {
                transactionalBusinessObject, transactionalBusinessObjectDuplicate
            };

            //---------------Assert Precondition----------------
            Assert.IsFalse(contactPersonTestBO.Status.IsNew);
            Assert.IsTrue(contactPersonTestBO.Status.IsDirty);
            Assert.IsTrue(newContactPersonTestBOWithSameSurname.Status.IsNew);
            Assert.AreEqual(surname, contactPersonTestBO.Surname);
            Assert.AreEqual(surname, newContactPersonTestBOWithSameSurname.Surname);
            //---------------Execute Test ----------------------
            var errorMessages = new List <string>();

            transactionalBusinessObject.CheckDuplicateIdentifier(pendingTransactions, errorMessages);
            //---------------Test Result -----------------------
            Assert.AreEqual(1, errorMessages.Count);
            Assert.AreEqual(string.Format("A 'Contact Person Test BO' already exists with the same identifier: Surname = {0}.", surname), errorMessages[0]);
        }
        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);
        }
예제 #4
0
        //This Acceptance Test has a corresponding unit test on the CheckDuplicateIdentifier method in TestTransactionalBusinessObject
        public void Test_Commit_WhenTransactionCommitterHasAddedBOAndUpdatedBOWithSameUniqueKey_ShouldThrowDuplicateError()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO.LoadDefaultClassDefWithKeyOnSurname();
            var surname             = BOTestUtils.RandomString;
            var contactPersonTestBO = ContactPersonTestBO.CreateUnsavedContactPerson(BOTestUtils.RandomString, BOTestUtils.RandomString);
            var newContactPersonTestBOWithSameSurname = ContactPersonTestBO.CreateUnsavedContactPerson(surname, BOTestUtils.RandomString);
            var committer = BORegistry.DataAccessor.CreateTransactionCommitter();

            committer.AddBusinessObject(contactPersonTestBO);
            committer.CommitTransaction();
            contactPersonTestBO.Surname = surname;
            committer.AddBusinessObject(contactPersonTestBO);
            committer.AddBusinessObject(newContactPersonTestBOWithSameSurname);
            //---------------Assert Precondition----------------
            Assert.IsFalse(contactPersonTestBO.Status.IsNew);
            Assert.IsTrue(contactPersonTestBO.Status.IsDirty);
            Assert.IsTrue(newContactPersonTestBOWithSameSurname.Status.IsNew);
            Assert.AreEqual(surname, contactPersonTestBO.Surname);
            Assert.AreEqual(surname, newContactPersonTestBOWithSameSurname.Surname);
            //---------------Execute Test ----------------------
            var exception = Assert.Throws <BusObjDuplicateConcurrencyControlException>(() =>
            {
                committer.CommitTransaction();
            });

            //---------------Test Result -----------------------
            Assert.AreEqual(string.Format("A 'Contact Person Test BO' already exists with the same identifier: Surname = {0}.", surname), exception.Message);
        }
        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
        public void Test_CheckDuplicateIdentifier_WhenTransactionCommitterHasAddedBOWithSameUniqueKeyAsMarkedForDeleteBO_WhenDeletedBONotInPendingTransactions_ShouldReturnError()
        {
            //---------------Set up test pack-------------------
            BORegistry.BusinessObjectManager = new BusinessObjectManagerNull();
            ContactPersonTestBO.LoadDefaultClassDefWithKeyOnSurname();
            var surname             = BOTestUtils.RandomString;
            var contactPersonTestBO = ContactPersonTestBO.CreateUnsavedContactPerson(surname, BOTestUtils.RandomString);

            contactPersonTestBO.Save();
            contactPersonTestBO.MarkForDelete();
            var transactionalBusinessObjectForDeletedDuplicate = new TransactionalBusinessObject(contactPersonTestBO);
            var newContactPersonTestBOWithSameSurname          = ContactPersonTestBO.CreateUnsavedContactPerson(surname, BOTestUtils.RandomString);
            var transactionalBusinessObject = new TransactionalBusinessObject(newContactPersonTestBOWithSameSurname);
            var pendingTransactions         = new List <ITransactional> {
                transactionalBusinessObject
            };

            //---------------Assert Precondition----------------
            Assert.IsFalse(transactionalBusinessObjectForDeletedDuplicate.IsNew());
            Assert.IsTrue(transactionalBusinessObjectForDeletedDuplicate.IsDeleted);
            Assert.IsTrue(transactionalBusinessObject.IsNew());
            Assert.IsFalse(transactionalBusinessObject.IsDeleted);
            Assert.AreEqual(surname, contactPersonTestBO.Props["Surname"].PersistedPropertyValueString);
            //---------------Execute Test ----------------------
            var errorMessages = new List <string>();

            transactionalBusinessObject.CheckDuplicateIdentifier(pendingTransactions, errorMessages);
            //---------------Test Result -----------------------
            Assert.AreEqual(1, errorMessages.Count);
            Assert.AreEqual(string.Format("A 'Contact Person Test BO' already exists with the same identifier: Surname = {0}.", surname), errorMessages[0]);
        }
예제 #7
0
        public void Test_CheckDuplicateIdentifier_WhenTransactionCommitterHasAddedBOsWithSamePrimaryKey_ShouldReturnError()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO.LoadClassDefWithCompositePrimaryKeyNameSurname();
            var contactPersonTestBO                   = ContactPersonTestBO.CreateUnsavedContactPerson();
            var surname                               = contactPersonTestBO.Surname;
            var firstName                             = contactPersonTestBO.FirstName;
            var transactionalBusinessObject           = new TransactionalBusinessObject(contactPersonTestBO);
            var newContactPersonTestBOWithSameSurname = ContactPersonTestBO.CreateUnsavedContactPerson(surname, firstName);
            var transactionalBusinessObjectDuplicate  = new TransactionalBusinessObject(newContactPersonTestBOWithSameSurname);
            var pendingTransactions                   = new List <ITransactional> {
                transactionalBusinessObject, transactionalBusinessObjectDuplicate
            };

            //---------------Assert Precondition----------------
            Assert.IsTrue(contactPersonTestBO.Status.IsNew);
            Assert.IsTrue(newContactPersonTestBOWithSameSurname.Status.IsNew);
            Assert.AreEqual(contactPersonTestBO.FirstName, newContactPersonTestBOWithSameSurname.FirstName);
            Assert.AreEqual(contactPersonTestBO.Surname, newContactPersonTestBOWithSameSurname.Surname);
            //---------------Execute Test ----------------------
            var errorMessages = new List <string>();

            transactionalBusinessObject.CheckDuplicateIdentifier(pendingTransactions, errorMessages);
            //---------------Test Result -----------------------
            Assert.AreEqual(1, errorMessages.Count);
            Assert.AreEqual(string.Format("A 'Contact Person Test BO' already exists with the same identifier: Surname = {0}, FirstName = {1}.", surname, firstName), errorMessages[0]);
        }
        public void Test_ParentDirtyIfHasDirtyChildren()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisation = OrganisationTestBO.CreateSavedOrganisation();
            SingleRelationship <ContactPersonTestBO> relationship = GetCompositionRelationship(organisation);
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateUnsavedContactPerson();

            relationship.SetRelatedObject(contactPerson);
            contactPerson.Surname   = TestUtil.GetRandomString();
            contactPerson.FirstName = TestUtil.GetRandomString();
            contactPerson.Save();

            //---------------Assert Precondition----------------
            Assert.IsFalse(contactPerson.Status.IsDirty);
            Assert.IsFalse(relationship.IsDirty);
            Assert.IsFalse(organisation.Relationships.IsDirty);
            Assert.IsFalse(organisation.Status.IsDirty);

            //---------------Execute Test ----------------------
            contactPerson.FirstName = TestUtil.GetRandomString();

            //---------------Test Result -----------------------
            Assert.IsTrue(contactPerson.Status.IsDirty);
            Assert.IsTrue(relationship.IsDirty);
            Assert.IsTrue(organisation.Relationships.IsDirty);
            Assert.IsTrue(organisation.Status.IsDirty);
        }
예제 #9
0
        public void Test_SetParentNull_NewChild_BotRelationshipSetUpAsOwning()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO  organisation  = OrganisationTestBO.CreateSavedOrganisation();
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateUnsavedContactPerson();
            SingleRelationship <OrganisationTestBO> relationshipOrganisation = GetAggregationRelationshipOrganisation(contactPerson, "Organisation");

            relationshipOrganisation.OwningBOHasForeignKey = true;

            SingleRelationship <ContactPersonTestBO> relationshipContactPerson = GetAggregationRelationshipContactPerson(organisation, "ContactPerson");

            relationshipContactPerson.OwningBOHasForeignKey = true;
            //---------------Assert Preconditon-----------------
            Assert.IsNull(organisation.ContactPerson);
            Assert.IsNull(contactPerson.Organisation);
            Assert.IsNotNull(organisation.OrganisationID);
            //---------------Execute Test ----------------------
            try
            {
                contactPerson.Organisation = organisation;
                Assert.Fail("expected Err");
            }
            //---------------Test Result -----------------------
            catch (HabaneroDeveloperException ex)
            {
                StringAssert.Contains("The corresponding single (one to one) relationships Organisation ", ex.Message);
                StringAssert.Contains("cannot both be configured as having the foreign key", ex.Message);
            }
        }
예제 #10
0
        public void TestGetReverseRelationship_ReverseRelationshipSpecifiedButNotFound()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO.LoadDefaultClassDef();
            IClassDef cpClassDef = ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse();

            string reverseRelationshipName = TestUtil.GetRandomString();

            cpClassDef.RelationshipDefCol["Organisation"].ReverseRelationshipName = reverseRelationshipName;

            OrganisationTestBO  organisation  = OrganisationTestBO.CreateSavedOrganisation();
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateUnsavedContactPerson();

            SingleRelationship <OrganisationTestBO> organisationRel =
                contactPerson.Relationships.GetSingle <OrganisationTestBO>("Organisation");

            //---------------Execute Test ----------------------
            try
            {
                organisationRel.GetReverseRelationship(organisation);
                Assert.Fail("Should have failed since a reverse relationship was specified that didn't exist.");
            }
            catch (HabaneroDeveloperException ex)
            {
                StringAssert.Contains(
                    string.Format(
                        "The relationship 'Organisation' on class 'ContactPersonTestBO' has a reverse relationship defined ('{0}')",
                        reverseRelationshipName), ex.Message);
            }
        }
        protected static ContactPersonTestBO CreateCreatedChild_ChildOwnsEdit(OrganisationTestBO organisationTestBO)
        {
            ContactPersonTestBO createdChild = ContactPersonTestBO.CreateUnsavedContactPerson();

            createdChild.Organisation = organisationTestBO;
            return(createdChild);
        }
예제 #12
0
        //This Acceptance Test has a corresponding unit test on the CheckDuplicateIdentifier method in TestTransactionalBusinessObject
        public void Test_Commit_WhenTransactionCommitterHasAddedBOsWithSamePrimaryKey_ShouldThrowDuplicateError()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO.LoadClassDefWithCompositePrimaryKeyNameSurname();
            var contactPersonTestBO = ContactPersonTestBO.CreateUnsavedContactPerson();
            var surname             = contactPersonTestBO.Surname;
            var firstName           = contactPersonTestBO.FirstName;
            var newContactPersonTestBOWithSameSurname = ContactPersonTestBO.CreateUnsavedContactPerson(surname, firstName);
            var committer = BORegistry.DataAccessor.CreateTransactionCommitter();

            committer.AddBusinessObject(contactPersonTestBO);
            committer.AddBusinessObject(newContactPersonTestBOWithSameSurname);
            //---------------Assert Precondition----------------
            Assert.IsTrue(contactPersonTestBO.Status.IsNew);
            Assert.IsTrue(newContactPersonTestBOWithSameSurname.Status.IsNew);
            Assert.AreEqual(contactPersonTestBO.FirstName, newContactPersonTestBOWithSameSurname.FirstName);
            Assert.AreEqual(contactPersonTestBO.Surname, newContactPersonTestBOWithSameSurname.Surname);
            //---------------Execute Test ----------------------
            var exception = Assert.Throws <BusObjDuplicateConcurrencyControlException>(() =>
            {
                committer.CommitTransaction();
            });

            //---------------Test Result -----------------------
            Assert.AreEqual(string.Format("A 'Contact Person Test BO' already exists with the same identifier: Surname = {0}, FirstName = {1}.", surname, firstName), exception.Message);
        }
        public void Test_ResetParent_NewChild_SetToNull()
        {
            //A tyre can be removed from its car.   This test is removing via the reverse relationship
            //---------------Set up test pack-------------------
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            BusinessObjectCollection <ContactPersonTestBO> cpCol;

            GetAggregateRelationship(organisationTestBO, out cpCol);
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateUnsavedContactPerson(TestUtil.GetRandomString(), TestUtil.GetRandomString());

            contactPerson.OrganisationID = organisationTestBO.OrganisationID;
            contactPerson.Save();
            cpCol.LoadAll();
            util.RegisterForAddedAndRemovedEvents(cpCol);

            //---------------Assert Precondition----------------
            util.AssertOneObjectInCurrentPersistedCollection(cpCol);

            //---------------Execute Test ----------------------

            contactPerson.Organisation = null;

            //---------------Test Result -----------------------
            Assert.IsNull(contactPerson.Organisation);
            util.AssertOneObjectInRemovedAndPersisted(cpCol);
            util.AssertRemovedEventFired();
        }
예제 #14
0
        //This Acceptance Test has a corresponding unit test on the CheckDuplicateIdentifier method in TestTransactionalBusinessObject
        public void Test_Commit_WhenTransactionCommitterHasAddedBOWithSameUniqueKeyAsMarkedForDeleteBO_WhenDeletedBOInTransaction_ShouldNotThrowDuplicateError()
        {
            //---------------Set up test pack-------------------
            BORegistry.BusinessObjectManager = new BusinessObjectManagerNull();
            ContactPersonTestBO.LoadDefaultClassDefWithKeyOnSurname();
            var surname             = BOTestUtils.RandomString;
            var contactPersonTestBO = ContactPersonTestBO.CreateUnsavedContactPerson(surname, BOTestUtils.RandomString);

            contactPersonTestBO.Save();
            var committer = BORegistry.DataAccessor.CreateTransactionCommitter();

            contactPersonTestBO.MarkForDelete();
            committer.AddBusinessObject(contactPersonTestBO);
            var newContactPersonTestBOWithSameSurname = ContactPersonTestBO.CreateUnsavedContactPerson(surname, BOTestUtils.RandomString);

            committer.AddBusinessObject(newContactPersonTestBOWithSameSurname);
            //---------------Assert Precondition----------------
            Assert.IsFalse(contactPersonTestBO.Status.IsNew);
            Assert.IsTrue(contactPersonTestBO.Status.IsDeleted);
            Assert.IsTrue(newContactPersonTestBOWithSameSurname.Status.IsNew);
            Assert.IsFalse(newContactPersonTestBOWithSameSurname.Status.IsDeleted);
            Assert.AreEqual(surname, contactPersonTestBO.Props["Surname"].PersistedPropertyValueString);
            //---------------Execute Test ----------------------
            committer.CommitTransaction();
            //---------------Test Result -----------------------
            Assert.IsFalse(newContactPersonTestBOWithSameSurname.Status.IsNew);
            Assert.IsTrue(contactPersonTestBO.Status.IsDeleted);
            newContactPersonTestBOWithSameSurname.MarkForDelete();
            newContactPersonTestBOWithSameSurname.Save();
        }
        protected static ContactPersonTestBO CreateRemovedChild_ChildOwnsEdit(OrganisationTestBO organisationTestBO)
        {
            ContactPersonTestBO removedChild = ContactPersonTestBO.CreateUnsavedContactPerson();

            removedChild.Organisation = organisationTestBO;
            organisationTestBO.Save();
            removedChild.Organisation = null;
            return(removedChild);
        }
예제 #16
0
        public void Test_SetParent_AggregateDoesNotOwnForeignKey_NewChild()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO  organisation  = OrganisationTestBO.CreateSavedOrganisation();
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateUnsavedContactPerson();

            GetAggregationRelationshipOrganisation(contactPerson, "Organisation");
            //---------------Execute Test ----------------------
            contactPerson.Organisation = organisation;
            //---------------Test Result -----------------------
            Assert.AreSame(contactPerson, organisation.ContactPerson);
            Assert.AreSame(organisation, contactPerson.Organisation);
        }
예제 #17
0
        public void Test_SetChild_AggregateDoesNotOwnForeignKey_NewChild()
        {
            //A new Heart can be set as the heart of a person.  This is allowed in Habanero for flexibility, but
            // it is rather recommended that the Person creates the Heart.
            //---------------Set up test pack-------------------
            OrganisationTestBO  organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            ContactPersonTestBO contactPerson      = ContactPersonTestBO.CreateUnsavedContactPerson();
            SingleRelationship <OrganisationTestBO> relationship = GetAggregationRelationshipOrganisation(contactPerson, "Organisation");

            //---------------Execute Test ----------------------
            relationship.SetRelatedObject(organisationTestBO);
            //---------------Test Result -----------------------
            Assert.AreSame(organisationTestBO, relationship.GetRelatedObject());
        }
        public void Test_SetParentNull()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateUnsavedContactPerson(TestUtil.GetRandomString(), TestUtil.GetRandomString());

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

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

            //---------------Test Result -----------------------
            Assert.IsNull(contactPerson.Organisation);
        }
        public void Test_SetChild_NewChild()
        {
            //A new ContactPerson can be set as the contact person of an organisation.
            //---------------Set up test pack-------------------
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            SingleRelationship <ContactPersonTestBO> relationship = GetAssociationRelationship(organisationTestBO);
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateUnsavedContactPerson();

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

            //---------------Test Result -----------------------
            Assert.AreSame(contactPerson, relationship.GetRelatedObject());
        }
예제 #20
0
        public void Test_SetParent_NewChild_NonPersistedParent()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisation = OrganisationTestBO.CreateUnsavedOrganisation();

            GetAggregationRelationshipContactPerson(organisation, "ContactPerson");
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateUnsavedContactPerson();

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

            //---------------Test Result -----------------------
            Assert.AreSame(contactPerson, organisation.ContactPerson);
            Assert.AreSame(organisation, contactPerson.Organisation);
        }
        public void Test_NewChild_SavesWhenParentSaves()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisation = OrganisationTestBO.CreateSavedOrganisation();

            GetAssociationRelationship(organisation);
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateUnsavedContactPerson();

            organisation.ContactPerson = contactPerson;
            //---------------Execute Test ----------------------
            organisation.Save();

            //---------------Test Result -----------------------
            Assert.IsFalse(contactPerson.Status.IsDirty);
        }
        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());
        }
예제 #23
0
        public void Test_SetParentNull()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisation = OrganisationTestBO.CreateSavedOrganisation();

            GetAggregationRelationshipContactPerson(organisation, "ContactPerson");
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateUnsavedContactPerson();

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

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

            //---------------Test Result -----------------------
            Assert.IsNull(contactPerson.Organisation);
        }
        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);
        }
        public void Test_NotDirty_IfChildIsAddedThenRemoved()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO  organisation  = OrganisationTestBO.CreateSavedOrganisation();
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateUnsavedContactPerson();
            SingleRelationship <ContactPersonTestBO> relationship = GetCompositionRelationship(organisation);

            relationship.SetRelatedObject(contactPerson);
            IList <ContactPersonTestBO> children = relationship.GetDirtyChildren();

            //---------------Assert preconditions---------------
            Assert.AreEqual(1, children.Count);
            //---------------Execute Test ----------------------
            relationship.SetRelatedObject(null);
            children = relationship.GetDirtyChildren();
            //---------------Test Result -----------------------
            Assert.AreEqual(0, children.Count);
        }
        public void Test_ResetParent_NewChild_SetToNull()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisation = OrganisationTestBO.CreateSavedOrganisation();
            SingleRelationship <ContactPersonTestBO> relationship = GetAssociationRelationship(organisation);

            relationship.OwningBOHasForeignKey = false;
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateUnsavedContactPerson();

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

            //---------------Execute Test ----------------------
            contactPerson.Organisation = null;
            //---------------Test Result -----------------------
            Assert.IsNull(contactPerson.Organisation);
        }
        public void Test_MarkedForDeleteChild_SavesWhenParentSaves()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisation = OrganisationTestBO.CreateSavedOrganisation();

            GetAssociationRelationship(organisation);
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateUnsavedContactPerson();

            organisation.ContactPerson = contactPerson;
            contactPerson.Save();
            contactPerson.MarkForDelete();

            //---------------Execute Test ----------------------
            organisation.Save();

            //---------------Test Result -----------------------
            BOTestUtils.AssertBOStateIsValidAfterDelete(contactPerson);
        }
        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);
        }
예제 #29
0
        public void Test_TestAddNewChildBO_ParentNotPersisted_ParentSet()
        {
            //Test that the parent business object is set for a
            // child bo that is created by the collection
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            BORegistry.DataAccessor = new DataAccessorInMemory();
            ContactPersonTestBO.LoadClassDefWithAddresBOsRelationship_AddressReverseRelationshipConfigured();
            ContactPersonTestBO contactPersonTestBO =
                ContactPersonTestBO.CreateUnsavedContactPerson(TestUtil.GetRandomString(), TestUtil.GetRandomString());
            AddressTestBO address = new AddressTestBO();

            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            contactPersonTestBO.AddressTestBOs.Add(address);
            //---------------Test Result -----------------------
            Assert.IsNotNull(address.ContactPersonID);
            Assert.IsNotNull(address.ContactPersonTestBO);
        }
예제 #30
0
        public void Test_RemoveMethod()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisation = OrganisationTestBO.CreateSavedOrganisation();
            SingleRelationship <ContactPersonTestBO> relationship = GetAggregationRelationshipContactPerson(organisation, "ContactPerson");
            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateUnsavedContactPerson();

            relationship.SetRelatedObject(contactPerson);
            //---------------Assert Precondition----------------
            Assert.AreEqual(contactPerson.OrganisationID, organisation.OrganisationID);
            Assert.AreSame(organisation.ContactPerson, contactPerson);
            //---------------Execute Test ----------------------
            relationship.SetRelatedObject(null);
            //---------------Test Result -----------------------
            Assert.IsNull(contactPerson.OrganisationID);
            Assert.IsNull(organisation.ContactPerson);
            Assert.IsNotNull(organisation.OrganisationID);
            Assert.IsNull(contactPerson.Organisation);
        }