Esempio n. 1
0
 public void LoadTransportData_InvalidData()
 {
     using (var stream = new MemoryStream(new byte[] { 1, 2, 3 }))
     {
         DomainObjectTransporter.LoadTransportData(stream);
     }
 }
 public static byte[] GetBinaryDataFor(DomainObjectTransporter transporter)
 {
     using (var stream = new MemoryStream())
     {
         transporter.Export(stream);
         return(stream.ToArray());
     }
 }
        private TransportedDomainObjects Transport(DomainObjectTransporter transporter)
        {
            using (var stream = new MemoryStream())
            {
                transporter.Export(stream);
                stream.Seek(0, SeekOrigin.Begin);

                return(DomainObjectTransporter.LoadTransportData(stream));
            }
        }
        public static byte[] GetBinaryDataFor(params ObjectID[] ids)
        {
            var transporter = new DomainObjectTransporter();

            foreach (ObjectID id in ids)
            {
                transporter.Load(id);
            }
            return(GetBinaryDataFor(transporter));
        }
Esempio n. 5
0
        private byte[] GetBinaryDataForChangedObject(ObjectID id, string propertyToTouch, object newValue)
        {
            var transporter = new DomainObjectTransporter();

            transporter.Load(id);
            var domainObject = transporter.GetTransportedObject(id);
            var properties   = new PropertyIndexer(domainObject);

            properties[propertyToTouch].SetValueWithoutTypeCheck(newValue);
            return(DomainObjectTransporterTestHelper.GetBinaryDataFor(transporter));
        }
Esempio n. 6
0
        public void NonExistingObjects_NewInSource()
        {
            var transporter   = new DomainObjectTransporter();
            var outerComputer = (Computer)transporter.LoadNew(typeof(Computer), ParamList.Empty);

            byte[] binaryData = DomainObjectTransporterTestHelper.GetBinaryDataFor(transporter);

            var imported = DomainObjectTransporterTestHelper.ImportObjects(binaryData);

            Assert.That(imported[0].State, Is.EqualTo(StateType.New));
            Assert.That(imported[0].ID, Is.EqualTo(outerComputer.ID));
        }
Esempio n. 7
0
        public void ChangedBySource_RelatedObjectToNew()
        {
            var transporter = new DomainObjectTransporter();
            var computer    = (Computer)transporter.LoadNew(typeof(Computer), ParamList.Empty);
            var employee    = (Employee)transporter.LoadNew(typeof(Employee), ParamList.Empty);

            computer.Employee = employee;

            byte[] binaryData = DomainObjectTransporterTestHelper.GetBinaryDataFor(transporter);
            var    imported   = DomainObjectTransporterTestHelper.ImportObjects(binaryData);

            var loadedObject1 = (Computer)imported.Find(obj => obj is Computer);
            var loadedObject2 = (Employee)imported.Find(obj => obj is Employee);

            Assert.That(loadedObject1.Employee, Is.SameAs(loadedObject2));
        }
Esempio n. 8
0
        public void ChangedBySource_RelatedObjectToExistingObject_VirtualSide()
        {
            var transporter = new DomainObjectTransporter();

            transporter.Load(DomainObjectIDs.Computer1);
            transporter.Load(DomainObjectIDs.Computer2);
            transporter.Load(DomainObjectIDs.Employee3);
            transporter.Load(DomainObjectIDs.Employee4);
            var employee = (Employee)transporter.GetTransportedObject(DomainObjectIDs.Employee3);

            employee.Computer = (Computer)transporter.GetTransportedObject(DomainObjectIDs.Computer2);

            byte[] binaryData    = DomainObjectTransporterTestHelper.GetBinaryDataFor(transporter);
            var    imported      = DomainObjectTransporterTestHelper.ImportObjects(binaryData);
            var    loadedObject1 = (Computer)imported.Find(obj => obj.ID == DomainObjectIDs.Computer2);
            var    loadedObject2 = (Employee)imported.Find(obj => obj.ID == DomainObjectIDs.Employee3);

            Assert.That(loadedObject2.Computer, Is.SameAs(loadedObject1));
        }
        private TransportedDomainObjects TransportAndDeleteObjects(params ObjectID[] objectsToLoadAndDelete)
        {
            var transporter = new DomainObjectTransporter();

            foreach (ObjectID id in objectsToLoadAndDelete)
            {
                transporter.Load(id);
            }

            ModifyDatabase(
                delegate
            {
                foreach (var id in objectsToLoadAndDelete)
                {
                    var domainObject = LifetimeService.GetObject(ClientTransaction.Current, id, false);
                    LifetimeService.DeleteObject(ClientTransaction.Current, domainObject);
                }
            });

            return(Transport(transporter));
        }
        private TransportedDomainObjects TransportAndChangeObjects(string propertyName, object newValue, params ObjectID[] objectsToLoadAndDelete)
        {
            var transporter = new DomainObjectTransporter();

            foreach (ObjectID id in objectsToLoadAndDelete)
            {
                transporter.Load(id);
            }

            ModifyDatabase(
                delegate
            {
                foreach (var id in objectsToLoadAndDelete)
                {
                    var domainObject = LifetimeService.GetObject(ClientTransaction.Current, id, false);
                    var properties   = new PropertyIndexer(domainObject);
                    properties[propertyName].SetValueWithoutTypeCheck(newValue);
                }
            });

            return(Transport(transporter));
        }
