public void TearDown() { BusinessObjectCollection<Shape> shapes = new BusinessObjectCollection<Shape>(); shapes.LoadAll(); Shape[] shapesClone = shapes.ToArray(); foreach (Shape shape in shapesClone) { shape.MarkForDelete(); } shapes.SaveAll(); //Shape shape = BOLoader.Instance.GetBusinessObject<Shape>( // "ShapeName = 'MyShape' OR ShapeName = 'MyShapeChanged'"); //if (shape != null) //{ // shape.MarkForDelete(); // shape.Save(); //} //CircleNoPrimaryKey circle = BOLoader.Instance.GetBusinessObject<CircleNoPrimaryKey>( // "ShapeName = 'Circle' OR ShapeName = 'CircleChanged'"); //if (circle != null) //{ // circle.MarkForDelete(); // circle.Save(); //} //FilledCircleInheritsCircleNoPK filledCircle = BOLoader.Instance.GetBusinessObject<FilledCircleInheritsCircleNoPK>( // "ShapeName = 'FilledCircle' OR ShapeName = 'FilledCircleChanged'"); //if (filledCircle != null) //{ // filledCircle.MarkForDelete(); // filledCircle.Save(); //} }
public void Test_CreatedBusinessObject_SaveAll() { //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------------------- 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 ---------------------- cpCol.SaveAll(); //---------------Test Result ----------------------- Assert.IsFalse(_addedEventFired); Assert.Contains(newCP, cpCol); AssertOneObjectInCurrentAndPersistedCollection(cpCol); }
public void TestRemoveRelatedObject_PersistColToDataStore_usingRelationshipRefreshing() { //-----Create Test pack--------------------- ClassDef.ClassDefs.Clear(); AddressTestBO address; BORegistry.DataAccessor = new DataAccessorInMemory(); ContactPersonTestBO contactPersonTestBO = ContactPersonTestBO.CreateContactPersonWithOneAddress_CascadeDelete(out address, TestUtil.GetRandomString()); //-----Assert Precondition------------------ Assert.AreEqual(0, contactPersonTestBO.Addresses.RemovedBusinessObjects.Count); Assert.AreEqual(1, contactPersonTestBO.Addresses.Count); //-----Run tests---------------------------- //Run tests BusinessObjectCollection <AddressTestBO> addresses = contactPersonTestBO.Addresses; addresses.Remove(address); addresses.SaveAll(); ////-----Test results------------------------- Assert.IsFalse(address.Status.IsDirty); Assert.AreEqual(0, contactPersonTestBO.Addresses.RemovedBusinessObjects.Count); Assert.AreEqual(0, contactPersonTestBO.Addresses.Count); Assert.AreEqual(0, contactPersonTestBO.Addresses.PersistedBusinessObjects.Count); }
public void TearDown() { BusinessObjectCollection <Shape> shapes = new BusinessObjectCollection <Shape>(); shapes.LoadAll(); Shape[] shapesClone = shapes.ToArray(); foreach (Shape shape in shapesClone) { shape.MarkForDelete(); } shapes.SaveAll(); //Shape shape = BOLoader.Instance.GetBusinessObject<Shape>( // "ShapeName = 'MyShape' OR ShapeName = 'MyShapeChanged'"); //if (shape != null) //{ // shape.MarkForDelete(); // shape.Save(); //} //CircleNoPrimaryKey circle = BOLoader.Instance.GetBusinessObject<CircleNoPrimaryKey>( // "ShapeName = 'Circle' OR ShapeName = 'CircleChanged'"); //if (circle != null) //{ // circle.MarkForDelete(); // circle.Save(); //} //FilledCircleInheritsCircleNoPK filledCircle = BOLoader.Instance.GetBusinessObject<FilledCircleInheritsCircleNoPK>( // "ShapeName = 'FilledCircle' OR ShapeName = 'FilledCircleChanged'"); //if (filledCircle != null) //{ // filledCircle.MarkForDelete(); // filledCircle.Save(); //} }
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 static void ClearAllFromDB() { BusinessObjectCollection <OrganisationTestBO> col = new BusinessObjectCollection <OrganisationTestBO>(); col.LoadAll(); while (col.Count > 0) { OrganisationTestBO obj = col[0]; obj.MarkForDelete(); } col.SaveAll(); }
public static void ClearTable() { BusinessObjectCollection <OrderItem> col = new BusinessObjectCollection <OrderItem>(); col.LoadAll(); OrderItem item; while (col.Count > 0) { item = col[0]; item.MarkForDelete(); } col.SaveAll(); }
public void Test_MarkForDelete_Added_SaveAll() { //---------------Set up test pack------------------- BusinessObjectCollection <ContactPersonTestBO> cpCol = new BusinessObjectCollection <ContactPersonTestBO>(); ContactPersonTestBO myBO = ContactPersonTestBO.CreateSavedContactPerson("BB"); cpCol.Add(myBO); myBO.MarkForDelete(); //---------------Assert Precondition---------------- BusinessObjectCollectionTestHelper.AssertOneObjectInMarkForDeleteAndAddedCollection(cpCol); Assert.IsTrue(myBO.Status.IsDirty); //---------------Execute Test ---------------------- cpCol.SaveAll(); //---------------Test Result ----------------------- BusinessObjectCollectionTestHelper.AssertAllCollectionsHaveNoItems(cpCol); Assert.IsFalse(myBO.Status.IsDirty); }
public void TestAddMethod_SaveAllBusinessObject() { //---------------Set up test pack------------------- BusinessObjectCollection <ContactPersonTestBO> cpCol = new BusinessObjectCollection <ContactPersonTestBO>(); ContactPersonTestBO myBO = ContactPersonTestBO.CreateSavedContactPerson(); cpCol.Add(myBO); myBO.Surname = TestUtil.GetRandomString(); _businessObjectCollectionTestHelper.RegisterForAddedEvent(cpCol); //---------------Assert Precondition---------------- BusinessObjectCollectionTestHelper.AssertOneObjectInCurrentAndAddedCollection(cpCol); Assert.IsTrue(myBO.Status.IsDirty); _businessObjectCollectionTestHelper.AssertAddedEventNotFired(); //---------------Execute Test ---------------------- cpCol.SaveAll(); //---------------Test Result ----------------------- BusinessObjectCollectionTestHelper.AssertOneObjectInCurrentPersistedAndAddedCollection(cpCol); Assert.IsFalse(myBO.Status.IsDirty); _businessObjectCollectionTestHelper.AssertAddedEventNotFired(); }
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 static void ClearAllFromDB() { BusinessObjectCollection<OrganisationTestBO> col = new BusinessObjectCollection<OrganisationTestBO>(); col.LoadAll(); while (col.Count > 0) { OrganisationTestBO obj = col[0]; obj.MarkForDelete(); } col.SaveAll(); }
public void Test_MarkForDelete_Added_SaveAll() { //---------------Set up test pack------------------- BusinessObjectCollection<ContactPersonTestBO> cpCol = new BusinessObjectCollection<ContactPersonTestBO>(); ContactPersonTestBO myBO = ContactPersonTestBO.CreateSavedContactPerson("BB"); cpCol.Add(myBO); myBO.MarkForDelete(); //---------------Assert Precondition---------------- BusinessObjectCollectionTestHelper.AssertOneObjectInMarkForDeleteAndAddedCollection(cpCol); Assert.IsTrue(myBO.Status.IsDirty); //---------------Execute Test ---------------------- cpCol.SaveAll(); //---------------Test Result ----------------------- BusinessObjectCollectionTestHelper.AssertAllCollectionsHaveNoItems(cpCol); Assert.IsFalse(myBO.Status.IsDirty); }
public void TestAddMethod_SaveAllBusinessObject() { //---------------Set up test pack------------------- BusinessObjectCollection<ContactPersonTestBO> cpCol = new BusinessObjectCollection<ContactPersonTestBO>(); ContactPersonTestBO myBO = ContactPersonTestBO.CreateSavedContactPerson(); cpCol.Add(myBO); myBO.Surname = TestUtil.GetRandomString(); _businessObjectCollectionTestHelper.RegisterForAddedEvent(cpCol); //---------------Assert Precondition---------------- BusinessObjectCollectionTestHelper.AssertOneObjectInCurrentAndAddedCollection(cpCol); Assert.IsTrue(myBO.Status.IsDirty); _businessObjectCollectionTestHelper.AssertAddedEventNotFired(); //---------------Execute Test ---------------------- cpCol.SaveAll(); //---------------Test Result ----------------------- BusinessObjectCollectionTestHelper.AssertOneObjectInCurrentPersistedAndAddedCollection(cpCol); Assert.IsFalse(myBO.Status.IsDirty); _businessObjectCollectionTestHelper.AssertAddedEventNotFired(); }
public static void ClearTable() { BusinessObjectCollection<OrderItem> col = new BusinessObjectCollection<OrderItem>(); col.LoadAll(); OrderItem item; while (col.Count > 0) { item = col[0]; item.MarkForDelete(); } col.SaveAll(); }
public void Test_CreatedBusinessObject_SaveAll() { //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------------------- 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 ---------------------- cpCol.SaveAll(); //---------------Test Result ----------------------- Assert.IsFalse(_addedEventFired); Assert.Contains(newCP, cpCol); AssertOneObjectInCurrentAndPersistedCollection(cpCol); }
public void Test_RestoreAll() { ContactPersonTestBO.LoadDefaultClassDef(); ContactPersonTestBO contact1 = new ContactPersonTestBO {Surname = "Soap"}; ContactPersonTestBO contact2 = new ContactPersonTestBO {Surname = "Hope"}; BusinessObjectCollection<ContactPersonTestBO> col = new BusinessObjectCollection<ContactPersonTestBO> {contact1, contact2}; col.SaveAll(); Assert.AreEqual("Soap", col[0].Surname); Assert.AreEqual("Hope", col[1].Surname); contact1.Surname = "Cope"; contact2.Surname = "Pope"; Assert.AreEqual("Cope", col[0].Surname); Assert.AreEqual("Pope", col[1].Surname); col.CancelEdits(); Assert.AreEqual("Soap", col[0].Surname); Assert.AreEqual("Hope", col[1].Surname); contact1.MarkForDelete(); contact2.MarkForDelete(); col.SaveAll(); Assert.AreEqual(0, col.Count); }