예제 #1
0
        public void Test_CreateBusinessObject()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO    organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            IMultipleRelationship cpRelationship     =
                (IMultipleRelationship)organisationTestBO.Relationships["ContactPeople"];
            RelatedBusinessObjectCollection <ContactPersonTestBO> cpCol =
                new RelatedBusinessObjectCollection <ContactPersonTestBO>(cpRelationship);

            cpCol.LoadAll();
            RegisterForAddedEvent(cpCol);

            //---------------Assert Precondition----------------
            Assert.AreEqual(0, cpCol.Count);
            Assert.IsFalse(_addedEventFired);
            Assert.AreEqual(0, cpCol.PersistedBusinessObjects.Count);

            //---------------Execute Test ----------------------
            ContactPersonTestBO newCP = cpCol.CreateBusinessObject();

            //---------------Test Result -----------------------
            AssertOneObjectInCurrentAndCreatedCollection(cpCol);

            Assert.Contains(newCP, cpCol.CreatedBusinessObjects);
            Assert.Contains(newCP, cpCol);
            Assert.IsFalse(cpCol.PersistedBusinessObjects.Contains(newCP));
            Assert.IsTrue(_addedEventFired);
        }
예제 #2
0
        public void Test_LoadMultiplerelationship_TimeOutExceeded_WhenTimeOutZero_UsingRelationship_DoesReloadFromDB()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            IClassDef orgClassDef = OrganisationTestBO.LoadDefaultClassDef();

            ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse();
            OrganisationTestBO        organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            IBusinessObjectCollection collection         = organisationTestBO.ContactPeople;
            DateTime?initialTimeLastLoaded = collection.TimeLastLoaded;

            //---------------Assert Precondition----------------
            Assert.IsNotNull(collection.TimeLastLoaded);
            Assert.AreEqual(initialTimeLastLoaded, collection.TimeLastLoaded);
            Assert.AreEqual(0, collection.Count);
            MultipleRelationship <ContactPersonTestBO> relationship = (MultipleRelationship <ContactPersonTestBO>)organisationTestBO.Relationships["ContactPeople"];

            Assert.AreEqual(0, relationship.TimeOut);
            //---------------Execute Test ----------------------
            ContactPersonTestBO contactPerson = organisationTestBO.ContactPeople.CreateBusinessObject();

            contactPerson.Surname   = TestUtil.GetRandomString();
            contactPerson.FirstName = TestUtil.GetRandomString();
            contactPerson.Save();
            TestUtil.Wait(100);
            IBusinessObjectCollection secondCollectionCall = organisationTestBO.ContactPeople;

            //---------------Test Result -----------------------
            Assert.AreSame(collection, secondCollectionCall);
            Assert.IsNotNull(secondCollectionCall.TimeLastLoaded);
            Assert.AreEqual(1, secondCollectionCall.Count);
            Assert.AreNotEqual(initialTimeLastLoaded, secondCollectionCall.TimeLastLoaded);
        }
        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();
        }
예제 #4
0
        public void Test_LoadMultiplerelationship_TimeOutNotExceeded_DoesNotReloadFromDB()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            IClassDef orgClassDef = OrganisationTestBO.LoadDefaultClassDef();

            ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse();
            OrganisationTestBO        organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            RelationshipDef           relationshipDef    = (RelationshipDef)orgClassDef.RelationshipDefCol["ContactPeople"];
            IMultipleRelationship     rel        = new MultipleRelationship <ContactPersonTestBO>(organisationTestBO, relationshipDef, organisationTestBO.Props, 30000);
            IBusinessObjectCollection collection = rel.BusinessObjectCollection;
            DateTime?initialTimeLastLoaded       = collection.TimeLastLoaded;

            //---------------Assert Precondition----------------
            Assert.AreEqual(initialTimeLastLoaded, collection.TimeLastLoaded);
            Assert.AreEqual(0, collection.Count);
            //---------------Execute Test ----------------------
            ContactPersonTestBO contactPerson = organisationTestBO.ContactPeople.CreateBusinessObject();

            contactPerson.Surname   = TestUtil.GetRandomString();
            contactPerson.FirstName = TestUtil.GetRandomString();
            contactPerson.Save();
            TestUtil.Wait(100);
            IBusinessObjectCollection secondCollectionCall = rel.BusinessObjectCollection;

            //---------------Test Result -----------------------
            Assert.AreSame(collection, secondCollectionCall);
            Assert.AreEqual(0, secondCollectionCall.Count);
            Assert.AreEqual(initialTimeLastLoaded, secondCollectionCall.TimeLastLoaded);
        }
