public void TryUnloadVirtualEndPointAndItemData_Failure_InHigherTransaction()
        {
            var customer             = DomainObjectIDs.Customer1.GetObject <Customer> ();
            var parentOrdersEndPoint = DomainObjectCollectionDataTestHelper.GetAssociatedEndPoint(customer.Orders);

            EnsureEndPointLoadedAndComplete(parentOrdersEndPoint.ID);

            customer.Orders[0].RegisterForCommit();

            Assert.That(parentOrdersEndPoint.Collection[0].State, Is.EqualTo(StateType.Changed));

            var subTransaction    = TestableClientTransaction.CreateSubTransaction();
            var subOrdersEndPoint = (ICollectionEndPoint)ClientTransactionTestHelper.GetDataManager(subTransaction).GetRelationEndPointWithLazyLoad(
                parentOrdersEndPoint.ID);

            EnsureEndPointLoadedAndComplete(ClientTransactionTestHelper.GetDataManager(subTransaction), subOrdersEndPoint.ID);

            Assert.That(subOrdersEndPoint.Collection[0].TransactionContext[subTransaction].State, Is.EqualTo(StateType.Unchanged));

            var result = UnloadService.TryUnloadVirtualEndPointAndItemData(subTransaction, parentOrdersEndPoint.ID);

            Assert.That(result, Is.False);
            Assert.That(subOrdersEndPoint.IsDataComplete, Is.True);
            Assert.That(parentOrdersEndPoint.IsDataComplete, Is.True);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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));
        }
Ejemplo n.º 4
0
        public void Clone_ReadOnly_DataStrategy()
        {
            OrderCollection associatedCollection = CreateAssociatedCollectionWithEndPointStub();
            var             clonedCollection     = associatedCollection.Clone(true);

            // clone is always stand-alone, even when source is associated with end point
            DomainObjectCollectionDataTestHelper.CheckReadOnlyCollectionStrategy(clonedCollection);
        }
Ejemplo n.º 5
0
        public void Clone_BecomesStandAlone()
        {
            OrderCollection associatedCollection = CreateAssociatedCollectionWithEndPointStub();
            var             clonedCollection     = (DomainObjectCollection)associatedCollection.Clone();

            // clone is always stand-alone, even when source is associated with end point
            DomainObjectCollectionDataTestHelper.CheckStandAloneCollectionStrategy(clonedCollection, associatedCollection.RequiredItemType);
        }
Ejemplo n.º 6
0
        public void CreateCollection_ForStandaloneCollection()
        {
            DomainObjectCollection collection = _factory.CreateCollection(typeof(ObjectList <Order>), new[] { _orderA, _orderB }, typeof(Order));

            Assert.That(collection, Is.Not.Null);
            Assert.That(collection.RequiredItemType, Is.EqualTo(typeof(Order)));

            DomainObjectCollectionDataTestHelper.CheckStandAloneCollectionStrategy(collection, typeof(Order));
        }
Ejemplo n.º 7
0
        public void PerformCollectionRemoveWithOtherClientTransaction()
        {
            var order1     = DomainObjectIDs.Order1.GetObject <Order> ();
            var orderItem1 = DomainObjectMother.GetObjectInOtherTransaction <OrderItem> (DomainObjectIDs.OrderItem1);

            var endPoint = DomainObjectCollectionDataTestHelper.GetAssociatedEndPoint(order1.OrderItems);

            endPoint.Collection.Remove(orderItem1);
        }
Ejemplo n.º 8
0
        private void CheckOriginalDataMatches(IDomainObjectCollectionData expected, IDomainObjectCollectionData actual)
        {
            var expectedInner = DomainObjectCollectionDataTestHelper.GetWrappedDataAndCheckType <CopyOnWriteDomainObjectCollectionData> (
                (ReadOnlyCollectionDataDecorator)expected);
            var actualInner = DomainObjectCollectionDataTestHelper.GetWrappedDataAndCheckType <CopyOnWriteDomainObjectCollectionData> (
                (ReadOnlyCollectionDataDecorator)actual);

            Assert.That(actualInner, Is.SameAs(expectedInner));
        }
