Ejemplo n.º 1
0
        public void TestDontGetTheFreshestObject_Strategy()
        {
            //------------------------------Setup Test
            ClassDef.ClassDefs.Clear();
            SetupDefaultContactPersonBO();
            ContactPersonTestBO originalContactPerson = new ContactPersonTestBO();

            originalContactPerson.Surname = "FirstSurname";
            originalContactPerson.Save();
            IPrimaryKey origCPID = originalContactPerson.ID;

            BORegistry.BusinessObjectManager = new BusinessObjectManagerSpy();//Ensures a new BOMan is created and used for each test


            //load second object from DB to ensure that it is now in the object manager
            ContactPersonTestBO myContact2 =
                BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <ContactPersonTestBO>(origCPID);

            //-----------------------------Execute Test-------------------------
            //Edit first object and save
            originalContactPerson.Surname = "SecondSurname";
            originalContactPerson.Save();

            ContactPersonTestBO myContact3 =
                BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <ContactPersonTestBO>(origCPID);

            //-----------------------------Assert Result-----------------------
            Assert.AreSame(myContact3, myContact2);
            //The two surnames should be equal since the myContact3 was refreshed
            // when it was loaded.
            Assert.AreNotEqual(originalContactPerson.Surname, myContact3.Surname);
            //Just to check the myContact2 should also match since it is physically the
            // same object as myContact3
            Assert.AreNotEqual(originalContactPerson.Surname, myContact2.Surname);
        }
Ejemplo n.º 2
0
        public void Test_Refresh_AfterLoadIsCalled_IfObjectUpdatedInLoading()
        {
            //---------------Set up test pack---------------------
            ClassDef.ClassDefs.Clear();
            SetupDefaultContactPersonBO();

            ContactPersonTestBO cp = new ContactPersonTestBO();

            cp.Surname = Guid.NewGuid().ToString();
            cp.Save();
            FixtureEnvironment.ClearBusinessObjectManager();

            ContactPersonTestBO cpLoaded =
                BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <ContactPersonTestBO>(cp.ID);
            string newFirstname = cp.FirstName = TestUtil.GetRandomString();

            cp.Save();
            cpLoaded.AfterLoadCalled = false;

            //---------------Assert Precondition------------------
            Assert.IsFalse(cpLoaded.AfterLoadCalled);

            //---------------Execute Test ------------------------
            BORegistry.DataAccessor.BusinessObjectLoader.Refresh(cpLoaded);

            //---------------Test Result -------------------------
            Assert.IsTrue(cpLoaded.AfterLoadCalled);
            Assert.AreNotSame(cp, cpLoaded);

            Assert.AreEqual(cp.FirstName, cpLoaded.FirstName);
            Assert.AreEqual(newFirstname, cpLoaded.FirstName);
        }
Ejemplo n.º 3
0
        public void Test_Refresh_UpdatedEventIsFired_IfObjectUpdatedInLoading()
        {
            //---------------Set up test pack---------------------
            ClassDef.ClassDefs.Clear();
            SetupDefaultContactPersonBO();

            ContactPersonTestBO cp = new ContactPersonTestBO();

            cp.Surname = Guid.NewGuid().ToString();
            cp.Save();
            FixtureEnvironment.ClearBusinessObjectManager();

            ContactPersonTestBO cpLoaded =
                BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <ContactPersonTestBO>(cp.ID);
            string newFirstname = cp.FirstName = TestUtil.GetRandomString();

            cp.Save();
            bool updatedEventFired = false;

            cpLoaded.Updated += (sender, args) => updatedEventFired = true;

            //---------------Assert Precondition------------------
            Assert.IsFalse(updatedEventFired);

            //---------------Execute Test ------------------------
            BORegistry.DataAccessor.BusinessObjectLoader.Refresh(cpLoaded);

            //---------------Test Result -------------------------
            Assert.IsTrue(updatedEventFired);
        }
Ejemplo n.º 4
0
        public void Test_SavedObject_Twice_AddedToObjectManager_Once()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO.LoadDefaultClassDef();
            BusinessObjectManager boMan = BusinessObjectManager.Instance;

            ContactPersonTestBO cp = new ContactPersonTestBO();

            cp.Surname = TestUtil.CreateRandomString();
            cp.Save();
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, boMan.Count);
            Assert.IsTrue(boMan.Contains(cp));

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

            cp.Surname = TestUtil.CreateRandomString();
            cp.Save();

            //---------------Test Result -----------------------
            Assert.AreEqual(1, boMan.Count);
            Assert.IsTrue(boMan.Contains(cp));
            Assert.IsTrue(boMan.Contains(cp.ID));
            Assert.IsTrue(boMan.Contains(cp.ID.GetObjectId()));
            Assert.AreSame(cp, boMan[cp.ID.GetObjectId()]);
            Assert.AreSame(cp, boMan[cp.ID]);
        }
Ejemplo n.º 5
0
        public void TestFindAll_UsingClassDef()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory(new DataStoreInMemory());
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadDefaultClassDef();
            OrganisationTestBO.LoadDefaultClassDef();
            DataStoreInMemory   dataStore = new DataStoreInMemory();
            DateTime            now       = DateTime.Now;
            ContactPersonTestBO cp1       = new ContactPersonTestBO();

            cp1.DateOfBirth = now;
            cp1.Surname     = TestUtil.GetRandomString();
            cp1.Save();
            dataStore.Add(cp1);
            ContactPersonTestBO cp2 = new ContactPersonTestBO();

            cp2.DateOfBirth = now;
            cp2.Surname     = TestUtil.GetRandomString();
            cp2.Save();
            dataStore.Add(cp2);
            Criteria criteria = new Criteria("DateOfBirth", Criteria.ComparisonOp.Equals, now);

            dataStore.Add(OrganisationTestBO.CreateSavedOrganisation());
            //---------------Execute Test ----------------------
            IBusinessObjectCollection col = dataStore.FindAll(ClassDef.Get <ContactPersonTestBO>(), criteria);

            //---------------Test Result -----------------------
            Assert.AreEqual(2, col.Count);
            Assert.Contains(cp1, col);
            Assert.Contains(cp2, col);
        }