예제 #5
0
        public void Test_LoadMultiplerelationship_TimeOutExceeded_WhenTimeOutZero_UsingRelationship_DoesResetTheTimeLastLoaded()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            IClassDef orgClassDef = OrganisationTestBO.LoadDefaultClassDef();

            ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse();
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            RelationshipDef    relationshipDef    = (RelationshipDef)orgClassDef.RelationshipDefCol["ContactPeople"];
            //IMultipleRelationship rel = new MultipleRelationship<ContactPersonTestBO>(organisationTestBO, relationshipDef, organisationTestBO.Props, 0);
            IBusinessObjectCollection collection = organisationTestBO.ContactPeople;
            DateTime?initialTimeLastLoaded       = collection.TimeLastLoaded;

            //---------------Assert Precondition----------------
            Assert.IsNotNull(collection.TimeLastLoaded);
            Assert.AreEqual(initialTimeLastLoaded, collection.TimeLastLoaded);
            //---------------Execute Test ----------------------
            TestUtil.Wait(100);
            IBusinessObjectCollection secondCollectionCall = organisationTestBO.ContactPeople;

            //---------------Test Result -----------------------
            Assert.AreSame(collection, secondCollectionCall);
            Assert.IsNotNull(secondCollectionCall.TimeLastLoaded);
            Assert.AreNotEqual(initialTimeLastLoaded, secondCollectionCall.TimeLastLoaded);
        }
예제 #6
0
        public void Test_GetDirtyChildren_ReturnAllDirty()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            BusinessObjectCollection <ContactPersonTestBO> cpCol;
            MultipleRelationship <ContactPersonTestBO>     relationship = GetAggregationRelationship(organisationTestBO, out cpCol);

            ContactPersonTestBO myBO_delete = ContactPersonTestBO.CreateSavedContactPerson_AsChild(cpCol);

            cpCol.MarkForDelete(myBO_delete);
            ContactPersonTestBO myBO_Edited = ContactPersonTestBO.CreateSavedContactPerson_AsChild(cpCol);

            myBO_Edited.Surname = TestUtil.GetRandomString();

            ContactPersonTestBO myBo_Created = ContactPersonTestBO.CreateUnsavedContactPerson_AsChild(cpCol);
            ContactPersonTestBO myBo_Removed = ContactPersonTestBO.CreateSavedContactPerson_AsChild(cpCol);

            cpCol.Remove(myBo_Removed);

            //---------------Execute Test ----------------------
            IList <ContactPersonTestBO> dirtyChildren = relationship.GetDirtyChildren();

            //---------------Test Result -----------------------
            Assert.Contains(myBO_delete, (ICollection)dirtyChildren);
            Assert.Contains(myBO_Edited, (ICollection)dirtyChildren);
            Assert.Contains(myBo_Created, (ICollection)dirtyChildren);
            Assert.Contains(myBo_Removed, (ICollection)dirtyChildren);
            Assert.AreEqual(4, dirtyChildren.Count);
        }
        public virtual void Test_RemovedChild_UpdatesRelatedPropertiesOnlyWhenParentSaves()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisation = OrganisationTestBO.CreateSavedOrganisation();
            SingleRelationship <ContactPersonTestBO> relationship = GetAssociationRelationship(organisation);

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

            organisation.ContactPerson = contactPerson;
            organisation.Save();
            contactPerson.Surname      = TestUtil.GetRandomString();
            organisation.ContactPerson = null;

            //---------------Assert PreConditions---------------
            Assert.IsTrue(contactPerson.Status.IsDirty);
            Assert.IsTrue(contactPerson.Props["OrganisationID"].IsDirty);
            Assert.IsNull(contactPerson.Props["OrganisationID"].Value);
            Assert.IsTrue(organisation.Status.IsDirty);

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

            //---------------Test Result -----------------------
            Assert.IsTrue(contactPerson.Status.IsDirty);
            Assert.IsFalse(contactPerson.Props["OrganisationID"].IsDirty);
            Assert.IsNull(contactPerson.Props["OrganisationID"].Value);
            Assert.IsFalse(organisation.Status.IsDirty);
        }
        public virtual void Test_AddedChild_UpdatesRelatedPropertiesOnlyWhenParentSaves()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisation = OrganisationTestBO.CreateSavedOrganisation();

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

            organisation.ContactPerson = contactPerson;
            contactPerson.Surname      = TestUtil.GetRandomString();

            //---------------Assert PreConditions---------------
            Assert.IsTrue(contactPerson.Status.IsDirty);
            Assert.IsTrue(contactPerson.Props["OrganisationID"].IsDirty);
            Assert.IsTrue(organisation.Status.IsDirty);

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

            //---------------Test Result -----------------------
            Assert.IsTrue(contactPerson.Status.IsDirty);
            Assert.IsFalse(contactPerson.Props["OrganisationID"].IsDirty);
            Assert.IsFalse(organisation.Status.IsDirty);

            //---------------Tear Down -------------------------
        }
