Пример #1
0
        public void DomainObjectCollection_Events_Contents()
        {
            var collection = new DomainObjectCollection(typeof(Order))
            {
                DomainObjectIDs.Order1.GetObject <Order> ()
            };

            var eventReceiver = new DomainObjectCollectionEventReceiver(collection);

            var deserializedCollectionAndEventReceiver = Serializer.SerializeAndDeserialize(Tuple.Create(collection, eventReceiver));
            var deserializedCollection    = deserializedCollectionAndEventReceiver.Item1;
            var deserializedEventReceiver = deserializedCollectionAndEventReceiver.Item2;

            Assert.That(deserializedEventReceiver.HasAddedEventBeenCalled, Is.False);
            Assert.That(deserializedEventReceiver.HasAddingEventBeenCalled, Is.False);
            Assert.That(deserializedEventReceiver.HasRemovedEventBeenCalled, Is.False);
            Assert.That(deserializedEventReceiver.HasRemovingEventBeenCalled, Is.False);

            deserializedCollection.Add(Order.NewObject());
            deserializedCollection.RemoveAt(0);

            Assert.That(deserializedEventReceiver.HasAddedEventBeenCalled, Is.True);
            Assert.That(deserializedEventReceiver.HasAddingEventBeenCalled, Is.True);
            Assert.That(deserializedEventReceiver.HasRemovedEventBeenCalled, Is.True);
            Assert.That(deserializedEventReceiver.HasRemovingEventBeenCalled, Is.True);
        }
        public void CreateReplaceCommand()
        {
            var oldRelatedObject   = DomainObjectMother.CreateFakeObject <Order> ();
            var fakeCollectionData = new DomainObjectCollectionData(new[] { oldRelatedObject });

            _dataManagerMock.Stub(stub => stub.CollectionData).Return(fakeCollectionData);
            _dataManagerMock.Stub(stub => stub.ContainsOriginalItemWithoutEndPoint(_relatedObject)).Return(false);
            _dataManagerMock.Stub(stub => stub.ContainsOriginalItemWithoutEndPoint(oldRelatedObject)).Return(false);

            var fakeCollection = new DomainObjectCollection();

            _collectionEndPointMock.Stub(mock => mock.IsNull).Return(false);
            _collectionEndPointMock.Stub(mock => mock.Collection).Return(fakeCollection);
            _collectionEndPointMock.Stub(mock => mock.GetDomainObject()).Return(_owningObject);

            var command = (RelationEndPointModificationCommand)_loadState.CreateReplaceCommand(_collectionEndPointMock, 0, _relatedObject);

            Assert.That(command, Is.InstanceOf(typeof(CollectionEndPointReplaceCommand)));
            Assert.That(command.ModifiedEndPoint, Is.SameAs(_collectionEndPointMock));
            Assert.That(command.OldRelatedObject, Is.SameAs(oldRelatedObject));
            Assert.That(command.NewRelatedObject, Is.SameAs(_relatedObject));
            Assert.That(command.TransactionEventSink, Is.SameAs(_transactionEventSinkStub));

            Assert.That(((CollectionEndPointReplaceCommand)command).ModifiedCollectionData, Is.SameAs(fakeCollectionData));
            Assert.That(((CollectionEndPointReplaceCommand)command).ModifiedCollection, Is.SameAs(fakeCollection));
        }
