public static Person CreateSavedPerson() { Person person = CreateUnsavedPerson(); person.Save(); return(person); }
public static Person CreateSavedPerson(string firstName) { Person person = CreateUnsavedPerson(firstName); person.Save(); return(person); }
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); }