예제 #9
0
        public void Test_CreatedBusinessObject_SaveBO()
        {
            //Saving a created business object should remove the business
            // object from the created col. it should still exist in
            // the main collection and should be added to the persisted collection
            //---------------Set up test pack-------------------
            OrganisationTestBO    organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            IMultipleRelationship cpRelationship     =
                (IMultipleRelationship)organisationTestBO.Relationships["ContactPeople"];
            RelatedBusinessObjectCollection <ContactPersonTestBO> cpCol =
                new RelatedBusinessObjectCollection <ContactPersonTestBO>(cpRelationship);

            cpCol.LoadAll();

            ContactPersonTestBO newCP = cpCol.CreateBusinessObject();

            newCP.Surname   = TestUtil.GetRandomString();
            newCP.FirstName = TestUtil.GetRandomString();
            RegisterForAddedEvent(cpCol);

            //---------------Assert Preconditions --------------
            Assert.IsFalse(_addedEventFired);
            AssertOneObjectInCurrentAndCreatedCollection(cpCol);

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

            //---------------Test Result -----------------------
            Assert.IsFalse(_addedEventFired);
            Assert.Contains(newCP, cpCol);
            AssertOneObjectInCurrentAndPersistedCollection(cpCol);
        }
        public virtual void Test_RemovedChild_UpdatesRelatedPropertiesOnlyWhenParentSaves()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            RelationshipDef    relationshipDef    =
                (RelationshipDef)organisationTestBO.Relationships["ContactPeople"].RelationshipDef;

            relationshipDef.RelationshipType = RelationshipType.Association;
            ContactPersonTestBO contactPerson = organisationTestBO.ContactPeople.CreateBusinessObject();

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

            contactPerson.Surname = TestUtil.GetRandomString();
            organisationTestBO.ContactPeople.Remove(contactPerson);

            //---------------Assert PreConditions---------------
            Assert.IsTrue(contactPerson.Status.IsDirty);
            Assert.IsTrue(contactPerson.Props["OrganisationID"].IsDirty);
            Assert.IsNull(contactPerson.Props["OrganisationID"].Value);
            Assert.IsTrue(organisationTestBO.Status.IsDirty);

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

            //---------------Test Result -----------------------
            Assert.IsTrue(contactPerson.Status.IsDirty);
            Assert.IsFalse(contactPerson.Props["OrganisationID"].IsDirty);
            Assert.IsNull(contactPerson.Props["OrganisationID"].Value);
            Assert.IsFalse(organisationTestBO.Status.IsDirty);
        }
예제 #11
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();
        }
        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());
        }
예제 #14
0
        public void Test_CancelEdits_CallsCancelEditsOnDirtyRelationshipsOnly()
        {
            //---------------Set up test pack-------------------
            new AddressTestBO();
            ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse();
            OrganisationTestBO.LoadDefaultClassDef_WithMultipleRelationshipToAddress();
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            RelationshipCol    relationshipCol    = new RelationshipCol(organisationTestBO);
            // Setup Mocks
            MockRepository   mockRepository       = new MockRepository();
            RelationshipBase dirtyRelationship    = mockRepository.PartialMock <RelationshipBase>();
            RelationshipBase nonDirtyRelationship = mockRepository.PartialMock <RelationshipBase>();

            Expect.Call(dirtyRelationship.RelationshipName).Return("DirtyRelationship").Repeat.Any();
            Expect.Call(dirtyRelationship.IsDirty).Return(true).Repeat.Once();
            Expect.Call(dirtyRelationship.CancelEdits).Repeat.Once();

            Expect.Call(nonDirtyRelationship.RelationshipName).Return("NonDirtyRelationship").Repeat.Any();
            Expect.Call(nonDirtyRelationship.IsDirty).Return(false).Repeat.Once();
            Expect.Call(nonDirtyRelationship.CancelEdits).Repeat.Never();
            mockRepository.ReplayAll();
            relationshipCol.Add(dirtyRelationship);
            relationshipCol.Add(nonDirtyRelationship);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            relationshipCol.CancelEdits();
            //---------------Test Result -----------------------
            mockRepository.VerifyAll();
        }
