Пример #1
0
        private static BusinessObjectCollection <FakeBo> GetBusinessObjectCollectionWith3Items()
        {
            var businessObjectCollection = new BusinessObjectCollection <FakeBo>();

            businessObjectCollection.CreateBusinessObject();
            businessObjectCollection.CreateBusinessObject();
            businessObjectCollection.CreateBusinessObject();
            return(businessObjectCollection);
        }
Пример #2
0
        public void TestSerialiseDeserialiseBusinessObjectCollection_HavingAllCollections()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            BORegistry.DataAccessor = new DataAccessorInMemory();
            Structure.Car.LoadDefaultClassDef();
            OrganisationPerson.LoadDefaultClassDef();
            Person.LoadDefaultClassDef();
            BusinessObjectCollection <Person> originalPeople = new BusinessObjectCollection <Person>();
            Person persistedPerson = originalPeople.CreateBusinessObject();
            Person deletedPerson   = originalPeople.CreateBusinessObject();
            Person removedPerson   = originalPeople.CreateBusinessObject();

            originalPeople.SaveAll();

            originalPeople.Remove(removedPerson);
            deletedPerson.MarkForDelete();
            Person createdPerson = originalPeople.CreateBusinessObject();
            Person addedPerson   = new Person();

            addedPerson.Save();
            originalPeople.Add(addedPerson);

            IFormatter   formatter    = new BinaryFormatter();
            MemoryStream memoryStream = new MemoryStream();

            FixtureEnvironment.ClearBusinessObjectManager();
            //---------------Assert PreConditions---------------
            Assert.AreEqual(1, originalPeople.MarkedForDeleteBusinessObjects.Count);
            Assert.AreEqual(1, originalPeople.RemovedBusinessObjects.Count);
            Assert.AreEqual(1, originalPeople.AddedBusinessObjects.Count);
            Assert.AreEqual(3, originalPeople.PersistedBusinessObjects.Count);
            Assert.AreEqual(1, originalPeople.CreatedBusinessObjects.Count);
            Assert.AreEqual(3, originalPeople.Count);

            //---------------Execute Test ----------------------
            formatter.Serialize(memoryStream, originalPeople);
            memoryStream.Seek(0, SeekOrigin.Begin);
            BusinessObjectCollection <Person> deserialisedPeople = (BusinessObjectCollection <Person>)formatter.Deserialize(memoryStream);

            //---------------Test Result -----------------------
            Assert.AreEqual(originalPeople.Count, deserialisedPeople.Count);
            Assert.AreEqual(originalPeople.PersistedBusinessObjects.Count, deserialisedPeople.PersistedBusinessObjects.Count);
            Assert.AreEqual(originalPeople.CreatedBusinessObjects.Count, deserialisedPeople.CreatedBusinessObjects.Count);
            Assert.AreEqual(originalPeople.AddedBusinessObjects.Count, deserialisedPeople.AddedBusinessObjects.Count);
            Assert.AreEqual(originalPeople.RemovedBusinessObjects.Count, deserialisedPeople.RemovedBusinessObjects.Count);
            Assert.AreEqual(originalPeople.MarkedForDeleteBusinessObjects.Count, deserialisedPeople.MarkedForDeleteBusinessObjects.Count);

            AssertPersonsAreEqual(deserialisedPeople.MarkedForDeleteBusinessObjects[0], deletedPerson);
            AssertPersonsAreEqual(deserialisedPeople.RemovedBusinessObjects[0], removedPerson);
            AssertPersonsAreEqual(deserialisedPeople.AddedBusinessObjects[0], addedPerson);
            AssertPersonsAreEqual(deserialisedPeople.PersistedBusinessObjects[0], persistedPerson);
            AssertPersonsAreEqual(deserialisedPeople.CreatedBusinessObjects[0], createdPerson);
        }
Пример #3
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();
        }
Пример #4
0
        public void Test_CreateBusObject()
        {
            //---------------Set up test pack-------------------
            //ContactPersonTestBO.LoadDefaultClassDef();
            BusinessObjectCollection <ContactPersonTestBO> cpCol = new BusinessObjectCollection <ContactPersonTestBO>();

            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);
        }
