public void FinishTransport_FilterNew()
        {
            TransportedDomainObjects transportedObjects = TransportAndDeleteObjects(
                DomainObjectIDs.ClassWithAllDataTypes1,
                DomainObjectIDs.ClassWithAllDataTypes2);

            transportedObjects.FinishTransport(transportedObject =>
            {
                Assert.That(transportedObject.State == StateType.New);
                return(((ClassWithAllDataTypes)transportedObject).Int32Property < 0);
            });

            using (ClientTransaction.CreateRootTransaction().EnterNonDiscardingScope())
            {
                try
                {
                    DomainObjectIDs.ClassWithAllDataTypes1.GetObject <ClassWithAllDataTypes> ();
                    Assert.Fail("Expected ObjectsNotFoundException");
                }
                catch (ObjectsNotFoundException)
                {
                    // ok
                }

                ClassWithAllDataTypes c2 = DomainObjectIDs.ClassWithAllDataTypes2.GetObject <ClassWithAllDataTypes> ();
                Assert.That(c2.Int32Property, Is.EqualTo(-2147483647));
            }
        }
        public void FinishTransport_CallsCommit()
        {
            TransportedDomainObjects transportedObjects = TransportAndDeleteObjects(
                DomainObjectIDs.ClassWithAllDataTypes1,
                DomainObjectIDs.ClassWithAllDataTypes2);
            var mockRepository = new MockRepository();
            var extensionMock  = mockRepository.StrictMock <IClientTransactionExtension>();

            extensionMock.Expect(mock => mock.Committing(
                                     Arg.Is(transportedObjects.DataTransaction),
                                     Arg <ReadOnlyCollection <DomainObject> > .List.Equivalent(GetTransportedObjects(transportedObjects)),
                                     Arg <ICommittingEventRegistrar> .Is.Anything));
            extensionMock.Expect(mock => mock.CommitValidate(
                                     Arg.Is(transportedObjects.DataTransaction),
                                     Arg <ReadOnlyCollection <PersistableData> > .Matches(c => c.Select(d => d.DomainObject).SetEquals(GetTransportedObjects(transportedObjects)))));
            extensionMock.Expect(mock => mock.Committed(
                                     Arg.Is(transportedObjects.DataTransaction),
                                     Arg <ReadOnlyCollection <DomainObject> > .List.Equivalent(GetTransportedObjects(transportedObjects))));
            extensionMock.Expect(mock => mock.TransactionDiscard(transportedObjects.DataTransaction));

            extensionMock.Stub(stub => stub.Key).Return("mock");

            mockRepository.ReplayAll();

            transportedObjects.DataTransaction.Extensions.Add(extensionMock);
            transportedObjects.FinishTransport();

            mockRepository.VerifyAll();
        }
Esempio n. 3
0
        public void SpecialStrategy()
        {
            TransportItem[] items;
            using (ClientTransaction.CreateRootTransaction().EnterNonDiscardingScope())
            {
                items = new[] { TransportItem.PackageDataContainer(DomainObjectIDs.Order1.GetObject <Order> ().InternalDataContainer) };
            }

            var repository   = new MockRepository();
            var strategyMock = repository.StrictMock <IImportStrategy>();
            var streamFake   = repository.Stub <Stream> ();

            strategyMock.Expect(mock => mock.Import(streamFake)).Return(items);

            strategyMock.Replay();

            var importer = DomainObjectImporter.CreateImporterFromStream(streamFake, strategyMock);
            TransportedDomainObjects result = importer.GetImportedObjects();

            Assert.That(
                result.TransportedObjects,
                Is.EquivalentTo(LifetimeService.GetObjects <Order> (result.DataTransaction, DomainObjectIDs.Order1)));

            strategyMock.VerifyAllExpectations();
        }
        public void FinishTransport_Twice()
        {
            TransportedDomainObjects transportedObjects = TransportAndDeleteObjects(
                DomainObjectIDs.ClassWithAllDataTypes1,
                DomainObjectIDs.ClassWithAllDataTypes2);

            transportedObjects.FinishTransport(delegate { return(false); });
            transportedObjects.FinishTransport();
        }
        public void EmptyTransport()
        {
            ClientTransaction dataTransaction = ClientTransaction.CreateRootTransaction();
            var transportedObjects            = new TransportedDomainObjects(dataTransaction, new List <DomainObject>());

            Assert.That(transportedObjects.DataTransaction, Is.Not.Null);
            Assert.That(transportedObjects.DataTransaction, Is.SameAs(dataTransaction));
            Assert.That(GetTransportedObjects(transportedObjects), Is.Empty);
        }