예제 #15
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);
            }
        }
예제 #16
0
        public void Test_CreateMultipleRelationshipDef_Association()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            ClassDef.ClassDefs.Clear();
            OrganisationTestBO.LoadDefaultClassDef();
            ContactPersonTestBO.LoadDefaultClassDef();
            RelPropDef relPropDef = new RelPropDef(ClassDef.Get <OrganisationTestBO>().PropDefcol["OrganisationID"], "OrganisationID");
            RelKeyDef  relKeyDef  = new RelKeyDef();

            relKeyDef.Add(relPropDef);
            const int expectedTimeout = 550;
            MultipleRelationshipDef relationshipDef = new MultipleRelationshipDef("ContactPeople", "Habanero.Test.BO",
                                                                                  "ContactPersonTestBO", relKeyDef, true, "", DeleteParentAction.DeleteRelated, InsertParentAction.InsertRelationship, RelationshipType.Association, expectedTimeout);
            OrganisationTestBO organisation = OrganisationTestBO.CreateSavedOrganisation();

            //---------------Assert Precondition----------------
            Assert.AreEqual(expectedTimeout, relationshipDef.TimeOut);
            //---------------Execute Test ----------------------
            MultipleRelationship <ContactPersonTestBO> relationship = (MultipleRelationship <ContactPersonTestBO>)relationshipDef.CreateRelationship(organisation, organisation.Props);

            //---------------Test Result -----------------------
            Assert.AreEqual(expectedTimeout, relationship.TimeOut);
            Assert.AreEqual(InsertParentAction.InsertRelationship, relationship.RelationshipDef.InsertParentAction);
        }
예제 #17
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);
            }
        }
        public virtual void Test_AddDirtyChildrenToTransactionCommitter_AddedChild()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            MultipleRelationship <ContactPersonTestBO> relationship =
                organisationTestBO.Relationships.GetMultiple <ContactPersonTestBO>("ContactPeople");
            RelationshipDef relationshipDef = (RelationshipDef)relationship.RelationshipDef;

            relationshipDef.RelationshipType = RelationshipType.Association;

            ContactPersonTestBO contactPerson = ContactPersonTestBO.CreateSavedContactPerson();

            relationship.BusinessObjectCollection.Add(contactPerson);
            SingleRelationship <OrganisationTestBO> reverseRelationship =
                contactPerson.Relationships.GetSingle <OrganisationTestBO>("Organisation");


            TransactionCommitter tc = (TransactionCommitter)BORegistry.DataAccessor.CreateTransactionCommitter();

            //---------------Assert PreConditions---------------
            Assert.AreEqual(0, tc.OriginalTransactions.Count);
            Assert.IsNotNull(reverseRelationship);

            //---------------Execute Test ----------------------
            relationship.AddDirtyChildrenToTransactionCommitter(tc);

            //---------------Test Result -----------------------
            Assert.AreEqual(1, tc.OriginalTransactions.Count);

            Assert.IsInstanceOf(typeof(TransactionalSingleRelationship_Added), tc.OriginalTransactions[0]);
            Assert.AreSame(relationship, ((TransactionalSingleRelationship_Added)tc.OriginalTransactions[0]).Relationship);
        }