Ejemplo n.º 9
0
        public void Clone()
        {
            var clonedCollection = _collection.Clone();

            Assert.That(clonedCollection, Is.EqualTo(new[] { _customer1, _customer2 }));
            Assert.That(clonedCollection.IsReadOnly, Is.False);
            Assert.That(clonedCollection.RequiredItemType, Is.EqualTo(_collection.RequiredItemType));

            DomainObjectCollectionDataTestHelper.CheckStandAloneCollectionStrategy(clonedCollection, typeof(Customer));
        }
        public void CopyOnWrite_Twice()
        {
            _copyOnWriteData.CopyOnWrite();
            var data1 = DomainObjectCollectionDataTestHelper.GetWrappedData(_copyOnWriteData);

            _copyOnWriteData.CopyOnWrite();
            var data2 = DomainObjectCollectionDataTestHelper.GetWrappedData(_copyOnWriteData);

            Assert.That(data1, Is.SameAs(data2));
        }
Ejemplo n.º 11
0
        private void CheckOriginalDataNotCopied(ChangeCachingCollectionDataDecorator decorator)
        {
            var originalData = DomainObjectCollectionDataTestHelper.GetWrappedDataAndCheckType <CopyOnWriteDomainObjectCollectionData> (
                decorator.OriginalData);

            var originalDataStore   = DomainObjectCollectionDataTestHelper.GetWrappedData(originalData);
            var observedWrappedData = PrivateInvoke.GetNonPublicField(decorator, "_observedWrappedData");

            Assert.That(originalDataStore, Is.SameAs(observedWrappedData));
        }
        public void UnloadVirtualEndPoint_Collection_AlreadyUnloaded()
        {
            var customer = DomainObjectIDs.Customer1.GetObject <Customer> ();
            var endPoint = DomainObjectCollectionDataTestHelper.GetAssociatedEndPoint(customer.Orders);

            UnloadService.UnloadVirtualEndPoint(TestableClientTransaction, endPoint.ID);
            ClientTransactionTestHelperWithMocks.EnsureTransactionThrowsOnEvents(TestableClientTransaction);
            Assert.That(endPoint.IsDataComplete, Is.False);

            UnloadService.UnloadVirtualEndPoint(TestableClientTransaction, endPoint.ID);
        }
        public void CollectionEndPoint_DelegatingDataMembers()
        {
            _endPoint.Collection.Add(DomainObjectIDs.OrderItem5.GetObject <OrderItem>());

            var deserializedEndPoint = FlattenedSerializer.SerializeAndDeserialize(_endPoint);

            DomainObjectCollectionDataTestHelper.CheckAssociatedCollectionStrategy(
                deserializedEndPoint.Collection,
                _endPoint.Collection.RequiredItemType,
                deserializedEndPoint.ID);
        }
Ejemplo n.º 14
0
        public void Initialization_WithEnumerable()
        {
            var collection = new DomainObjectCollection(new[] { _customer1, _customer2 }, typeof(Customer));

            Assert.That(collection, Is.EqualTo(new[] { _customer1, _customer2 }));
            Assert.That(collection.RequiredItemType, Is.SameAs(typeof(Customer)));
            Assert.That(collection.IsReadOnly, Is.False);
            Assert.That(collection.AssociatedEndPointID, Is.Null);

            DomainObjectCollectionDataTestHelper.CheckStandAloneCollectionStrategy(collection, typeof(Customer));
        }
        public void Commit_ReadOnly()
        {
            _customerEndPoint.Collection.Add(_order3);
            DomainObjectCollectionDataTestHelper.MakeCollectionReadOnly(_customerEndPoint.Collection);

            _customerEndPoint.Commit();

            Assert.That(_customerEndPoint.Collection, Is.EqualTo(new[] { _order1, _order2, _order3 }));
            Assert.That(_customerEndPoint.GetCollectionWithOriginalData(), Is.EqualTo(new[] { _order1, _order2, _order3 }));
            Assert.That(_customerEndPoint.OriginalCollection, Is.SameAs(_customerEndPoint.Collection));
            Assert.That(_customerEndPoint.Collection.IsReadOnly, Is.True);
        }