Ejemplo n.º 6
0
        public void TestFind_UsingGuidCriteriaString_Typed()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory(new DataStoreInMemory());
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadDefaultClassDef_WOrganisationID();
            OrganisationTestBO.LoadDefaultClassDef();
            ContactPersonTestBO cp = new ContactPersonTestBO {
                Surname = Guid.NewGuid().ToString("N")
            };

            cp.OrganisationID = OrganisationTestBO.CreateSavedOrganisation().OrganisationID;
            cp.Save();
            DataStoreInMemory dataStore = new DataStoreInMemory();

            dataStore.Add(cp);
            Criteria criteria = CriteriaParser.CreateCriteria("OrganisationID = " + cp.OrganisationID);

            //---------------Assert Precondtions---------------
            Assert.IsNotNull(cp.OrganisationID);
            //---------------Execute Test ----------------------
            ContactPersonTestBO loadedCP = dataStore.Find <ContactPersonTestBO>(criteria);

            //---------------Test Result -----------------------
            Assert.IsNotNull(loadedCP);
            Assert.AreSame(cp.ID, loadedCP.ID);
        }
        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();
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
        public void Test_UpdateStateAsCommitted_Removed_UpdatesCols()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO contactPersonTestBO = ContactPersonTestBO.CreateSavedContactPerson();
            OrganisationTestBO  organisationTestBO  = new OrganisationTestBO();

            SingleRelationship <OrganisationTestBO>        singleRelationship = contactPersonTestBO.Relationships.GetSingle <OrganisationTestBO>("Organisation");
            BusinessObjectCollection <ContactPersonTestBO> people             = organisationTestBO.ContactPeople;

            organisationTestBO.Save();
            contactPersonTestBO.Organisation = organisationTestBO;
            contactPersonTestBO.Save();
            contactPersonTestBO.Organisation = null;
            IRelationship relationship = organisationTestBO.Relationships.GetMultiple <ContactPersonTestBO>("ContactPeople");
            TransactionalSingleRelationship_Removed tsr = new TransactionalSingleRelationship_Removed(relationship, contactPersonTestBO);

            //---------------Assert PreConditions---------------

            Assert.AreEqual(1, people.RemovedBusinessObjects.Count);
            Assert.AreEqual(1, people.PersistedBusinessObjects.Count);
            Assert.IsTrue(singleRelationship.IsRemoved);
            //---------------Execute Test ----------------------

            tsr.UpdateStateAsCommitted();
            //---------------Test Result -----------------------

            Assert.AreEqual(0, people.RemovedBusinessObjects.Count);
            Assert.AreEqual(0, people.PersistedBusinessObjects.Count);
//            Assert.IsFalse(singleRelationship.IsRemoved);
            //---------------Tear Down -------------------------
        }
Ejemplo n.º 11
0
        public void Test_Refresh_W_CreatedBOs_CreatedObjectsStillRespondToEvents()
        {
            //---------------Set up test pack-------------------
            BusinessObjectCollection <ContactPersonTestBO> cpCol = CreateCollectionWith_OneBO();

            ContactPersonTestBO createdCp = cpCol.CreateBusinessObject();

            createdCp.Surname = BOTestUtils.RandomString;
            RegisterForAddedAndRemovedEvents(cpCol);

            //---------------Assert Precondition----------------
            Assert.AreEqual(2, cpCol.Count);
            Assert.AreEqual(1, cpCol.CreatedBusinessObjects.Count);
            Assert.AreEqual(1, cpCol.PersistedBusinessObjects.Count);

            //---------------Execute Test ----------------------
            cpCol.Refresh();
            createdCp.Save();

            //---------------Test Result -----------------------
            Assert.AreEqual(2, cpCol.Count);
            Assert.AreEqual(0, cpCol.CreatedBusinessObjects.Count);
            Assert.AreEqual(2, cpCol.PersistedBusinessObjects.Count);
            AssertAddedAndRemovedEventsNotFired();
        }
Ejemplo n.º 12
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-------------------
            //ContactPersonTestBO.LoadDefaultClassDef();

            BusinessObjectCollection <ContactPersonTestBO> cpCol = new BusinessObjectCollection <ContactPersonTestBO>();

            cpCol.LoadAll();

            ContactPersonTestBO newCP = cpCol.CreateBusinessObject();

            newCP.Surname = 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);
        }
Ejemplo n.º 13
0
        public void Test3LayerLoadRelated()
        {
            //---------------Set up test pack-------------------
            BusinessObjectManager.Instance.ClearLoadedObjects();
            ContactPersonTestBO.DeleteAllContactPeople();
            BORegistry.DataAccessor = new DataAccessorDB();
            OrganisationTestBO.LoadDefaultClassDef();
            TestUtil.WaitForGC();
            Address             address;
            ContactPersonTestBO contactPersonTestBO =
                ContactPersonTestBO.CreateContactPersonWithOneAddress_CascadeDelete(out address);

            OrganisationTestBO org = new OrganisationTestBO();

            contactPersonTestBO.SetPropertyValue("OrganisationID", org.OrganisationID);
            org.Save();
            contactPersonTestBO.Save();

            //---------------Assert Preconditions --------------
            Assert.AreEqual(3, BusinessObjectManager.Instance.Count);

            //---------------Execute Test ----------------------
            IBusinessObjectCollection colContactPeople = org.Relationships["ContactPeople"].GetRelatedBusinessObjectCol();
            ContactPersonTestBO       loadedCP         = (ContactPersonTestBO)colContactPeople[0];
            IBusinessObjectCollection colAddresses     = loadedCP.Relationships["Addresses"].GetRelatedBusinessObjectCol();
            Address loadedAdddress = (Address)colAddresses[0];

            //---------------Test Result -----------------------
            Assert.AreEqual(3, BusinessObjectManager.Instance.Count);
            Assert.AreEqual(1, colAddresses.Count);
            Assert.AreSame(contactPersonTestBO, loadedCP);
            Assert.AreSame(address, loadedAdddress);
        }
Ejemplo n.º 14
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);
        }