예제 #19
0
        public void Test_PersistParent_PersistsDirtyChildren()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            RelationshipCol    relationships      = organisationTestBO.Relationships;
            BusinessObjectCollection <ContactPersonTestBO> cpCol;
            MultipleRelationship <ContactPersonTestBO>     aggregateRelationship = GetAggregationRelationship
                                                                                       (organisationTestBO, out cpCol);

            ContactPersonTestBO myBO = cpCol.CreateBusinessObject();

            myBO.Surname   = TestUtil.GetRandomString();
            myBO.FirstName = TestUtil.GetRandomString();
            myBO.Save();
            myBO.FirstName = TestUtil.GetRandomString();

            //---------------Assert Precondition----------------
            Assert.IsTrue(aggregateRelationship.IsDirty);
            Assert.IsTrue(myBO.Status.IsDirty);
            Assert.IsTrue(relationships.IsDirty);
            Assert.IsTrue(organisationTestBO.Status.IsDirty);

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

            //---------------Test Result -----------------------
            Assert.IsFalse(myBO.Status.IsDirty);
            Assert.IsFalse(aggregateRelationship.IsDirty);
            Assert.IsFalse(relationships.IsDirty);
            Assert.IsFalse(organisationTestBO.Status.IsDirty);
        }
        public void Test_GetDirtyChildren_MarkedForDelete()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            SingleRelationship <ContactPersonTestBO> relationship = GetAssociationRelationship(organisationTestBO);
            ContactPersonTestBO myBO = new ContactPersonTestBO();

            myBO.Surname      = TestUtil.GetRandomString();
            myBO.FirstName    = TestUtil.GetRandomString();
            myBO.Organisation = organisationTestBO;
            organisationTestBO.Save();
            ReflectionUtilities.SetPropertyValue(myBO.Status, "IsDeleted", true);
            //ReflectionUtilities.SetPropertyValue(myBO.Status, "IsDirty", true);

            //---------------Assert Preconditions---------------
            Assert.IsTrue(myBO.Status.IsDeleted);
            Assert.IsTrue(myBO.Status.IsDirty);
            //---------------Execute Test ----------------------

            IList <ContactPersonTestBO> dirtyChildren = relationship.GetDirtyChildren();

            //---------------Test Result -----------------------
            Assert.AreEqual(1, dirtyChildren.Count);
            Assert.Contains(myBO, (ICollection)dirtyChildren);
        }
        public void Test_AddedChild_UpdatesRelatedPropertiesOnlyWhenParentSaves_OnlyIDChanged()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO  organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            ContactPersonTestBO contactPerson      = ContactPersonTestBO.CreateSavedContactPerson();
            RelationshipDef     relationshipDef    =
                (RelationshipDef)organisationTestBO.Relationships["ContactPeople"].RelationshipDef;

            relationshipDef.RelationshipType = RelationshipType.Association;
            organisationTestBO.ContactPeople.Add(contactPerson);

            //---------------Assert PreConditions---------------
            Assert.IsTrue(contactPerson.Status.IsDirty);
            Assert.IsTrue(contactPerson.Props["OrganisationID"].IsDirty);
            Assert.IsTrue(organisationTestBO.Status.IsDirty);

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

            //---------------Test Result -----------------------
            Assert.IsFalse(contactPerson.Status.IsDirty);
            Assert.IsFalse(contactPerson.Props["OrganisationID"].IsDirty);
            Assert.IsFalse(organisationTestBO.Status.IsDirty);

            //---------------Tear Down -------------------------
        }
예제 #22
0
        public void Test_ItemsShowingInComboBox()
        {
            //--------------- Set up test pack ------------------

            ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();

            contactPersonTestBO.Surname   = TestUtil.GetRandomString();
            contactPersonTestBO.FirstName = TestUtil.GetRandomString();
            OrganisationTestBO.LoadDefaultClassDef();
            OrganisationTestBO.CreateSavedOrganisation();
            OrganisationTestBO.CreateSavedOrganisation();

            IControlFactory       controlFactory     = GetControlFactory();
            ExtendedTextBoxWin    extendedTextBoxWin = new ExtendedTextBoxWin(controlFactory);
            const string          propName           = "OrganisationID";
            ExtendedTextBoxMapper mapper             = new ExtendedTextBoxMapper(
                extendedTextBoxWin, propName, true, controlFactory);

            //--------------- Test Preconditions ----------------
            Assert.IsNull(mapper.BusinessObject);
            Assert.IsNull(mapper.BusinessObject);

            //--------------- Execute Test ----------------------
            mapper.BusinessObject = contactPersonTestBO;
            //--------------- Test Result -----------------------
            Assert.AreSame(contactPersonTestBO, mapper.BusinessObject);
            Assert.AreSame(contactPersonTestBO, mapper.BusinessObject);
//            Assert.AreEqual(2, mapper.LookupList.Count);
        }
        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);
        }
 protected MultipleRelationship <ContactPersonTestBO> GetRelationship(
     out OrganisationTestBO organisationTestBO, out RelationshipCol relationships,
     out BusinessObjectCollection <ContactPersonTestBO> cpCol)
 {
     organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
     relationships      = organisationTestBO.Relationships;
     return(GetRelationship(organisationTestBO, out cpCol));
 }