Пример #5
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);
        }
        protected static ContactPersonTestBO CreateExistingChild(BusinessObjectCollection <ContactPersonTestBO> cpCol)
        {
            ContactPersonTestBO existingChildEdited = cpCol.CreateBusinessObject();

            existingChildEdited.Surname   = TestUtil.GetRandomString();
            existingChildEdited.FirstName = TestUtil.GetRandomString();
            existingChildEdited.Save();
            return(existingChildEdited);
        }
 public void Test_BindBusinessObjectCollection_ToListBox_ShouldAddToControlList()
 {
     //---------------Set up test pack-------------------
     var lstBox = new ListBox();
     var selectorBinder = new HabaneroSelectorControlBinder<FakeBo, ListBox>(lstBox);
     var businessObjectCollection = new BusinessObjectCollection<FakeBo>();
     businessObjectCollection.CreateBusinessObject();
     //---------------Assert Precondition----------------
     Assert.AreEqual(0, lstBox.Items.Count);
     //---------------Execute Test ----------------------
     selectorBinder.SetBusinessObjectCollection(businessObjectCollection);
     //---------------Test Result -----------------------
     Assert.AreEqual(1, lstBox.Items.Count, "The business object collection's items should be in list");
 }
Пример #8
0
        public void Test_BindBusinessObjectCollection_ToListBox_ShouldAddToControlList()
        {
            //---------------Set up test pack-------------------
            var lstBox                   = new ListBox();
            var selectorBinder           = new HabaneroSelectorControlBinder <FakeBo, ListBox>(lstBox);
            var businessObjectCollection = new BusinessObjectCollection <FakeBo>();

            businessObjectCollection.CreateBusinessObject();
            //---------------Assert Precondition----------------
            Assert.AreEqual(0, lstBox.Items.Count);
            //---------------Execute Test ----------------------
            selectorBinder.SetBusinessObjectCollection(businessObjectCollection);
            //---------------Test Result -----------------------
            Assert.AreEqual(1, lstBox.Items.Count, "The business object collection's items should be in list");
        }
Пример #9
0
        public void Test_CreatedBusinessObject_MarkForDelete_ShouldBeRemovedFromTheCollection()
        {
            //---------------Set up test pack-------------------
            //ContactPersonTestBO.LoadDefaultClassDef();
            BusinessObjectCollection <ContactPersonTestBO> cpCol = new BusinessObjectCollection <ContactPersonTestBO>();
            ContactPersonTestBO newCP = cpCol.CreateBusinessObject();

            newCP.Surname = TestUtil.GetRandomString();
            //---------------Assert Precondition----------------
            AssertOneObjectInCurrentAndCreatedCollection(cpCol);
            //---------------Execute Test ----------------------
            newCP.MarkForDelete();
            //---------------Test Result -----------------------
            Assert.AreEqual(0, cpCol.Count);
            Assert.IsTrue(newCP.Status.IsDeleted);
        }
Пример #10
0
        public void Test_CreatedBusinessObject_RestoreIndependently()
        {
            //---------------Set up test pack-------------------
            //ContactPersonTestBO.LoadDefaultClassDef();
            BusinessObjectCollection <ContactPersonTestBO> cpCol = new BusinessObjectCollection <ContactPersonTestBO>();
            ContactPersonTestBO newCP = cpCol.CreateBusinessObject();

            newCP.Surname = TestUtil.GetRandomString();

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

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

            //---------------Test Result -----------------------
            AssertOneObjectInCurrentAndCreatedCollection(cpCol);
        }
Пример #11
0
        public void Test_CreatedBusinessObject_Refresh()
        {
            //---------------Set up test pack-------------------
            //ContactPersonTestBO.LoadDefaultClassDef();
            BusinessObjectCollection <ContactPersonTestBO> cpCol = new BusinessObjectCollection <ContactPersonTestBO>();
            ContactPersonTestBO newCP = cpCol.CreateBusinessObject();

            newCP.Surname = TestUtil.GetRandomString();

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

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

            //---------------Test Result -----------------------
            AssertOneObjectInCurrentAndCreatedCollection(cpCol);
        }
Пример #12
0
        public void Test_RefreshAll_W_CreatedBO()
        {
            //---------------Set up test pack-------------------
            BusinessObjectCollection <ContactPersonTestBO> cpCol = new BusinessObjectCollection <ContactPersonTestBO>();

            cpCol.CreateBusinessObject();
            RegisterForAddedAndRemovedEvents(cpCol);

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

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

            //---------------Test Result -----------------------
            AssertOneObjectInCurrentAndCreatedCollection(cpCol);
            AssertAddedAndRemovedEventsNotFired();
        }