Ejemplo n.º 15
0
        public void Test_RemoveCreatedBo_DeregistersForSaveEvent()
        {
            //If you remove a created business object that is not yet persisted then
            //-- remove from the restored and saved event.
            //-- when the object is saved it should be independent of the collection.
            //---------------Set up test pack-------------------
            RelatedBusinessObjectCollection <ContactPersonTestBO> cpCol = CreateCollectionWith_OneBO();
            ContactPersonTestBO createdCp = cpCol.CreateBusinessObject();

            createdCp.Surname   = BOTestUtils.RandomString;
            createdCp.FirstName = BOTestUtils.RandomString;
            cpCol.Remove(createdCp);
            RegisterForAddedAndRemovedEvents(cpCol);
            //---------------Assert Precondition----------------
            AssertOneObjectInCurrentAndPersistedCollection(cpCol);
            Assert.IsFalse(cpCol.Contains(createdCp));

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

            //---------------Test Result -----------------------
            AssertOneObjectInCurrentAndPersistedCollection(cpCol);
            Assert.IsFalse(cpCol.Contains(createdCp));
            AssertAddedAndRemovedEventsNotFired();
        }
        public void Test_SetParentNull_PersistedChild()
        {
            //---------------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;
            contactPerson.Save();
            //---------------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);
            }
        }
Ejemplo n.º 17
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_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);
        }
        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);
        }
Ejemplo n.º 20
0
        public void TestBoLoader_RefreshBusinessObjectDeletedByAnotherUser()
        {
            //-------------Setup Test Pack------------------
            SetupDefaultContactPersonBO();
            ContactPersonTestBO cpTemp = ContactPersonTestBO.CreateSavedContactPerson();

            FixtureEnvironment.ClearBusinessObjectManager();

            ContactPersonTestBO cpLoaded =
                BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <ContactPersonTestBO>(cpTemp.ID);

            cpTemp.MarkForDelete();
            cpTemp.Save();

            //-------------Execute Test ---------------------
            try
            {
                BORegistry.DataAccessor.BusinessObjectLoader.Refresh(cpLoaded);
                Assert.Fail();
            }
            //-------------Test Result ---------------------
            catch (BusObjDeleteConcurrencyControlException ex)
            {
                StringAssert.Contains
                    ("A Error has occured since the object you are trying to refresh has been deleted by another user.",
                    ex.Message);
                StringAssert.Contains("There are no records in the database for the Class", ex.Message);
                StringAssert.Contains("ContactPersonTestBO", ex.Message);
                StringAssert.Contains(cpLoaded.ID.ToString(), ex.Message);
            }
        }
Ejemplo n.º 21
0
        public void TestGetTheFreshestObject_Strategy()
        {
            //------------------------------Setup Test----------------------------
            SetupDefaultContactPersonBO();
            ContactPersonTestBO originalContactPerson = new ContactPersonTestBO();

            originalContactPerson.Surname = "FirstSurname";
            originalContactPerson.Save();

            FixtureEnvironment.ClearBusinessObjectManager();

            //load second object from DB to ensure that it is now in the object manager
            ContactPersonTestBO myContact2 =
                BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <ContactPersonTestBO>
                    (originalContactPerson.ID);

            //-----------------------------Assert Precondition -----------------
            Assert.AreNotSame(originalContactPerson, myContact2);
            IPrimaryKey id = myContact2.ID;

            Assert.IsTrue(BORegistry.BusinessObjectManager.Contains(id));
            IBusinessObject boFromAllLoadedObjects = BORegistry.BusinessObjectManager[id];

            Assert.AreSame(boFromAllLoadedObjects, myContact2);
            Assert.IsFalse(myContact2.Status.IsEditing);

            //-----------------------------Execute Test-------------------------
            //Edit first object and save
            originalContactPerson.Surname = "SecondSurname";
            originalContactPerson.Save();

            ContactPersonTestBO myContact3 =
                BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject <ContactPersonTestBO>
                    (originalContactPerson.ID);

            //-----------------------------Assert Result-----------------------
            Assert.IsFalse(myContact3.Status.IsEditing);
            Assert.AreNotSame(originalContactPerson, myContact3);
            Assert.IsTrue(BORegistry.BusinessObjectManager.Contains(myContact3));
            Assert.AreSame(myContact3, myContact2);
            //The two surnames should be equal since the myContact3 was refreshed
            // when it was loaded.
            Assert.AreEqual(originalContactPerson.Surname, myContact3.Surname);
            //Just to check the myContact2 should also match since it is physically the
            // same object as myContact3
            Assert.AreEqual(originalContactPerson.Surname, myContact2.Surname);
        }
 private static ContactPersonTestBO CreateContactPersonTestBO()
 {
     ContactPersonTestBO bo = new ContactPersonTestBO();
     string newSurname = Guid.NewGuid().ToString();
     bo.Surname = newSurname;
     bo.Save();
     return bo;
 }
        private static void CreateContactPersonInDB_With_SSSSS_InSurname()
        {
            ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();

            contactPersonTestBO.Surname = Guid.NewGuid().ToString("N") + "SSSSS";
            contactPersonTestBO.Save();
            return;
        }
        private static ContactPersonTestBO CreateContactPersonTestBO()
        {
            var bo         = new ContactPersonTestBO();
            var newSurname = Guid.NewGuid().ToString();

            bo.Surname = newSurname;
            bo.Save();
            return(bo);
        }
Ejemplo n.º 25
0
        private static ContactPersonTestBO CreateSavedCP()
        {
            ContactPersonTestBO cp = new ContactPersonTestBO();

            cp.Surname   = TestUtil.CreateRandomString();
            cp.FirstName = TestUtil.CreateRandomString();
            cp.Save();
            return(cp);
        }
        private ContactPersonTestBO CreateContactPerson(DateTime now)
        {
            ContactPersonTestBO cp1 = new ContactPersonTestBO();

            cp1.DateOfBirth = now;
            cp1.Surname     = Guid.NewGuid().ToString("N");
            cp1.Save();
            return(cp1);
        }
        protected static ContactPersonTestBO CreateExistingChild(BusinessObjectCollection <ContactPersonTestBO> cpCol)
        {
            ContactPersonTestBO existingChildEdited = cpCol.CreateBusinessObject();

            existingChildEdited.Surname   = TestUtil.GetRandomString();
            existingChildEdited.FirstName = TestUtil.GetRandomString();
            existingChildEdited.Save();
            return(existingChildEdited);
        }
        private ContactPersonTestBO CreateContactPerson(string surname)
        {
            var cp1 = new ContactPersonTestBO();

            cp1.Surname   = surname;
            cp1.FirstName = Guid.NewGuid().ToString("N");
            cp1.Save();
            return(cp1);
        }