Пример #3
0
        public void CheckRequiredItemTypeForNew()
        {
            Order order = Order.NewObject();
            DomainObjectCollection orderItems = order.OrderItems;

            orderItems.Add(Customer.NewObject());
        }
        public void CreateSetCollectionCommand()
        {
            var fakeCollectionData = new DomainObjectCollectionData();

            _dataManagerMock.Stub(stub => stub.CollectionData).Return(fakeCollectionData);
            _dataManagerMock.Stub(stub => stub.OriginalItemsWithoutEndPoints).Return(new DomainObject[0]);

            var fakeCollection = new DomainObjectCollection();

            _collectionEndPointMock.Stub(mock => mock.IsNull).Return(false);
            _collectionEndPointMock.Stub(mock => mock.Collection).Return(fakeCollection);
            _collectionEndPointMock.Stub(mock => mock.GetDomainObject()).Return(_owningObject);
            _collectionEndPointMock.Replay();

            var newCollection = new OrderCollection();

            var command = (RelationEndPointModificationCommand)_loadState.CreateSetCollectionCommand(_collectionEndPointMock, newCollection, _collectionManagerStub);

            Assert.That(command, Is.TypeOf(typeof(CollectionEndPointSetCollectionCommand)));
            Assert.That(command.ModifiedEndPoint, Is.SameAs(_collectionEndPointMock));
            Assert.That(command.TransactionEventSink, Is.SameAs(_transactionEventSinkStub));
            Assert.That(((CollectionEndPointSetCollectionCommand)command).NewCollection, Is.SameAs(newCollection));
            Assert.That(((CollectionEndPointSetCollectionCommand)command).CollectionEndPointCollectionManager, Is.SameAs(_collectionManagerStub));
            Assert.That(((CollectionEndPointSetCollectionCommand)command).ModifiedCollectionData, Is.SameAs(fakeCollectionData));
        }