Ejemplo n.º 16
0
        public void DomainObjectCollection_StandAlone_Data()
        {
            var collection = new DomainObjectCollection(typeof(Order));

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

            DomainObjectCollection deserializedCollection = SerializeAndDeserialize(collection);

            DomainObjectCollectionDataTestHelper.CheckStandAloneCollectionStrategy(deserializedCollection, typeof(Order));
            Assert.That(deserializedCollection.Count, Is.EqualTo(1));
            Assert.That(deserializedCollection[0].ID, Is.EqualTo(DomainObjectIDs.Order1));
        }
Ejemplo n.º 17
0
        public void Initialization_WithData()
        {
            var givenData  = new DomainObjectCollectionData();
            var collection = new DomainObjectCollection(givenData);

            Assert.That(collection.IsReadOnly, Is.False);
            Assert.That(collection.AssociatedEndPointID, Is.Null);

            var actualData = DomainObjectCollectionDataTestHelper.GetDataStrategy(collection);

            Assert.That(actualData, Is.SameAs(givenData));
        }
        public void RollbackReadOnlyOppositeDomainObjects()
        {
            Customer customer = DomainObjectIDs.Customer1.GetObject <Customer> ();

            customer.Orders.Add(DomainObjectIDs.Order3.GetObject <Order> ());

            DomainObjectCollectionDataTestHelper.MakeCollectionReadOnly(customer.Orders);
            TestableClientTransaction.Rollback();

            Assert.That(customer.GetOriginalRelatedObjects("Remotion.Data.DomainObjects.UnitTests.TestDomain.Customer.Orders").IsReadOnly, Is.True);
            Assert.That(customer.Orders.IsReadOnly, Is.True);
        }
Ejemplo n.º 19
0
        public void TransformToStandAlone()
        {
            var endPoint   = RelationEndPointObjectMother.CreateCollectionEndPoint_Customer1_Orders();
            var collection = endPoint.Collection;
            var originalCollectionDataStrategy = DomainObjectCollectionDataTestHelper.GetDataStrategy(collection);
            var originalCollectionContents     = collection.Cast <DomainObject> ().ToArray();

            var result = ((IAssociatableDomainObjectCollection)collection).TransformToStandAlone();

            DomainObjectCollectionDataTestHelper.CheckStandAloneCollectionStrategy(collection, typeof(Order));
            Assert.That(collection, Is.EqualTo(originalCollectionContents));
            Assert.That(result, Is.SameAs(originalCollectionDataStrategy));
        }
        public void GetData()
        {
            var collectionDataStub = MockRepository.GenerateStub <IDomainObjectCollectionData> ();

            _dataManagerMock.Stub(stub => stub.CollectionData).Return(collectionDataStub);

            var result = _loadState.GetData(_collectionEndPointMock);

            Assert.That(result, Is.TypeOf(typeof(ReadOnlyCollectionDataDecorator)));
            var wrappedData = DomainObjectCollectionDataTestHelper.GetWrappedData(result);

            Assert.That(wrappedData, Is.SameAs(collectionDataStub));
        }
        public void UnloadVirtualEndPointAndItemData_Collection_EmptyCollection_UnloadsEndPoint()
        {
            var customer       = DomainObjectIDs.Customer2.GetObject <Customer> ();
            var ordersEndPoint = DomainObjectCollectionDataTestHelper.GetAssociatedEndPoint(customer.Orders);

            EnsureEndPointLoadedAndComplete(ordersEndPoint.ID);

            Assert.That(ordersEndPoint.Collection, Is.Empty);

            UnloadService.UnloadVirtualEndPointAndItemData(TestableClientTransaction, ordersEndPoint.ID);

            Assert.That(ordersEndPoint.IsDataComplete, Is.False);
            Assert.That(customer.State, Is.EqualTo(StateType.Unchanged));
        }