Ejemplo n.º 29
0
        private static ContactPersonTestBO CreateSavedContactPerson(OrganisationTestBO organisation)
        {
            MultipleRelationship <ContactPersonTestBO> relationship = GetContactPersonRelationship(organisation);
            ContactPersonTestBO cp = relationship.BusinessObjectCollection.CreateBusinessObject();

            cp.Surname   = TestUtil.GetRandomString();
            cp.FirstName = TestUtil.GetRandomString();
            cp.Save();
            return(cp);
        }
Ejemplo n.º 30
0
        public void Test_CreatedBusinessObject_SavedTwice()
        {
            //---------------Set up test pack-------------------
            //ContactPersonTestBO.LoadDefaultClassDef();
            BusinessObjectCollection <ContactPersonTestBO> cpCol = new BusinessObjectCollection <ContactPersonTestBO>();
            ContactPersonTestBO newCP = cpCol.CreateBusinessObject();

            newCP.Surname = TestUtil.GetRandomString();
            newCP.Save();

            //---------------Assert Precondition----------------
            AssertOneObjectInCurrentAndPersistedCollection(cpCol);

            //---------------Execute Test ----------------------
            newCP.Surname = TestUtil.GetRandomString();
            newCP.Save();

            //---------------Test Result -----------------------
            AssertOneObjectInCurrentAndPersistedCollection(cpCol);
        }
        public void TestNowDateStringCriteria()
        {
            DeleteAllContactPeople();
            BusinessObjectCollection <ContactPersonTestBO> myCol = new BusinessObjectCollection <ContactPersonTestBO>();

            myCol.LoadAll();
            Assert.AreEqual(0, myCol.Count);
            ContactPersonTestBO contactPerson1 = new ContactPersonTestBO();

            contactPerson1.Surname     = "aaa";
            contactPerson1.DateOfBirth = DateTime.Now.AddMinutes(-1);
            contactPerson1.Save();
            ContactPersonTestBO contactPerson2 = new ContactPersonTestBO();

            contactPerson2.Surname     = "bbb";
            contactPerson2.DateOfBirth = DateTime.Now.AddMinutes(-1);
            contactPerson2.Save();
            ContactPersonTestBO contactPerson3 = new ContactPersonTestBO();

            contactPerson3.Surname     = "ccc";
            contactPerson3.DateOfBirth = DateTime.Now.AddMinutes(-1);
            contactPerson3.Save();

            //ContactPersonTestBO.ClearObjectManager();
            BusinessObjectLookupList businessObjectLookupList = new BusinessObjectLookupList("Habanero.Test.BO",
                                                                                             "ContactPersonTestBO", "DateOfBirth < 'Now'", "");

            businessObjectLookupList.PropDef = new PropDef("name", typeof(string), PropReadWriteRule.ReadWrite, null);
            Dictionary <string, string> col = businessObjectLookupList.GetLookupList(DatabaseConnection.CurrentConnection);

            Assert.AreEqual(3, col.Count);
            Assert.IsTrue(col.ContainsValue(GuidToString(contactPerson1.ID.GetAsGuid())));
            Assert.IsTrue(col.ContainsValue(GuidToString(contactPerson2.ID.GetAsGuid())));
            Assert.IsTrue(col.ContainsValue(GuidToString(contactPerson3.ID.GetAsGuid())));
            businessObjectLookupList = new BusinessObjectLookupList("Habanero.Test.BO",
                                                                    "ContactPersonTestBO", "DateOfBirth > 'now'", "")
            {
                PropDef = new PropDef("name", typeof(string), PropReadWriteRule.ReadWrite, null)
            };
            col = businessObjectLookupList.GetLookupList(DatabaseConnection.CurrentConnection);
            Assert.AreEqual(0, col.Count);
            ContactPersonTestBO contactPerson4 = new ContactPersonTestBO();

            contactPerson4.Surname     = "ddd";
            contactPerson4.DateOfBirth = DateTime.Now.AddMinutes(5);
            contactPerson4.Save();
            businessObjectLookupList = new BusinessObjectLookupList("Habanero.Test.BO",
                                                                    "ContactPersonTestBO", "DateOfBirth > NOW", "");
            businessObjectLookupList.PropDef = new PropDef("name", typeof(string), PropReadWriteRule.ReadWrite, null);

            col = businessObjectLookupList.GetLookupList(DatabaseConnection.CurrentConnection);
            Assert.AreEqual(1, col.Count);
            Assert.IsTrue(col.ContainsValue(GuidToString(contactPerson4.ID.GetAsGuid())));
        }
Ejemplo n.º 32
0
 public void Test_SetToNull()
 {
     //---------------Set up test pack-------------------
     OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
     SingleRelationship<ContactPersonTestBO> relationship = GetAssociationRelationship(organisationTestBO);
     relationship.OwningBOHasForeignKey = false;
     ContactPersonTestBO contactPerson = new ContactPersonTestBO();
     contactPerson.Surname = TestUtil.GetRandomString();
     contactPerson.FirstName = TestUtil.GetRandomString();
     contactPerson.Organisation = organisationTestBO;
     contactPerson.Save();
     //---------------Assert Precondition----------------
     Assert.AreSame(contactPerson, organisationTestBO.ContactPerson);
     //---------------Execute Test ----------------------
     organisationTestBO.ContactPerson = null;
     //---------------Test Result -----------------------
     Assert.IsNull(organisationTestBO.ContactPerson);
 }
        public void Test_ConcurrentSave()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            var classDef = ContactPersonTestBO.LoadDefaultClassDef();
            FixtureEnvironment.ClearBusinessObjectManager();
            TestUtil.WaitForGC();
            
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            Parallel.For(0, 1000, i =>
                                  {
                                      var person = new ContactPersonTestBO();
                                      person.Surname = RandomValueGen.GetRandomString(1, 10);
                                      person.Save();
                                  });

            //---------------Test Result -----------------------
        }
 public void ShouldMapValuesToCorrectType_WhenPropertyIsNotStringAndDatabaseTypeIs()
 {
     //---------------Set up test pack-------------------
     var classDef = ContactPersonTestBO.LoadDefaultClassDef();
     classDef.PropDefcol["FirstName"].PropertyType = typeof(int);
     var cp1 = new ContactPersonTestBO();
     cp1.Surname = Guid.NewGuid().ToString("N");
     var firstNameValue = 20;
     cp1.SetPropertyValue("FirstName", firstNameValue);
     cp1.Save();
     var selectQuery = QueryBuilder.CreateSelectQuery(classDef);
     selectQuery.Fields.Clear();
     selectQuery.Fields.Add("FirstName", QueryBuilder.CreateQueryField(classDef, "FirstName"));
     //---------------Execute Test ----------------------
     var resultSet = _queryResultLoader.GetResultSet(selectQuery);
     //---------------Test Result -----------------------
     var rows = resultSet.Rows.ToList();
     Assert.AreEqual(firstNameValue, rows[0].Values[0]);
 }