Esempio n. 6
0
        public void TransactionContainsMoreObjects_ThanAreTransported()
        {
            _transporter.LoadRecursive(DomainObjectIDs.Employee1, new FollowAllProcessNoneStrategy());
            Assert.That(_transporter.ObjectIDs.Count, Is.EqualTo(0));
            Assert.That(new List <ObjectID> (_transporter.ObjectIDs), Is.Empty);

            TransportedDomainObjects transportedObjects = ExportAndLoadTransportData();

            Assert.That(transportedObjects.TransportedObjects, Is.Empty);
        }
        public void FinishTransport_ClearsTransportedObjects()
        {
            TransportedDomainObjects transportedObjects = TransportAndDeleteObjects(
                DomainObjectIDs.ClassWithAllDataTypes1,
                DomainObjectIDs.ClassWithAllDataTypes2);

            transportedObjects.FinishTransport(delegate { return(false); });
            Assert.That(transportedObjects.DataTransaction, Is.Null);
            Assert.That(transportedObjects.TransportedObjects, Is.Null);
        }
        public void FinishTransport_WithInactiveTTransaction()
        {
            var dataTransaction    = ClientTransaction.CreateRootTransaction();
            var transportedObjects = new TransportedDomainObjects(dataTransaction, new List <DomainObject>());

            using (ClientTransactionTestHelper.MakeInactive(dataTransaction))
            {
                Assert.That(
                    () => transportedObjects.FinishTransport(),
                    Throws.TypeOf <ClientTransactionReadOnlyException>());
            }
        }
Esempio n. 9
0
        public void NonEmptyTransport_ObjectsBoundToTransaction()
        {
            var loadedIDs = new[] { DomainObjectIDs.Order1, DomainObjectIDs.Order3, DomainObjectIDs.Company1 };
            var data      = DomainObjectTransporterTestHelper.GetBinaryDataFor(loadedIDs);

            TransportedDomainObjects transportedObjects = DomainObjectTransporterTestHelper.Import(data);

            foreach (DomainObject domainObject in transportedObjects.TransportedObjects)
            {
                Assert.That(domainObject.RootTransaction, Is.SameAs(transportedObjects.DataTransaction));
            }
        }
        public void FinishTransport_DiscardsTransaction()
        {
            TransportedDomainObjects transportedObjects = TransportAndDeleteObjects(
                DomainObjectIDs.ClassWithAllDataTypes1,
                DomainObjectIDs.ClassWithAllDataTypes2);

            var transaction = transportedObjects.DataTransaction;

            transportedObjects.FinishTransport();

            Assert.That(transaction.IsDiscarded, Is.True);
        }