Пример #5
0
        public void OrderCancelsChangeEvent()
        {
            DomainObject[]           domainObjectEventSources = new DomainObject[] { _oldCustomer, _newCustomer, _order1 };
            DomainObjectCollection[] collectionEventSources   = new DomainObjectCollection[] { _oldCustomer.Orders, _newCustomer.Orders };
            SequenceEventReceiver    eventReceiver            = new SequenceEventReceiver(domainObjectEventSources, collectionEventSources, 1);

            try
            {
                _newCustomer.Orders.Add(_order1);
                Assert.Fail("EventReceiverCancelException should be raised.");
            }
            catch (EventReceiverCancelException)
            {
                ChangeState[] expectedChangeStates = new ChangeState[]
                { new RelationChangeState(_order1, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.Customer", _oldCustomer, _newCustomer, "1. Changing event of order from old to new customer") };

                eventReceiver.Check(expectedChangeStates);

                Assert.That(_order1.State, Is.EqualTo(StateType.Unchanged));
                Assert.That(_oldCustomer.State, Is.EqualTo(StateType.Unchanged));
                Assert.That(_newCustomer.State, Is.EqualTo(StateType.Unchanged));

                Assert.That(_order1.Customer, Is.SameAs(_oldCustomer));
                Assert.That(_oldCustomer.Orders[_order1.ID], Is.SameAs(_order1));
                Assert.That(_newCustomer.Orders[_order1.ID], Is.Null);
            }
        }
Пример #6
0
        public override void SetUp()
        {
            base.SetUp();

            _order1 = DomainObjectIDs.Order1.GetObject <Order> (Transaction);
            _order2 = DomainObjectIDs.Order2.GetObject <Order> (Transaction);
            _order3 = DomainObjectIDs.Order3.GetObject <Order> (Transaction);

            // Collection currently contains _order1, _order2
            _modifiedCollectionData = new DomainObjectCollectionData(new[] { _order1, _order2 });

            // _order1 will stay, _order2 will be removed, _order3 will be added
            _newCollection = new OrderCollection {
                _order1, _order3
            };

            _mockRepository        = new MockRepository();
            _collectionManagerMock = _mockRepository.StrictMock <ICollectionEndPointCollectionManager> ();

            _command = new CollectionEndPointSetCollectionCommand(
                CollectionEndPoint,
                _newCollection,
                _modifiedCollectionData,
                _collectionManagerMock,
                TransactionEventSinkMock);
        }
        public void OldOrderCancelsReplace()
        {
            DomainObject[]           domainObjectEventSources = new DomainObject[] { _customer, _oldCustomerOfNewOrder, _oldOrder, _newOrder };
            DomainObjectCollection[] collectionEventSources   = new DomainObjectCollection[] { _customer.Orders, _oldCustomerOfNewOrder.Orders };

            SequenceEventReceiver eventReceiver =
                new SequenceEventReceiver(domainObjectEventSources, collectionEventSources, 1);

            int replaceIndex = _customer.Orders.IndexOf(_oldOrder);

            try
            {
                _customer.Orders[replaceIndex] = _newOrder;
                Assert.Fail("EventReceiverCancelException should be raised.");
            }
            catch (EventReceiverCancelException)
            {
                ChangeState[] expectedChangeStates = new ChangeState[]
                { new RelationChangeState(_oldOrder, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.Customer", _customer, null, "1. Changing event of old order from old customer to null") };

                eventReceiver.Check(expectedChangeStates);

                Assert.That(_customer.State, Is.EqualTo(StateType.Unchanged));
                Assert.That(_oldCustomerOfNewOrder.State, Is.EqualTo(StateType.Unchanged));
                Assert.That(_oldOrder.State, Is.EqualTo(StateType.Unchanged));
                Assert.That(_newOrder.State, Is.EqualTo(StateType.Unchanged));

                Assert.That(_customer.Orders[replaceIndex], Is.SameAs(_oldOrder));
                Assert.That(_oldOrder.Customer, Is.SameAs(_customer));

                Assert.That(_oldCustomerOfNewOrder.Orders.ContainsObject(_newOrder), Is.True);
                Assert.That(_newOrder.Customer, Is.SameAs(_oldCustomerOfNewOrder));
            }
        }
        public CollectionEndPointSetCollectionCommand(
            ICollectionEndPoint modifiedEndPoint,
            DomainObjectCollection newCollection,
            IDomainObjectCollectionData modifiedCollectionData,
            ICollectionEndPointCollectionManager collectionEndPointCollectionManager,
            IClientTransactionEventSink transactionEventSink)
            : base(
                ArgumentUtility.CheckNotNull("modifiedEndPoint", modifiedEndPoint),
                null,
                null,
                ArgumentUtility.CheckNotNull("transactionEventSink", transactionEventSink))
        {
            ArgumentUtility.CheckNotNull("newCollection", newCollection);
            ArgumentUtility.CheckNotNull("modifiedCollectionData", modifiedCollectionData);
            ArgumentUtility.CheckNotNull("collectionEndPointCollectionManager", collectionEndPointCollectionManager);

            if (modifiedEndPoint.IsNull)
            {
                throw new ArgumentException("Modified end point is null, a NullEndPointModificationCommand is needed.", "modifiedEndPoint");
            }

            _newCollection          = newCollection;
            _modifiedCollectionData = modifiedCollectionData;
            _collectionEndPointCollectionManager = collectionEndPointCollectionManager;

            var oldOppositeObjects = ModifiedCollectionData;

            _removedObjects = oldOppositeObjects.Where(oldObject => !NewCollection.Contains(oldObject.ID)).ToArray();

            var newOppositeObjects = NewCollection.Cast <DomainObject> ();

            _addedObjects = newOppositeObjects.Where(newObject => !ModifiedCollectionData.ContainsObjectID(newObject.ID)).ToArray();
        }
        public void RelationsFromConcreteSingle()
        {
            TICustomer customer = DomainObjectIDs.Customer.GetObject <TICustomer> ();

            Assert.That(customer.CreatedBy, Is.EqualTo("UnitTests"));
            Assert.That(customer.FirstName, Is.EqualTo("Zaphod"));
            Assert.That(customer.CustomerType, Is.EqualTo(CustomerType.Premium));

            TIRegion region = customer.Region;

            Assert.That(region, Is.Not.Null);
            Assert.That(region.ID, Is.EqualTo(DomainObjectIDs.Region));

            DomainObjectCollection orders = customer.Orders;

            Assert.That(orders.Count, Is.EqualTo(1));
            Assert.That(orders[0].ID, Is.EqualTo(DomainObjectIDs.Order));

            DomainObjectCollection historyEntries = customer.HistoryEntries;

            Assert.That(historyEntries.Count, Is.EqualTo(2));
            Assert.That(historyEntries[0].ID, Is.EqualTo(DomainObjectIDs.HistoryEntry2));
            Assert.That(historyEntries[1].ID, Is.EqualTo(DomainObjectIDs.HistoryEntry1));

            TIClient client = customer.Client;

            Assert.That(client.ID, Is.EqualTo(DomainObjectIDs.Client));

            Assert.That(customer.AbstractClassesWithoutDerivations, Is.Empty);
        }
Пример #10
0
        public CollectionEndPointRemoveCommand(
            ICollectionEndPoint modifiedEndPoint,
            DomainObject removedObject,
            IDomainObjectCollectionData collectionData,
            IRelationEndPointProvider endPointProvider,
            IClientTransactionEventSink transactionEventSink)
            : base(
                ArgumentUtility.CheckNotNull("modifiedEndPoint", modifiedEndPoint),
                ArgumentUtility.CheckNotNull("removedObject", removedObject),
                null,
                ArgumentUtility.CheckNotNull("transactionEventSink", transactionEventSink))
        {
            ArgumentUtility.CheckNotNull("collectionData", collectionData);
            ArgumentUtility.CheckNotNull("endPointProvider", endPointProvider);

            if (modifiedEndPoint.IsNull)
            {
                throw new ArgumentException("Modified end point is null, a NullEndPointModificationCommand is needed.", "modifiedEndPoint");
            }

            _index = modifiedEndPoint.Collection.IndexOf(removedObject);
            _modifiedCollectionData = collectionData;
            _modifiedCollection     = modifiedEndPoint.Collection;
            _endPointProvider       = endPointProvider;
        }
        public void RollbackDeletionWithRelationChange()
        {
            Order order = DomainObjectIDs.Order1.GetObject <Order> ();

            OrderTicket            oldOrderTicket = order.OrderTicket;
            DomainObjectCollection oldOrderItems  = order.GetOriginalRelatedObjects("Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.OrderItems");
            Customer oldCustomer = order.Customer;
            Official oldOfficial = order.Official;

            order.Delete();

            Assert.That(order.OrderTicket, Is.Null);
            Assert.That(order.OrderItems.Count, Is.EqualTo(0));
            Assert.That(order.Customer, Is.Null);
            Assert.That(order.Official, Is.Null);

            TestableClientTransaction.Rollback();

            Assert.That(order.OrderTicket, Is.SameAs(oldOrderTicket));
            Assert.That(order.OrderItems.Count, Is.EqualTo(oldOrderItems.Count));
            Assert.That(order.OrderItems[DomainObjectIDs.OrderItem1], Is.SameAs(oldOrderItems[DomainObjectIDs.OrderItem1]));
            Assert.That(order.OrderItems[DomainObjectIDs.OrderItem2], Is.SameAs(oldOrderItems[DomainObjectIDs.OrderItem2]));
            Assert.That(order.Customer, Is.SameAs(oldCustomer));
            Assert.That(order.Official, Is.SameAs(oldOfficial));
        }
        public static T GetDataStrategyAndCheckType <T> (DomainObjectCollection collection) where T : IDomainObjectCollectionData
        {
            var data = GetDataStrategy(collection);

            Assert.That(data, Is.InstanceOf(typeof(T)));
            return((T)data);
        }
Пример #13
0
        public void CopyEventHandlersFrom()
        {
            var source      = new DomainObjectCollection();
            var destination = new DomainObjectCollection();

            source.Added    += delegate { };
            source.Added    += delegate { };
            source.Adding   += delegate { };
            source.Adding   += delegate { };
            source.Removed  += delegate { };
            source.Removed  += delegate { };
            source.Removing += delegate { };
            source.Removing += delegate { };
            source.Deleted  += delegate { };
            source.Deleted  += delegate { };
            source.Deleting += delegate { };
            source.Deleting += delegate { };

            CallCopyEventHandlersFrom(source, destination);

            CheckSameEventHandlers(source, destination, "Adding");
            CheckSameEventHandlers(source, destination, "Added");
            CheckSameEventHandlers(source, destination, "Removing");
            CheckSameEventHandlers(source, destination, "Removed");
            CheckSameEventHandlers(source, destination, "Deleting");
            CheckSameEventHandlers(source, destination, "Deleted");
        }
Пример #14
0
        public void RollbackCollectionReference()
        {
            if (_originalCollectionReference == null)
            {
                Assertion.DebugAssert(_currentCollectionReference == null);
                return;
            }

            if (_currentCollectionReference == null)
            {
                return;
            }

            if (_originalCollectionReference == _currentCollectionReference)
            {
                return;
            }

            // If the end-point's current collection is still associated with this end point, transform it to stand-alone.
            // (During rollback, the current relation might have already been associated with another end-point, we must not overwrite this!)
            var oldCollection = (IAssociatableDomainObjectCollection)GetCurrentCollectionReference();

            if (oldCollection.AssociatedEndPointID == _endPointID)
            {
                oldCollection.TransformToStandAlone();
            }

            // We must always associate the new collection with the end point, however - even during rollback phase,
            ((IAssociatableDomainObjectCollection)_originalCollectionReference).TransformToAssociated(_endPointID, _dataStrategyFactory);
            _currentCollectionReference = _originalCollectionReference;
            Assertion.DebugAssert(!HasCollectionReferenceChanged());
        }
        public void Initialization_NoRequiredItemType_DomainObjectWorks()
        {
            var wrappedCollection = new DomainObjectCollection();
            var wrapper           = new DomainObjectCollectionWrapper <DomainObject> (wrappedCollection);

            Assert.That(wrapper.WrappedCollection, Is.SameAs(wrappedCollection));
        }
Пример #16
0
        public void GetChildrenTwice()
        {
            Employee employee = DomainObjectIDs.Employee1.GetObject <Employee> ();
            DomainObjectCollection subordinates = employee.Subordinates;

            Assert.That(ReferenceEquals(subordinates, employee.Subordinates), Is.True);
        }
        public static void CheckAssociatedCollectionStrategy(DomainObjectCollection collection, Type expectedRequiredItemType, RelationEndPointID expectedEndPointID)
        {
            // collection => checking checking decorator => end point data => actual data store
            var checkingDecorator = GetDataStrategy(collection);

            CheckAssociatedCollectionStrategy(checkingDecorator, expectedRequiredItemType, expectedEndPointID);
        }
Пример #18
0
        public void LoadObjectsOverRelationWithAbstractBaseClass()
        {
            const int numberOfTests = 10;

            Console.WriteLine("Expected average duration of LoadObjectsOverRelationWithAbstractBaseClass on reference system: ~193 ms (release build), ~262 ms (debug build)");

            Stopwatch stopwatch = new Stopwatch();

            for (int i = 0; i < numberOfTests; i++)
            {
                using (ClientTransaction.CreateRootTransaction().EnterScope(AutoRollbackBehavior.None))
                {
                    Client client = _clientID.GetObject <Client>();

                    stopwatch.Start();

                    DomainObjectCollection clientBoundBaseClasses = client.ClientBoundBaseClasses;

                    stopwatch.Stop();
                    Assert.That(clientBoundBaseClasses.Count, Is.EqualTo(4000));
                }
            }

            double averageMilliSeconds = stopwatch.ElapsedMilliseconds / numberOfTests;

            Console.WriteLine(
                "LoadObjectsOverRelationWithAbstractBaseClass (executed {0}x): Average duration: {1} ms", numberOfTests, averageMilliSeconds.ToString("n"));
        }
        public void CreateAddCommand()
        {
            var fakeCollectionData =
                new DomainObjectCollectionData(new[] { DomainObjectMother.CreateFakeObject <Order> (), DomainObjectMother.CreateFakeObject <Order> () });

            _dataManagerMock.Stub(stub => stub.CollectionData).Return(fakeCollectionData);
            _dataManagerMock.Stub(stub => stub.ContainsOriginalItemWithoutEndPoint(_relatedObject)).Return(false);

            var fakeCollection = new DomainObjectCollection();

            _collectionEndPointMock.Stub(mock => mock.IsNull).Return(false);
            _collectionEndPointMock.Stub(mock => mock.Collection).Return(fakeCollection);
            _collectionEndPointMock.Stub(mock => mock.GetDomainObject()).Return(_owningObject);

            var command = (RelationEndPointModificationCommand)_loadState.CreateAddCommand(_collectionEndPointMock, _relatedObject);

            Assert.That(command, Is.InstanceOf(typeof(CollectionEndPointInsertCommand)));
            Assert.That(command.ModifiedEndPoint, Is.SameAs(_collectionEndPointMock));
            Assert.That(command.NewRelatedObject, Is.SameAs(_relatedObject));
            Assert.That(((CollectionEndPointInsertCommand)command).Index, Is.EqualTo(2));

            Assert.That(((CollectionEndPointInsertCommand)command).ModifiedCollectionData, Is.SameAs(fakeCollectionData));
            Assert.That(((CollectionEndPointInsertCommand)command).ModifiedCollection, Is.SameAs(fakeCollection));
            Assert.That(((CollectionEndPointInsertCommand)command).EndPointProvider, Is.SameAs(_endPointProviderStub));
        }
Пример #20
0
        public void CheckRequiredItemTypeForExisting()
        {
            Order order = DomainObjectIDs.Order1.GetObject <Order>();
            DomainObjectCollection orderItems = order.OrderItems;

            orderItems.Add(Customer.NewObject());
        }
Пример #21
0
        public void GetOriginalRelatedObjectsWithLazyLoad()
        {
            Employee supervisor = DomainObjectIDs.Employee1.GetObject <Employee> ();
            DomainObjectCollection subordinates = supervisor.GetOriginalRelatedObjects("Remotion.Data.DomainObjects.UnitTests.TestDomain.Employee.Subordinates");

            Assert.That(subordinates.Count, Is.EqualTo(2));
        }
        public static void CheckReadOnlyCollectionStrategy(DomainObjectCollection collection)
        {
            // collection => read-only decorator => actual data store

            var readOnlyDecorator = GetDataStrategyAndCheckType <ReadOnlyCollectionDataDecorator> (collection);

            GetWrappedDataAndCheckType <DomainObjectCollectionData> (readOnlyDecorator);
        }
Пример #23
0
        public void SetValue_WithObjectList_DifferentRequiredItemType()
        {
            var customer1 = Customer.NewObject();

            var newCollection = new DomainObjectCollection(typeof(Customer));

            CreateAccessor(customer1, "Orders").SetValueWithoutTypeCheck(newCollection);
        }
Пример #24
0
        private DomainObjectCollection RegisterAssociatedOriginalCollection()
        {
            var oldCollection = new DomainObjectCollection(_associatedDataStrategyStub);

            StubEmptyDataStrategy(_associatedDataStrategyStub);
            RegisterOriginalCollection(oldCollection);
            return(oldCollection);
        }
Пример #25
0
        public void Initialization_WithItemType()
        {
            var collection = new DomainObjectCollection(typeof(Order));

            Assert.That(collection.IsReadOnly, Is.False);
            Assert.That(collection.AssociatedEndPointID, Is.Null);
            DomainObjectCollectionDataTestHelper.CheckStandAloneCollectionStrategy(collection, typeof(Order));
        }
Пример #26
0
        public IDataManagementCommand CreateSetCollectionCommand(DomainObjectCollection newCollection)
        {
            ArgumentUtility.CheckNotNull("newCollection", newCollection);

            var command = _loadState.CreateSetCollectionCommand(this, newCollection, _collectionManager);

            return(command);
        }
Пример #27
0
        public void UnionWith_ChecksItems()
        {
            var secondCollection = new DomainObjectCollection();

            secondCollection.Add(DomainObjectIDs.Order1.GetObject <Order>());

            _collection.UnionWith(secondCollection);
        }
Пример #28
0
        public void Initialization_Default()
        {
            var collection = new DomainObjectCollection();

            Assert.That(collection.IsReadOnly, Is.False);
            Assert.That(collection.AssociatedEndPointID, Is.Null);
            DomainObjectCollectionDataTestHelper.CheckStandAloneCollectionStrategy(collection, null);
        }
Пример #29
0
        public void AddRange()
        {
            var collection = new DomainObjectCollection();

            collection.AddRange(new[] { _customer1, _customer2 });

            Assert.That(collection, Is.EqualTo(new[] { _customer1, _customer2 }));
        }
        public void RegisterCollection()
        {
            _dataStrategyStub.Stub(stub => stub.AssociatedEndPointID).Return(_endPointID);
            var collection = new DomainObjectCollection(_dataStrategyStub);

            _provider.RegisterCollection(_endPointID, collection);

            Assert.That(_provider.GetCollection(_endPointID), Is.SameAs(collection));
        }