Ejemplo n.º 35
0
        public void TestNotIsMatch_OneProp_NotLike_ValuesEndsWith_CriteriaEndsWith()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadDefaultClassDef();
            ContactPersonTestBO cp = new ContactPersonTestBO();
            cp.Surname = "surname is MyValue";
            cp.Save();

            //---------------Assert PreConditions---------------            
            //---------------Execute Test ----------------------
            Criteria criteria = new Criteria("Surname", Criteria.ComparisonOp.NotLike, "%MyValue");
            bool isMatch = criteria.IsMatch(cp);
            //---------------Test Result -----------------------
            Assert.IsFalse(isMatch, "The object should not be a match since it matches the criteria given.");
        }
        public void Test_SaveDuplicateObject_DoesNotAddItselfToObjectManager()
        {
            //This scenario is unlikely to ever happen in normal use but is frequently hit during testing.
            //An object that has a reference to it is removed from the object manager (usually via ClearLoadedObjects).
            // A second instance of the same object is now loaded. This new instance is therefore added to the object manager.
            // The first object is saved. This must not remove the second instance of the object from the object manager 
            // and insert a itself.
            //---------------Set up test pack-------------------
            SetupDefaultContactPersonBO();
            var boMan = BusinessObjectManager.Instance;
            var originalContactPerson = new ContactPersonTestBO {Surname = "FirstSurname"};
            originalContactPerson.Save();
            var origCPID = originalContactPerson.ID;
            FixtureEnvironment.ClearBusinessObjectManager();

            //---------------Assert Precondition----------------
            Assert.AreEqual(0, boMan.Count);
            Assert.IsFalse(boMan.Contains(originalContactPerson));
            //---------------Execute Test Step 1----------------------
            var myContact2 =
                BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject<ContactPersonTestBO>(origCPID);
            //---------------Test Result Step 1-----------------------
            Assert.AreEqual(1, boMan.Count);
            Assert.IsTrue(boMan.Contains(myContact2));
            //---------------Execute Test Step 2----------------------
            originalContactPerson.Surname = TestUtil.GetRandomString();
            originalContactPerson.Save();
            //---------------Test Result Step 1-----------------------
            Assert.AreNotSame(originalContactPerson, myContact2);
            Assert.AreEqual(1, boMan.Count);
            Assert.IsFalse
                (boMan.Contains(originalContactPerson), "This object should not have been added to the object manager");
            Assert.IsTrue(boMan.Contains(myContact2), "This object should still b in the object manager");
        }
 private static ContactPersonTestBO CreateSavedCP()
 {
     var cp = new ContactPersonTestBO
                                  {Surname = TestUtil.GetRandomString(), FirstName = TestUtil.GetRandomString()};
     cp.Save();
     return cp;
 }
Ejemplo n.º 38
0
        public void TestRefreshWithRemovedChild_DereferenceChild()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            AddressTestBO address;
            ContactPersonTestBO cp = ContactPersonTestBO.CreateContactPersonWithOneAddress_DeleteDoNothing(out address);
            ContactPersonTestBO cp2 = new ContactPersonTestBO();
            cp2.Surname = Guid.NewGuid().ToString("N");
            cp2.FirstName = Guid.NewGuid().ToString("N");
            cp2.Save();
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, cp.Addresses.Count);

            //---------------Execute Test ----------------------
            address.ContactPersonID = cp2.ContactPersonID;
            address.Save();
            address.SetDeletable(false);
            RelatedBusinessObjectCollection<AddressTestBO> addresses = cp.Addresses;

            //---------------Test Result -----------------------
            Assert.AreEqual(0, addresses.Count);
        }
        public void Test_GetDirtyChildren_Edited()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            SingleRelationship<ContactPersonTestBO> relationship = GetAggregationRelationshipContactPerson(organisationTestBO, "ContactPerson");
            ContactPersonTestBO contactPerson = new ContactPersonTestBO();
            contactPerson.Surname = TestUtil.GetRandomString();
            contactPerson.FirstName = TestUtil.GetRandomString();
            contactPerson.Organisation = organisationTestBO;
            contactPerson.Save();
            contactPerson.FirstName = TestUtil.GetRandomString();

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

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

            //---------------Test Result -----------------------
            Assert.Contains(contactPerson, (ICollection) dirtyChildren);
            Assert.AreEqual(1, dirtyChildren.Count);
        }
        public void Test_DirtyIfHasDirtyChildren()
        {
            //---------------Set up test pack-------------------
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            SingleRelationship<ContactPersonTestBO> relationship = GetAggregationRelationshipContactPerson(organisationTestBO, "ContactPerson");

            ContactPersonTestBO contactPerson = new ContactPersonTestBO();
            contactPerson.Surname = TestUtil.GetRandomString();
            contactPerson.FirstName = TestUtil.GetRandomString();
            contactPerson.Organisation = organisationTestBO;
            contactPerson.Save();

            //---------------Assert Precondition----------------
            Assert.IsFalse(relationship.IsDirty);

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

            //---------------Test Result -----------------------
            Assert.IsTrue(relationship.IsDirty);
        }