Пример #13
0
        public void Test_CreatedBusinessObject_Add()
        {
            //---------------Set up test pack-------------------
            //ContactPersonTestBO.LoadDefaultClassDef();
            BusinessObjectCollection <ContactPersonTestBO> cpCol = new BusinessObjectCollection <ContactPersonTestBO>();
            ContactPersonTestBO newCP = cpCol.CreateBusinessObject();

            newCP.Surname = TestUtil.GetRandomString();
            RegisterForAddedAndRemovedEvents(cpCol);

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

            //---------------Execute Test ----------------------
            cpCol.Add(newCP);

            //---------------Test Result -----------------------
            AssertOneObjectInCurrentAndCreatedCollection(cpCol);
            AssertAddedAndRemovedEventsNotFired();
        }
Пример #14
0
        public void Test_CreatedBO_Remove_DeregisteresFromRestoredEvent()
        {
            //If you remove a created business object that is not yet persisted then
            //-- remove from the restored and saved event.
            //---------------Set up test pack-------------------
            BusinessObjectCollection <ContactPersonTestBO> cpCol = CreateCollectionWith_OneBO();
            ContactPersonTestBO createdCp = cpCol.CreateBusinessObject();

            createdCp.Surname = BOTestUtils.RandomString;

            //---------------Assert Precondition----------------
            AssertTwoCurrentObjects_OnePsersisted_OneCreated(cpCol);
            Assert.IsTrue(cpCol.Contains(createdCp));

            //---------------Execute Test ----------------------
            cpCol.Remove(createdCp);
            createdCp.CancelEdits();

            //---------------Test Result -----------------------
            AssertOneObjectInCurrentAndPersistedCollection(cpCol);
            Assert.IsFalse(cpCol.Contains(createdCp));
        }
Пример #15
0
        public void Test_CancelEdits()
        {
            //---------------Set up test pack-------------------
            new AddressTestBO();
            ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse();
            OrganisationTestBO.LoadDefaultClassDef_WithMultipleRelationshipToAddress();
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            RelationshipCol    relationships      = organisationTestBO.Relationships;
            MultipleRelationship <ContactPersonTestBO>     contactPersonRelationship = organisationTestBO.Relationships.GetMultiple <ContactPersonTestBO>("ContactPeople");
            BusinessObjectCollection <ContactPersonTestBO> contactPersonCol          = contactPersonRelationship.BusinessObjectCollection;
            MultipleRelationship <AddressTestBO>           addressRelationship       = organisationTestBO.Relationships.GetMultiple <AddressTestBO>("Addresses");
            BusinessObjectCollection <AddressTestBO>       addressCol = addressRelationship.BusinessObjectCollection;

            contactPersonCol.CreateBusinessObject();
            addressCol.CreateBusinessObject();
            //---------------Assert Precondition----------------
            Assert.IsTrue(relationships.IsDirty);
            //---------------Execute Test ----------------------
            relationships.CancelEdits();
            //---------------Test Result -----------------------
            Assert.IsFalse(relationships.IsDirty);
        }
        public void Test_CreateBusObject()
        {
            //---------------Set up test pack-------------------
            //ContactPersonTestBO.LoadDefaultClassDef();
            BusinessObjectCollection<ContactPersonTestBO> cpCol = new BusinessObjectCollection<ContactPersonTestBO>();
            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);
        }
        public void Test_SelectItem_SetsItemInBOEditor()
        {
            //---------------Set up test pack-------------------
            IBOColSelectorControl  boColSelector;
            IBusinessObjectControl boEditor;

            CreateBoSelectorAndEditorManager(out boColSelector, out boEditor);
            MyBO myBO;
            BusinessObjectCollection <MyBO> col = GetBOCol_WithOneBO(out myBO);

            col.CreateBusinessObject();
            boColSelector.BusinessObjectCollection = col;
            MyBO secondBO = col[1];

            //---------------Assert Precondition----------------
            Assert.AreEqual(2, col.Count);
            Assert.AreSame(myBO, boEditor.BusinessObject, "BOEditor Should have the first BO Set");
            //---------------Execute Test ----------------------
            boColSelector.SelectedBusinessObject = secondBO;
            //---------------Test Result -----------------------
            Assert.AreEqual(2, boColSelector.NoOfItems);
            Assert.AreSame(secondBO, boColSelector.SelectedBusinessObject);
            Assert.AreSame(secondBO, boEditor.BusinessObject, "BOEditor Should have the Bo Set");
        }
Пример #18
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-------------------
            BusinessObjectCollection <ContactPersonTestBO> cpCol = CreateCollectionWith_OneBO();
            ContactPersonTestBO createdCp = cpCol.CreateBusinessObject();

            createdCp.Surname = 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();
        }