Esempio n. 11
0
        public void LoadTransportData_XmlStrategy()
        {
            _transporter.Load(DomainObjectIDs.Employee1);
            _transporter.Load(DomainObjectIDs.Employee2);

            TransportedDomainObjects transportedObjects = ExportAndLoadTransportData(XmlImportStrategy.Instance, XmlExportStrategy.Instance);

            Assert.That(transportedObjects, Is.Not.Null);
            var domainObjects = new List <DomainObject> (transportedObjects.TransportedObjects);

            Assert.That(domainObjects.Count, Is.EqualTo(2));
            Assert.That(domainObjects.ConvertAll(obj => obj.ID), Is.EquivalentTo(new[] { DomainObjectIDs.Employee1, DomainObjectIDs.Employee2 }));
        }
        public void TransportedObjectsStayConstant_WhenTransactionIsManipulated()
        {
            var transportedObjects = new TransportedDomainObjects(ClientTransaction.CreateRootTransaction(), new List <DomainObject>());

            Assert.That(GetTransportedObjects(transportedObjects), Is.Empty);

            using (transportedObjects.DataTransaction.EnterNonDiscardingScope())
            {
                DomainObjectIDs.Order1.GetObject <Order> ();
            }

            Assert.That(GetTransportedObjects(transportedObjects), Is.Empty);
        }
        public void FinishTransport_WithoutFilter()
        {
            TransportedDomainObjects transportedObjects = TransportAndDeleteObjects(
                DomainObjectIDs.ClassWithAllDataTypes1,
                DomainObjectIDs.ClassWithAllDataTypes2);

            transportedObjects.FinishTransport();

            using (ClientTransaction.CreateRootTransaction().EnterNonDiscardingScope())
            {
                ClassWithAllDataTypes c3 = DomainObjectIDs.ClassWithAllDataTypes1.GetObject <ClassWithAllDataTypes> ();
                ClassWithAllDataTypes c4 = DomainObjectIDs.ClassWithAllDataTypes2.GetObject <ClassWithAllDataTypes> ();

                Assert.That(c3.Int32Property, Is.EqualTo(2147483647));
                Assert.That(c4.Int32Property, Is.EqualTo(-2147483647));
            }
        }
        public void NonEmptyTransport()
        {
            ClientTransaction newTransaction = ClientTransaction.CreateRootTransaction();
            var transportedObjectList        = new List <DomainObject>();

            using (newTransaction.EnterNonDiscardingScope())
            {
                transportedObjectList.Add(DomainObjectIDs.Order1.GetObject <Order> ());
                transportedObjectList.Add(DomainObjectIDs.Order3.GetObject <Order> ());
                transportedObjectList.Add(DomainObjectIDs.Company1.GetObject <Company> ());
            }

            var transportedObjects = new TransportedDomainObjects(newTransaction, transportedObjectList);

            Assert.That(transportedObjects.DataTransaction, Is.Not.Null);
            Assert.IsNotEmpty(GetTransportedObjects(transportedObjects));
            List <ObjectID> ids = GetTransportedObjects(transportedObjects).ConvertAll(obj => obj.ID);

            Assert.That(ids, Is.EquivalentTo(new[] { DomainObjectIDs.Order1, DomainObjectIDs.Order3, DomainObjectIDs.Company1 }));
        }
        public void FinishTransport_FilterExisting()
        {
            TransportedDomainObjects transportedObjects = TransportAndChangeObjects(
                typeof(ClassWithAllDataTypes).FullName + ".Int32Property",
                42,
                DomainObjectIDs.ClassWithAllDataTypes1,
                DomainObjectIDs.ClassWithAllDataTypes2);

            transportedObjects.FinishTransport(transportedObject =>
            {
                Assert.That(transportedObject.State == StateType.Changed);
                return(((ClassWithAllDataTypes)transportedObject).BooleanProperty);
            });

            using (ClientTransaction.CreateRootTransaction().EnterNonDiscardingScope())
            {
                var c1 = DomainObjectIDs.ClassWithAllDataTypes1.GetObject <ClassWithAllDataTypes> ();
                Assert.That(c1.Int32Property, Is.EqualTo(42));

                var c2 = DomainObjectIDs.ClassWithAllDataTypes2.GetObject <ClassWithAllDataTypes> ();
                Assert.That(c2.Int32Property, Is.Not.EqualTo(42));
            }
        }
        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));
        }
        public static List <DomainObject> ImportObjects(byte[] binaryData)
        {
            TransportedDomainObjects transportedObjects = Import(binaryData);

            return(new List <DomainObject> (transportedObjects.TransportedObjects));
        }
 private List <DomainObject> GetTransportedObjects(TransportedDomainObjects transportedObjects)
 {
     return(new List <DomainObject> (transportedObjects.TransportedObjects));
 }