Ejemplo n.º 41
0
 public void TestIsMatch_DateTimeToday_GreaterThan()
 {
     //---------------Set up test pack-------------------
     ClassDef.ClassDefs.Clear();
     ContactPersonTestBO.LoadDefaultClassDef();
     ContactPersonTestBO cp = new ContactPersonTestBO();
     cp.Surname = Guid.NewGuid().ToString("N");
     DateTimeToday dateTimeToday = new DateTimeToday();
     cp.DateOfBirth = DateTime.Today.AddDays(1);
     cp.Save();
     //---------------Assert PreConditions---------------            
     //---------------Execute Test ----------------------
     Criteria criteria = new Criteria("DateOfBirth", Criteria.ComparisonOp.GreaterThan, dateTimeToday);
     bool isMatch = criteria.IsMatch(cp);
     //---------------Test Result -----------------------
     Assert.IsTrue(isMatch, "The object should be a match since it matches the criteria given.");
     //---------------Tear Down -------------------------          
 }
Ejemplo n.º 42
0
 public void TestIsMatch_OneProp_GreaterThan()
 {
     //---------------Set up test pack-------------------
     ClassDef.ClassDefs.Clear();
     ContactPersonTestBO.LoadDefaultClassDef();
     ContactPersonTestBO cp = new ContactPersonTestBO();
     cp.DateOfBirth = DateTime.Now;
     cp.Surname = TestUtil.GetRandomString();
     cp.Save();
     //---------------Assert PreConditions---------------            
     //---------------Execute Test ----------------------
     Criteria criteria = new Criteria("DateOfBirth", Criteria.ComparisonOp.GreaterThan, DateTime.Now.AddDays(-1));
     bool isMatch = criteria.IsMatch(cp);
     //---------------Test Result -----------------------
     Assert.IsTrue(isMatch, "The object should be a match since it matches the criteria given.");
     //---------------Tear Down -------------------------          
 }
Ejemplo n.º 43
0
 public void TestIsMatch_OneProp_Equals()
 {
     //---------------Set up test pack-------------------
     ClassDef.ClassDefs.Clear();
     ContactPersonTestBO.LoadDefaultClassDef();
     ContactPersonTestBO cp = new ContactPersonTestBO();
     cp.Surname = Guid.NewGuid().ToString("N");
     cp.Save();
     //---------------Assert PreConditions---------------            
     //---------------Execute Test ----------------------
     Criteria criteria = new Criteria("Surname", Criteria.ComparisonOp.Equals, cp.Surname);
     bool isMatch = criteria.IsMatch(cp);
     //---------------Test Result -----------------------
     Assert.IsTrue(isMatch, "The object should be a match since it matches the criteria given.");
     //---------------Tear Down -------------------------          
 }
Ejemplo n.º 44
0
        public void TestNotIsMatch_OneProp_NotIn_Null()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadDefaultClassDef();
            ContactPersonTestBO cp = new ContactPersonTestBO();
            cp.Surname = "Surname1";
            cp.FirstName = null;
            cp.Save();
            object[] values = new object[] { null, "FirstName1" };
            Criteria.CriteriaValues criteriaValues = new Criteria.CriteriaValues(values);

            //---------------Assert PreConditions---------------            
            //---------------Execute Test ----------------------
            Criteria criteria = new Criteria("FirstName", Criteria.ComparisonOp.NotIn, criteriaValues);
            bool isMatch = criteria.IsMatch(cp);

            //---------------Test Result -----------------------
            Assert.IsFalse(isMatch, "The object should not be a match since it doesn't match the criteria given.");
            //---------------Tear Down -------------------------          
        }
Ejemplo n.º 45
0
        public void TestFindAll_UsingClassDef_BUGFIX_ShouldBeThreadsafe(string aaa)
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory(new DataStoreInMemory());
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadDefaultClassDef();
            OrganisationTestBO.LoadDefaultClassDef();
            var dataStore = new DataStoreInMemory();
            var now = DateTime.Now;
            var cp1 = new ContactPersonTestBO {DateOfBirth = now, Surname = TestUtil.GetRandomString()};
            cp1.Save();
            dataStore.Add(cp1);
            var cp2 = new ContactPersonTestBO {DateOfBirth = now, Surname = TestUtil.GetRandomString()};
            cp2.Save();
            dataStore.Add(cp2);
            //var criteria = MockRepository.GenerateStub<Criteria>("DateOfBirth", Criteria.ComparisonOp.Equals, now);
            //criteria.Stub(o => o.IsMatch(Arg<IBusinessObject>.Is.Anything)).WhenCalled(invocation =>
            //{
            //    Thread.Sleep(100);
            //    invocation.ReturnValue = true;
            //}).Return(true);
            var criteria = new Criteria("DateOfBirth", Criteria.ComparisonOp.Equals, now);

            for (int i1 = 0; i1 < 1000; i1++)
            {
                dataStore.Add(OrganisationTestBO.CreateSavedOrganisation());
            }

            var threads = new List<Thread>();
            threads.Add(new Thread(() =>
            {
                for (int i1 = 0; i1 < 1000; i1++)
                {
                    dataStore.Add(OrganisationTestBO.CreateSavedOrganisation());
                }
            }));

            var exceptions = new List<Exception>();
            threads.Add(new Thread(() =>
            {
                try
                {
                    for (int i = 0; i < 10; i++)
                    {
                        dataStore.FindAll(ClassDef.Get<ContactPersonTestBO>(), criteria);
                    }
                }
                catch (Exception ex)
                {
                    exceptions.Add( ex);
                }
            }));
            
            
            //---------------Execute Test ----------------------
            threads.AsParallel().ForAll(thread => thread.Start());
            threads.AsParallel().ForAll(thread => thread.Join());
            //Assert.DoesNotThrow(() =>
            //{
                //var col = dataStore.FindAll(ClassDef.Get<ContactPersonTestBO>(), criteria);
                //thread.Join();
            //});
            //---------------Test Result -----------------------
            if (exceptions.Count > 0)
            {
                Assert.Fail("Has an Exception: " + exceptions[0].ToString());
            }
        }