Пример #19
0
        public void Test_AddDirtyChildrenToTransactionCommitter()
        {
            //---------------Set up test pack-------------------
            new AddressTestBO();
            ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse();
            OrganisationTestBO.LoadDefaultClassDef_WithMultipleRelationshipToAddress();
            OrganisationTestBO organisationTestBO = OrganisationTestBO.CreateSavedOrganisation();
            RelationshipCol    relationships      = organisationTestBO.Relationships;
            MultipleRelationship <ContactPersonTestBO>     contactPersonRelationship = organisationTestBO.Relationships.GetMultiple <ContactPersonTestBO>("ContactPeople");
            BusinessObjectCollection <ContactPersonTestBO> contactPersonCol          = contactPersonRelationship.BusinessObjectCollection;
            MultipleRelationship <AddressTestBO>           addressRelationship       = organisationTestBO.Relationships.GetMultiple <AddressTestBO>("Addresses");
            BusinessObjectCollection <AddressTestBO>       addressCol = addressRelationship.BusinessObjectCollection;

            contactPersonCol.CreateBusinessObject();
            addressCol.CreateBusinessObject();

            //---------------Execute Test ----------------------
            TransactionCommitterInMemory tc = new TransactionCommitterInMemory(new DataStoreInMemory());

            relationships.AddDirtyChildrenToTransactionCommitter(tc);

            //---------------Test Result -----------------------
            Assert.AreEqual(2, tc.OriginalTransactions.Count);
        }
        public void Test_CreatedBusinessObject_RestoredTwice()
        {
            //---------------Set up test pack-------------------
            //ContactPersonTestBO.LoadDefaultClassDef();
            BusinessObjectCollection<ContactPersonTestBO> cpCol = new BusinessObjectCollection<ContactPersonTestBO>();
            ContactPersonTestBO newCP = cpCol.CreateBusinessObject();
            newCP.Surname = TestUtil.GetRandomString();
            newCP.CancelEdits();

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

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

            //---------------Test Result -----------------------
            AssertOneObjectInCurrentAndCreatedCollection(cpCol);
        }
        public void Test_CreatedBusinessObject_Refresh()
        {
            //---------------Set up test pack-------------------
            //ContactPersonTestBO.LoadDefaultClassDef();
            BusinessObjectCollection<ContactPersonTestBO> cpCol = new BusinessObjectCollection<ContactPersonTestBO>();
            ContactPersonTestBO newCP = cpCol.CreateBusinessObject();
            newCP.Surname = TestUtil.GetRandomString();

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

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

            //---------------Test Result -----------------------            
            AssertOneObjectInCurrentAndCreatedCollection(cpCol);
        }
 public void Test_CreatedBusinessObject_MarkForDelete_ShouldBeRemovedFromTheCollection()
 {
     //---------------Set up test pack-------------------
     //ContactPersonTestBO.LoadDefaultClassDef();
     BusinessObjectCollection<ContactPersonTestBO> cpCol = new BusinessObjectCollection<ContactPersonTestBO>();
     ContactPersonTestBO newCP = cpCol.CreateBusinessObject();
     newCP.Surname = TestUtil.GetRandomString();
     //---------------Assert Precondition----------------
     AssertOneObjectInCurrentAndCreatedCollection(cpCol);
     //---------------Execute Test ----------------------
     newCP.MarkForDelete();
     //---------------Test Result -----------------------
     Assert.AreEqual(0, cpCol.Count);
     Assert.IsTrue(newCP.Status.IsDeleted);
 }
        public void Test_RefreshAll_W_CreatedBO()
        {
            //---------------Set up test pack-------------------
            BusinessObjectCollection<ContactPersonTestBO> cpCol = new BusinessObjectCollection<ContactPersonTestBO>();
            cpCol.CreateBusinessObject();
            RegisterForAddedAndRemovedEvents(cpCol);

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

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

            //---------------Test Result -----------------------
            AssertOneObjectInCurrentAndCreatedCollection(cpCol);
            AssertAddedAndRemovedEventsNotFired();
        }
        public void Test_CreatedBusinessObject_Add()
        {
            //---------------Set up test pack-------------------
            //ContactPersonTestBO.LoadDefaultClassDef();
            BusinessObjectCollection<ContactPersonTestBO> cpCol = new BusinessObjectCollection<ContactPersonTestBO>();
            ContactPersonTestBO newCP = cpCol.CreateBusinessObject();
            newCP.Surname = TestUtil.GetRandomString();
            RegisterForAddedAndRemovedEvents(cpCol);

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

            //---------------Execute Test ----------------------
            cpCol.Add(newCP);

            //---------------Test Result -----------------------
            AssertOneObjectInCurrentAndCreatedCollection(cpCol);
            AssertAddedAndRemovedEventsNotFired();
        }
        public void Test_CreateBusinessObject_AlternateClassDef_NoConstructor_ShouldThrowException()
        {
            //---------------Set up test pack-------------------
            ClassDef classDef = (ClassDef) OrganisationTestBO.LoadDefaultClassDef();
            ClassDef alternateClassDef = classDef.Clone();
            alternateClassDef.TypeParameter = TestUtil.GetRandomString();
            BusinessObjectCollection<OrganisationTestBO> orgCol = new BusinessObjectCollection<OrganisationTestBO>
                                                                      {ClassDef = alternateClassDef};

            //---------------Execute Test ----------------------
            try
            {

                //this should not work because OrganisationTestBO does not have a constructor that takes a ClassDef as parameter
                orgCol.CreateBusinessObject();

                Assert.Fail("Expected to throw an HabaneroDeveloperException");
            }
                //---------------Test Result -----------------------
            catch (HabaneroDeveloperException ex)
            {
                StringAssert.Contains("There was a problem creating a Habanero.Test.BO.OrganisationTestBO", ex.Message);
            }
        }
        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);
        }
 protected static ContactPersonTestBO CreateCreatedChild(BusinessObjectCollection<ContactPersonTestBO> cpCol)
 {
     ContactPersonTestBO createdChildUnedited = cpCol.CreateBusinessObject();
     return createdChildUnedited;
 }
        public void Test_ClearClearsCreatedCollection()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO.LoadDefaultClassDef();
            BusinessObjectCollection<ContactPersonTestBO> cpCol = new BusinessObjectCollection<ContactPersonTestBO>();
            ContactPersonTestBO.DeleteAllContactPeople();
            CreateTwoSavedContactPeople();
            cpCol.CreateBusinessObject();

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

            //---------------Execute Test ----------------------
            cpCol.Clear();

            //---------------Test Result -----------------------
            Assert.AreEqual(0, cpCol.CreatedBusinessObjects.Count);
        }
        public void TestSerialiseDeserialiseBusinessObjectCollection_HavingAllCollections()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            BORegistry.DataAccessor = new DataAccessorInMemory();
            Structure.Car.LoadDefaultClassDef();
            OrganisationPerson.LoadDefaultClassDef();
            Person.LoadDefaultClassDef();
            BusinessObjectCollection<Person> originalPeople = new BusinessObjectCollection<Person>();
            Person persistedPerson = originalPeople.CreateBusinessObject();
            Person deletedPerson = originalPeople.CreateBusinessObject();
            Person removedPerson = originalPeople.CreateBusinessObject();
            originalPeople.SaveAll();

            originalPeople.Remove(removedPerson);
            deletedPerson.MarkForDelete();
            Person createdPerson = originalPeople.CreateBusinessObject();
            Person addedPerson = new Person();
            addedPerson.Save();
            originalPeople.Add(addedPerson);

            IFormatter formatter = new BinaryFormatter();
            MemoryStream memoryStream = new MemoryStream();
            FixtureEnvironment.ClearBusinessObjectManager();
            //---------------Assert PreConditions---------------       
            Assert.AreEqual(1, originalPeople.MarkedForDeleteBusinessObjects.Count);
            Assert.AreEqual(1, originalPeople.RemovedBusinessObjects.Count);
            Assert.AreEqual(1, originalPeople.AddedBusinessObjects.Count);
            Assert.AreEqual(3, originalPeople.PersistedBusinessObjects.Count);
            Assert.AreEqual(1, originalPeople.CreatedBusinessObjects.Count);
            Assert.AreEqual(3, originalPeople.Count);

            //---------------Execute Test ----------------------
            formatter.Serialize(memoryStream, originalPeople);
            memoryStream.Seek(0, SeekOrigin.Begin);
            BusinessObjectCollection<Person> deserialisedPeople = (BusinessObjectCollection<Person>)formatter.Deserialize(memoryStream);

            //---------------Test Result -----------------------
            Assert.AreEqual(originalPeople.Count, deserialisedPeople.Count);
            Assert.AreEqual(originalPeople.PersistedBusinessObjects.Count, deserialisedPeople.PersistedBusinessObjects.Count);
            Assert.AreEqual(originalPeople.CreatedBusinessObjects.Count, deserialisedPeople.CreatedBusinessObjects.Count);
            Assert.AreEqual(originalPeople.AddedBusinessObjects.Count, deserialisedPeople.AddedBusinessObjects.Count);
            Assert.AreEqual(originalPeople.RemovedBusinessObjects.Count, deserialisedPeople.RemovedBusinessObjects.Count);
            Assert.AreEqual(originalPeople.MarkedForDeleteBusinessObjects.Count, deserialisedPeople.MarkedForDeleteBusinessObjects.Count);

            AssertPersonsAreEqual(deserialisedPeople.MarkedForDeleteBusinessObjects[0], deletedPerson);
            AssertPersonsAreEqual(deserialisedPeople.RemovedBusinessObjects[0], removedPerson);
            AssertPersonsAreEqual(deserialisedPeople.AddedBusinessObjects[0], addedPerson);
            AssertPersonsAreEqual(deserialisedPeople.PersistedBusinessObjects[0], persistedPerson);
            AssertPersonsAreEqual(deserialisedPeople.CreatedBusinessObjects[0], createdPerson);

        }
        public void Test_CreateBusinessObject_AlternateClassDef()
        {
            //---------------Set up test pack-------------------
            AddressTestBO addressTestBO = new AddressTestBO();

            ClassDef classDef = addressTestBO.ClassDef;
            ClassDef alternateClassDef = classDef.Clone();
            alternateClassDef.TypeParameter = TestUtil.GetRandomString();
            BusinessObjectCollection<AddressTestBO> addressCol = new BusinessObjectCollection<AddressTestBO> {ClassDef = alternateClassDef};

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

            //this should work because AddressTestBO has a constructor that takes a ClassDef as parameter
            AddressTestBO newCP = addressCol.CreateBusinessObject();

            //---------------Test Result -----------------------
            Assert.AreEqual(alternateClassDef, newCP.ClassDef);
        }
        protected static ContactPersonTestBO CreateCreatedChild(BusinessObjectCollection <ContactPersonTestBO> cpCol)
        {
            ContactPersonTestBO createdChildUnedited = cpCol.CreateBusinessObject();

            return(createdChildUnedited);
        }
        public void Test_AddedEvent_NotFiringWhenRefreshing()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO.LoadDefaultClassDef();
            _addedEventFired = false;
            BusinessObjectCollection<ContactPersonTestBO> cpCol = new BusinessObjectCollection<ContactPersonTestBO>();
            cpCol.LoadAll();
            ContactPersonTestBO newCP = cpCol.CreateBusinessObject();
            newCP.Surname = Guid.NewGuid().ToString();
            newCP.Save();

            cpCol.BusinessObjectAdded += delegate { _addedEventFired = true; };
            //---------------Assert Preconditions --------------
            Assert.IsFalse(_addedEventFired);

            //---------------Execute Test ----------------------
            cpCol.Refresh();
            //---------------Test Result -----------------------
            Assert.IsFalse(_addedEventFired);
        }
 private static BusinessObjectCollection<FakeBo> GetBusinessObjectCollectionWith3Items()
 {
     var businessObjectCollection = new BusinessObjectCollection<FakeBo>();
     businessObjectCollection.CreateBusinessObject();
     businessObjectCollection.CreateBusinessObject();
     businessObjectCollection.CreateBusinessObject();
     return businessObjectCollection;
 }
        public void Test_CreateBusinessObject_ShouldAddToEndOfCollection()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO.LoadDefaultClassDef();
            CreateTwoSavedContactPeople();
            IBusinessObjectCollection col = new BusinessObjectCollection<ContactPersonTestBO>();
            col.LoadAll("Surname");

            //---------------Assert Precondition----------------
            Assert.AreEqual(2, col.Count);
            //---------------Execute Test ----------------------
            IBusinessObject businessObject = col.CreateBusinessObject();
            //---------------Test Result -----------------------
            Assert.AreSame(businessObject, col[2]);
        }      
 protected static ContactPersonTestBO CreateExistingChild(BusinessObjectCollection<ContactPersonTestBO> cpCol)
 {
     ContactPersonTestBO existingChildEdited = cpCol.CreateBusinessObject();
     existingChildEdited.Surname = TestUtil.GetRandomString();
     existingChildEdited.FirstName = TestUtil.GetRandomString();
     existingChildEdited.Save();
     return existingChildEdited;
 }