Ejemplo n.º 22
0
        public void RegisterOriginalItem_ItemAlreadyExists_InOriginal()
        {
            var underlyingOriginalData = DomainObjectCollectionDataTestHelper.GetWrappedDataAndCheckType <CopyOnWriteDomainObjectCollectionData> (
                _decoratorWithRealData.OriginalData);

            var domainObject = DomainObjectMother.CreateFakeObject <Order> ();

            underlyingOriginalData.Add(domainObject);

            Assert.That(_decoratorWithRealData.GetObject(domainObject.ID), Is.Null);
            Assert.That(_decoratorWithRealData.OriginalData.GetObject(domainObject.ID), Is.Not.Null);

            _decoratorWithRealData.RegisterOriginalItem(domainObject);
        }
Ejemplo n.º 23
0
        public void DomainObjectCollection_StandAlone_Contents()
        {
            var collection = new DomainObjectCollection(typeof(Order));

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

            DomainObjectCollection deserializedCollection = SerializeAndDeserialize(collection);

            Assert.That(deserializedCollection.Count, Is.EqualTo(1));
            Assert.That(deserializedCollection.Contains(DomainObjectIDs.Order1), Is.True);
            Assert.That(deserializedCollection[0].ID, Is.EqualTo(DomainObjectIDs.Order1));
            Assert.That(deserializedCollection.RequiredItemType, Is.EqualTo(typeof(Order)));
            Assert.That(deserializedCollection.IsReadOnly, Is.False);
            Assert.That(DomainObjectCollectionDataTestHelper.GetAssociatedEndPoint(deserializedCollection), Is.Null);
        }
        public void TryUnloadVirtualEndPointAndItemData_Success_IfDataNotComplete()
        {
            var customer       = DomainObjectIDs.Customer1.GetObject <Customer> ();
            var ordersEndPoint = DomainObjectCollectionDataTestHelper.GetAssociatedEndPoint(customer.Orders);

            UnloadService.UnloadVirtualEndPoint(TestableClientTransaction, ordersEndPoint.ID);
            Assert.That(ordersEndPoint.IsDataComplete, Is.False);

            ClientTransactionTestHelperWithMocks.EnsureTransactionThrowsOnEvents(TestableClientTransaction);

            var result = UnloadService.TryUnloadVirtualEndPointAndItemData(TestableClientTransaction, ordersEndPoint.ID);

            Assert.That(result, Is.True);
            Assert.That(ordersEndPoint.IsDataComplete, Is.False);
        }
        public void SetCollection_DataStrategy_OfNewOpposites()
        {
            var newOpposites = new OrderCollection {
                _order2
            };

            SetCollectionAndNotify(_customerEndPoint, newOpposites);

            // New collection now has a delegating data store...
            DomainObjectCollectionDataTestHelper.CheckAssociatedCollectionStrategy(newOpposites, typeof(Order), _customerEndPoint.ID);

            // ... and the end-point now has data newOpposites had before!
            Assert.That(_customerEndPoint.GetData(), Is.EqualTo(new[] { _order2 }));
            Assert.That(newOpposites, Is.EqualTo(new[] { _order2 }));
        }
        public void CreateDataStrategyForEndPoint()
        {
            var ordersEndPointID = RelationEndPointID.Create(DomainObjectIDs.Customer1, typeof(Customer), "Orders");

            var result = _factory.CreateDataStrategyForEndPoint(ordersEndPointID);

            Assert.That(result, Is.TypeOf <ModificationCheckingCollectionDataDecorator> ());
            var checkingDecorator = (ModificationCheckingCollectionDataDecorator)result;

            Assert.That(checkingDecorator.RequiredItemType, Is.SameAs(typeof(Order)));

            var delegator = DomainObjectCollectionDataTestHelper.GetWrappedDataAndCheckType <EndPointDelegatingCollectionData> (checkingDecorator);

            Assert.That(delegator.AssociatedEndPointID, Is.EqualTo(ordersEndPointID));
            Assert.That(delegator.VirtualEndPointProvider, Is.SameAs(_virtualEndPointProviderStub));
        }
        public void SetCollection_SourceCollection_IsReadOnly()
        {
            DomainObjectCollectionDataTestHelper.MakeCollectionReadOnly(_customerEndPoint.Collection);

            var newOpposites = new OrderCollection {
                _order2, _order3
            };
            var oldOpposites = _customerEndPoint.Collection;

            Assert.That(oldOpposites.IsReadOnly, Is.True);

            SetCollectionAndNotify(_customerEndPoint, newOpposites);

            Assert.That(_customerEndPoint.Collection, Is.SameAs(newOpposites));
            Assert.That(_customerEndPoint.OriginalCollection, Is.SameAs(oldOpposites));
        }