Esempio n. 11
0
        public void OnObjectImportedCallback()
        {
            var transporter = new DomainObjectTransporter();
            var instance    = (DomainObjectWithImportCallback)transporter.LoadNew(typeof(DomainObjectWithImportCallback), ParamList.Empty);

            instance.Property = 17;

            byte[] binaryData = DomainObjectTransporterTestHelper.GetBinaryDataFor(transporter);

            var facade = RootPersistenceStrategyMockFacade.CreateWithStrictMock();

            facade.ExpectLoadObjectData(new[] { instance.ID });
            using (facade.CreateScope())
            {
                var imported = DomainObjectTransporterTestHelper.ImportObjects(binaryData);

                var importedInstance = (DomainObjectWithImportCallback)imported.Single();
                Assert.That(importedInstance.CallbackCalled, Is.True);
                Assert.That(importedInstance.PropertyValueInCallback, Is.EqualTo(17));
                Assert.That(importedInstance.CallbackTransaction, Is.SameAs(importedInstance.RootTransaction));
            }
        }
        public void FinishTransport_FilterCalledForEachChangedObject()
        {
            var transporter = new DomainObjectTransporter();

            transporter.Load(DomainObjectIDs.ClassWithAllDataTypes1);
            transporter.Load(DomainObjectIDs.ClassWithAllDataTypes2);
            transporter.Load(DomainObjectIDs.Order1);

            ModifyDatabase(
                delegate
            {
                ClassWithAllDataTypes c1 = DomainObjectIDs.ClassWithAllDataTypes1.GetObject <ClassWithAllDataTypes> ();
                ClassWithAllDataTypes c2 = DomainObjectIDs.ClassWithAllDataTypes2.GetObject <ClassWithAllDataTypes> ();
                c1.Delete();
                c2.Delete();
            });

            TransportedDomainObjects transportedObjects = Transport(transporter);

            var expectedObjects = new List <DomainObject>();

            using (transportedObjects.DataTransaction.EnterNonDiscardingScope())
            {
                expectedObjects.Add(DomainObjectIDs.ClassWithAllDataTypes1.GetObject <ClassWithAllDataTypes> ());
                expectedObjects.Add(DomainObjectIDs.ClassWithAllDataTypes2.GetObject <ClassWithAllDataTypes> ());
            }

            var filteredObjects = new List <DomainObject>();

            transportedObjects.FinishTransport(
                delegate(DomainObject domainObject)
            {
                filteredObjects.Add(domainObject);
                return(true);
            });
            Assert.That(filteredObjects, Is.EquivalentTo(expectedObjects));
        }
Esempio n. 13
0
 public override void SetUp()
 {
     base.SetUp();
     _transporter = new DomainObjectTransporter();
     _listener    = new TransportTransactionListener(_transporter);
 }
Esempio n. 14
0
 private TransportedDomainObjects ExportAndLoadTransportData(IImportStrategy importStrategy, IExportStrategy exportStrategy)
 {
     _transporter.Export(_stream, exportStrategy);
     _stream.Seek(0, SeekOrigin.Begin);
     return(DomainObjectTransporter.LoadTransportData(_stream, importStrategy));
 }
Esempio n. 15
0
 public override void SetUp()
 {
     base.SetUp();
     _transporter = new DomainObjectTransporter();
     _stream      = new MemoryStream();
 }
Esempio n. 16
0
 private TransportedDomainObjects ExportAndLoadTransportData()
 {
     _transporter.Export(_stream);
     _stream.Seek(0, SeekOrigin.Begin);
     return(DomainObjectTransporter.LoadTransportData(_stream));
 }