Ejemplo n.º 46
0
        public void TestIsMatch_OneProp_In()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadDefaultClassDef();
            ContactPersonTestBO cp = new ContactPersonTestBO();
            cp.Surname = "Surname1";
            cp.Save();
            object[] values = new object[] { "Surname1", "Surname2" };
            Criteria.CriteriaValues criteriaValues = new Criteria.CriteriaValues(values);
            //---------------Assert PreConditions---------------            
            //---------------Execute Test ----------------------
            Criteria criteria = new Criteria("Surname", Criteria.ComparisonOp.In, criteriaValues);

            bool isMatch = criteria.IsMatch(cp);
            //---------------Test Result -----------------------
            Assert.IsTrue(isMatch, "The object should be a match since it matches the criteria given.");
            //---------------Tear Down -------------------------          
        }
 public void Test_SavedObjectInObjectManager()
 {
     //---------------Set up test pack-------------------
     FixtureEnvironment.ClearBusinessObjectManager();
     SetupDefaultContactPersonBO();
     var contactPersonTestBO = new ContactPersonTestBO {Surname = TestUtil.GetRandomString()};
     //---------------Assert Precondition----------------
     Assert.IsTrue(contactPersonTestBO.Status.IsNew);
     Assert.AreEqual(1, BusinessObjectManager.Instance.Count);
     Assert.IsTrue(BusinessObjectManager.Instance.Contains(contactPersonTestBO));
     //---------------Execute Test ----------------------
     contactPersonTestBO.Save();
     //---------------Test Result -----------------------
     Assert.IsFalse(contactPersonTestBO.Status.IsNew);
     Assert.AreEqual(1, BusinessObjectManager.Instance.Count);
     Assert.IsTrue(BusinessObjectManager.Instance.Contains(contactPersonTestBO));
     Assert.IsTrue(BusinessObjectManager.Instance.Contains(contactPersonTestBO.ID));
 }
Ejemplo n.º 48
0
        public void TestSaveUsesFactoryGeneratedTransactionCommitter()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            BORegistry.DataAccessor = new DataAccessorInMemory();
            SetupDefaultContactPersonBO();
            ContactPersonTestBO cp = new ContactPersonTestBO();
            cp.Surname = Guid.NewGuid().ToString("N");

            
            //---------------Execute Test ----------------------
            cp.Save();
            //---------------Test Result -----------------------
            ContactPersonTestBO loadedCP =
                BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject<ContactPersonTestBO>(cp.ID);
            Assert.IsNotNull(loadedCP);
            Assert.AreSame(cp, loadedCP);
            //---------------Tear Down -------------------------
        }
        public void Test_SavedObject_Twice_AddedToObjectManager_Once()
        {
            //---------------Set up test pack-------------------
            SetupDefaultContactPersonBO();
            var boMan = BusinessObjectManager.Instance;

            var cp = new ContactPersonTestBO {Surname = TestUtil.GetRandomString()};
            cp.Save();
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, boMan.Count);
            Assert.IsTrue(boMan.Contains(cp));

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

            cp.Surname = TestUtil.GetRandomString();
            cp.Save();

            //---------------Test Result -----------------------
            Assert.AreEqual(1, boMan.Count);
            Assert.IsTrue(boMan.Contains(cp));
            Assert.IsTrue(boMan.Contains(cp.ID));
            Assert.IsTrue(boMan.Contains(cp.ID.ObjectID));
            //Assert.AreSame(cp, boMan[cp.ID.AsString_CurrentValue()]);
            Assert.AreSame(cp, boMan[cp.ID.ObjectID]);
            Assert.AreSame(cp, boMan[cp.ID]);
        }
Ejemplo n.º 50
0
        public void TestBOLookupListWithString()
        {
            //ContactPersonTestBO.CreateSampleData();
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadDefaultClassDef();
            var classDef = MyBO.LoadClassDefWithBOStringLookup();

            //var criteria = new Criteria("Surname", Criteria.ComparisonOp.Equals, "abc");
            //var cp =
            //    BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObject<ContactPersonTestBO>(criteria);
            var cp = new ContactPersonTestBO();
            const string expectedSurname = "abc";
            cp.Surname = expectedSurname;
            cp.Save();
            var bo = (BusinessObject) classDef.CreateNewBusinessObject();

            bo.SetPropertyValue("TestProp2", "abc");
            Assert.IsNotNull(cp, "ContactPerson should not be null");
            Assert.AreEqual(cp.ContactPersonID.ToString(), bo.GetPropertyValue("TestProp2"));
            Assert.AreEqual("abc", bo.GetPropertyValueToDisplay("TestProp2"));
        }
Ejemplo n.º 51
0
        public void TestIsMatch_NotLike_Incomparable()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadClassDefWithImageProperty();
            ContactPersonTestBO cp = new ContactPersonTestBO();
            cp.SetPropertyValue("Image", new System.Drawing.Bitmap(10, 10));
            Criteria nameCriteria = new Criteria("Image", Criteria.ComparisonOp.NotLike, new System.Drawing.Bitmap(20, 20));
            cp.Surname = TestUtil.GetRandomString();
            cp.Save();
            
            //---------------Assert PreConditions---------------            
            //---------------Execute Test ----------------------
            try
            {
                nameCriteria.IsMatch(cp);
                Assert.Fail("expected InvalidOperationException because you Bitmap does not implement IComparable");

                //---------------Test Result -----------------------
            }
            catch (InvalidOperationException ex)
            {
                StringAssert.Contains("does not implement IComparable and cannot be matched", ex.Message);
            }
        }
Ejemplo n.º 52
0
        public void TestNotIsMatch_OneProp_IS()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadDefaultClassDef();
            ContactPersonTestBO cp = new ContactPersonTestBO();
            cp.Surname = "MyValue";
            cp.Save();

            //---------------Assert PreConditions---------------            
            //---------------Execute Test ----------------------
            Criteria criteria = new Criteria("Surname", Criteria.ComparisonOp.Is, "NULL"); 
            bool isMatch = criteria.IsMatch(cp);

            //---------------Test Result -----------------------
            Assert.IsFalse(isMatch, "The object should not be a match since its surname is not null.");
        }
Ejemplo n.º 53
0
        public void TestIsMatch_OneProp_Like_ValuesIdentical_CriteriaEndsWith()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadDefaultClassDef();
            ContactPersonTestBO cp = new ContactPersonTestBO();
            cp.Surname = "MyValue";
            cp.Save();

            //---------------Assert PreConditions---------------            
            //---------------Execute Test ----------------------
            Criteria criteria = new Criteria("Surname", Criteria.ComparisonOp.Like, "%MyValue");
            bool isMatch = criteria.IsMatch(cp);
            //---------------Test Result -----------------------
            Assert.IsTrue(isMatch, "The object should be a match since surname ends with MyValue.");
            //---------------Tear Down -------------------------          
        }