Ejemplo n.º 28
0
        public void TransformToAssociated()
        {
            var endPointID = RelationEndPointID.Create(DomainObjectIDs.Customer1, typeof(Customer), "Orders");
            var originalCollectionDataStrategy = DomainObjectCollectionDataTestHelper.GetDataStrategy(_collection);
            var originalCollectionContents     = _collection.Cast <DomainObject> ().ToArray();
            var originalEndPointContents       =
                ((ICollectionEndPoint)TestableClientTransaction.DataManager.GetRelationEndPointWithLazyLoad(endPointID)).GetData().ToArray();
            var associatedCollectionDataStrategyFactory = new AssociatedCollectionDataStrategyFactory(TestableClientTransaction.DataManager);

            var result = ((IAssociatableDomainObjectCollection)_collection).TransformToAssociated(endPointID, associatedCollectionDataStrategyFactory);

            DomainObjectCollectionDataTestHelper.CheckAssociatedCollectionStrategy(_collection, typeof(Order), endPointID);
            Assert.That(result, Is.SameAs(originalCollectionDataStrategy));
            Assert.That(result, Is.EqualTo(originalCollectionContents));
            Assert.That(_collection, Is.EqualTo(originalEndPointContents));
        }
        public void GetCollection()
        {
            _associatedCollectionDataStrategyFactoryMock
            .Expect(mock => mock.CreateDataStrategyForEndPoint(_endPointID))
            .Return(_dataStrategyStub);
            _associatedCollectionDataStrategyFactoryMock.Replay();

            _dataStrategyStub.Stub(stub => stub.AssociatedEndPointID).Return(_endPointID);

            var result = _provider.GetCollection(_endPointID);

            _associatedCollectionDataStrategyFactoryMock.VerifyAllExpectations();
            Assert.That(result, Is.TypeOf <OrderCollection> ());
            Assert.That(DomainObjectCollectionDataTestHelper.GetDataStrategy(result), Is.SameAs(_dataStrategyStub));

            Assert.That(result, Is.SameAs(_provider.GetCollection(_endPointID)));
        }
        public void UnloadVirtualEndPointAndItemData_Collection_UnloadsEndPointAndItems()
        {
            var order = DomainObjectIDs.Order1.GetObject <Order> ();
            var orderItemsEndPoint = DomainObjectCollectionDataTestHelper.GetAssociatedEndPoint(order.OrderItems);

            EnsureEndPointLoadedAndComplete(orderItemsEndPoint.ID);

            var orderItem1 = orderItemsEndPoint.Collection[0];
            var orderItem2 = orderItemsEndPoint.Collection[1];

            UnloadService.UnloadVirtualEndPointAndItemData(TestableClientTransaction, orderItemsEndPoint.ID);

            Assert.That(orderItemsEndPoint.IsDataComplete, Is.False);
            Assert.That(orderItem1.State, Is.EqualTo(StateType.NotLoadedYet));
            Assert.That(orderItem2.State, Is.EqualTo(StateType.NotLoadedYet));
            Assert.That(order.State, Is.EqualTo(StateType.Unchanged));
        }