예제 #25
0
        private static RelatedBusinessObjectCollection <ContactPersonTestBO> CreateRelatedCPCol()
        {
            OrganisationTestBO    organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            IMultipleRelationship cpRelationship     =
                (IMultipleRelationship)organisationTestBO.Relationships["ContactPeople"];

            return(new RelatedBusinessObjectCollection <ContactPersonTestBO>(cpRelationship));
        }
        private static ContactPersonTestBO CreateSavedContactPersonTestBoAndOrganisation()
        {
            OrganisationTestBO  organisationTestBO  = OrganisationTestBO.CreateSavedOrganisation();
            ContactPersonTestBO contactPersonTestBO = organisationTestBO.ContactPeople.CreateBusinessObject();

            contactPersonTestBO.Surname   = TestUtil.GetRandomString();
            contactPersonTestBO.FirstName = TestUtil.GetRandomString();
            organisationTestBO.Save();
            contactPersonTestBO.Save();
            return(contactPersonTestBO);
        }
예제 #27
0
        //[Test]
        //public void Test_ShowGridAndBOEditorControlWinWithSuperClassDef_DatabaseLookupList()
        //{
        //    //--------------- Set up test pack ------------------
        //    ClassDef.ClassDefs.Clear();
        //    OrganisationTestBO.LoadDefaultClassDef();
        //    ContactPersonTestBO.LoadDefaultClassDefWithPersonTestBOSuperClass();
        //    PersonTestBO.LoadDefaultClassDefWithTestOrganisationBOLookup_DatabaseLookupList();

        //    IControlFactory controlFactory = GetControlFactory();
        //    IExtendedComboBox extendedComboBox = CreateExtendedComboBox();
        //    const string propName = "OrganisationID";
        //    ExtendedComboBoxMapper mapper = new ExtendedComboBoxMapper(
        //        extendedComboBox, propName, true, controlFactory);
        //    DatabaseConfig databaseConfig = TestUtil.GetDatabaseConfig();
        //    DatabaseConnection.CurrentConnection = databaseConfig.GetDatabaseConnection();
        //    mapper.BusinessObject = new ContactPersonTestBO();
        //   // mapper.RelatedBusinessObject = OrganisationTestBO.CreateSavedOrganisation();
        //    //--------------- Test Preconditions ----------------
        //    Assert.IsNull(mapper.PopupForm);
        //    //--------------- Execute Test ----------------------
        //    //extendedComboBox.Button.PerformClick();
        //    mapper.SetupPopupForm();
        //    //--------------- Test Result -----------------------
        //    Assert.IsNotNull(mapper.PopupForm);
        //}

        private static BusinessObjectCollection <OrganisationTestBO> CreateSavedOrganisationTestBOSCollection()
        {
            OrganisationTestBO.LoadDefaultClassDef();
            BusinessObjectCollection <OrganisationTestBO> organisationTestBOS = new BusinessObjectCollection <OrganisationTestBO>();

            organisationTestBOS.Add(OrganisationTestBO.CreateSavedOrganisation());
            organisationTestBOS.Add(OrganisationTestBO.CreateSavedOrganisation());
            organisationTestBOS.Add(OrganisationTestBO.CreateSavedOrganisation());
            organisationTestBOS.Add(OrganisationTestBO.CreateSavedOrganisation());
            return(organisationTestBOS);
        }
예제 #28
0
        private static BusinessObjectCollection <OrganisationTestBO> CreateSavedOrganisationTestBOsCollection()
        {
            OrganisationTestBO.LoadDefaultClassDef();
            BusinessObjectCollection <OrganisationTestBO> organisationTestBOs = new BusinessObjectCollection <OrganisationTestBO>
            {
                OrganisationTestBO.CreateSavedOrganisation(),
                                                          OrganisationTestBO.CreateSavedOrganisation(),
                                                          OrganisationTestBO.CreateSavedOrganisation(),
                                                          OrganisationTestBO.CreateSavedOrganisation()
            };

            return(organisationTestBOs);
        }
예제 #29
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);
        }
예제 #30
0
        public void Test_LoadBoCol_Generic()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisation = OrganisationTestBO.CreateSavedOrganisation();

            CreateSavedContactPerson(organisation);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            RelatedBusinessObjectCollection <ContactPersonTestBO> cpCol = CreateRelatedCPCol(organisation);

            //---------------Test Result -----------------------
            AssertOneObjectInCurrentAndPersistedCollection(cpCol);
        }