Пример #1
0
 private static OrganisationPerson CreateUnsavedOrganisationPerson(Person person, Organisation organisation)
 {
     OrganisationPerson organisationPerson = new OrganisationPerson();
     organisationPerson.Person = person;
     organisationPerson.Organisation = organisation;
     return organisationPerson;
 }
        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
 private static Person CreateUnsavedPerson(string firstName)
 {
     Person person = new Person();
     person.FirstName = firstName;
     return person;
 }
Пример #4
0
 public static OrganisationPerson CreateSavedOrganisationPerson(Person person, Organisation organisation)
 {
     OrganisationPerson organisationPerson = CreateUnsavedOrganisationPerson(person, organisation);
     organisationPerson.Save();
     return organisationPerson;
 }
        public void Test_NewParentWithClassTableInheritance_NewChild()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            ClassDef.ClassDefs.Add(new XmlClassDefsLoader(BOBroker.GetClassDefsXml(), new DtdLoader(), new DefClassFactory()).LoadClassDefs());

            Habanero.Test.Structure.Person person = new Person();
            person.LastName = "bob";
            Vehicle vehicle = new Vehicle();
            vehicle.DateAssembled = DateTime.Now;
            person.VehiclesOwned.Add(vehicle);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            TransactionCommitter committer = (TransactionCommitter) BORegistry.DataAccessor.CreateTransactionCommitter();
            committer.AddBusinessObject(person);
            committer.CommitTransaction();
            //---------------Test Result -----------------------
            Assert.AreEqual(2, committer.OriginalTransactions.Count, "There should only be two transactions: one insert for the person and one insert for the vehicle"); 

        }