Ejemplo n.º 54
0
        public void TestFind()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory(new DataStoreInMemory());
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadDefaultClassDef();
            ContactPersonTestBO cp = new ContactPersonTestBO();
            cp.Surname = Guid.NewGuid().ToString("N");
            cp.Save();
            DataStoreInMemory dataStore = new DataStoreInMemory();
            dataStore.Add(cp);
            Criteria criteria = new Criteria("Surname", Criteria.ComparisonOp.Equals, cp.Surname);

            //---------------Execute Test ----------------------
            ContactPersonTestBO loadedCP = dataStore.Find<ContactPersonTestBO>(criteria);

            //---------------Test Result -----------------------
            Assert.AreSame(cp.ID, loadedCP.ID);
            //---------------Tear Down -------------------------      
        }
 private ContactPersonTestBO CreateContactPerson(string surname)
 {
     var cp1 = new ContactPersonTestBO();
     cp1.Surname = surname;
     cp1.FirstName = Guid.NewGuid().ToString("N");
     cp1.Save();
     return cp1;
 }
Ejemplo n.º 56
0
        public void TestFind_UsingGuidCriteria_Untyped()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory(new DataStoreInMemory());
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadDefaultClassDef_WOrganisationID();
            OrganisationTestBO.LoadDefaultClassDef();
            ContactPersonTestBO cp = new ContactPersonTestBO {Surname = Guid.NewGuid().ToString("N")};
            cp.OrganisationID = OrganisationTestBO.CreateSavedOrganisation().OrganisationID;
            cp.Save();
            DataStoreInMemory dataStore = new DataStoreInMemory();
            dataStore.Add(cp);
            Criteria criteria = new Criteria("OrganisationID", Criteria.ComparisonOp.Equals, cp.OrganisationID);

            //---------------Execute Test ----------------------
            ContactPersonTestBO loadedCP = (ContactPersonTestBO) dataStore.Find(typeof(ContactPersonTestBO), criteria);

            //---------------Test Result -----------------------
            Assert.AreSame(cp.ID, loadedCP.ID);
        }
Ejemplo n.º 57
0
 public void TestFind_UsingGuidCriteriaString_Typed()
 {
     //---------------Set up test pack-------------------
     BORegistry.DataAccessor = new DataAccessorInMemory(new DataStoreInMemory());
     ClassDef.ClassDefs.Clear();
     ContactPersonTestBO.LoadDefaultClassDef_WOrganisationID();
     OrganisationTestBO.LoadDefaultClassDef();
     ContactPersonTestBO cp = new ContactPersonTestBO { Surname = Guid.NewGuid().ToString("N") };
     cp.OrganisationID = OrganisationTestBO.CreateSavedOrganisation().OrganisationID;
     cp.Save();
     DataStoreInMemory dataStore = new DataStoreInMemory();
     dataStore.Add(cp);
     Criteria criteria = CriteriaParser.CreateCriteria("OrganisationID = " + cp.OrganisationID);
     //---------------Assert Precondtions---------------
     Assert.IsNotNull(cp.OrganisationID);
     //---------------Execute Test ----------------------
     ContactPersonTestBO loadedCP = dataStore.Find<ContactPersonTestBO>(criteria);
     //---------------Test Result -----------------------
     Assert.IsNotNull(loadedCP);
     Assert.AreSame(cp.ID, loadedCP.ID);
 }
Ejemplo n.º 58
0
        public void TestFindAll_UsingClassDef()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory(new DataStoreInMemory());
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadDefaultClassDef();
            OrganisationTestBO.LoadDefaultClassDef();
            DataStoreInMemory dataStore = new DataStoreInMemory();
            DateTime now = DateTime.Now;
            ContactPersonTestBO cp1 = new ContactPersonTestBO();
            cp1.DateOfBirth = now;
            cp1.Surname = TestUtil.GetRandomString();
            cp1.Save();
            dataStore.Add(cp1);
            ContactPersonTestBO cp2 = new ContactPersonTestBO();
            cp2.DateOfBirth = now;
            cp2.Surname = TestUtil.GetRandomString();
            cp2.Save();
            dataStore.Add(cp2);
            Criteria criteria = new Criteria("DateOfBirth", Criteria.ComparisonOp.Equals, now);

            dataStore.Add(OrganisationTestBO.CreateSavedOrganisation());
            //---------------Execute Test ----------------------
            IBusinessObjectCollection col = dataStore.FindAll(ClassDef.Get<ContactPersonTestBO>(), criteria);
            //---------------Test Result -----------------------
            Assert.AreEqual(2, col.Count);
            Assert.Contains(cp1, col);
            Assert.Contains(cp2, col);
        }
Ejemplo n.º 59
0
        public void Test_IsMatch_GuidCriteriaAsString_UserPersistedValueTrue()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadDefaultClassDef_WOrganisationID();
            OrganisationTestBO.LoadDefaultClassDef();
            ContactPersonTestBO cp = new ContactPersonTestBO { Surname = Guid.NewGuid().ToString("N") };
            cp.OrganisationID = OrganisationTestBO.CreateSavedOrganisation().OrganisationID;
            cp.Save();
            Criteria criteria = CriteriaParser.CreateCriteria("OrganisationID = " + cp.OrganisationID);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            bool isMatch = criteria.IsMatch(cp);
            //---------------Test Result -----------------------
            Assert.IsTrue(isMatch);
        }
Ejemplo n.º 60
0
        public void TestIsMatch_TwoProps_And()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadDefaultClassDef();
            ContactPersonTestBO cp = new ContactPersonTestBO();
            DateTime dob = DateTime.Now;
            cp.DateOfBirth = dob;
            string surname = Guid.NewGuid().ToString("N");
            cp.Surname = surname;
            cp.Save();

            Criteria dobCriteria = new Criteria("DateOfBirth", Criteria.ComparisonOp.Equals, dob);
            Criteria nameCriteria = new Criteria("Surname", Criteria.ComparisonOp.Equals, surname);

            //---------------Execute Test ----------------------
            Criteria twoPropCriteria = new Criteria(dobCriteria, Criteria.LogicalOp.And, nameCriteria);
            bool isMatch = twoPropCriteria.IsMatch(cp);
            //---------------Test Result -----------------------
            Assert.IsTrue(isMatch, "The object should be a match since it matches the criteria given.");
            //---------------Tear Down -------------------------
        }