Exemplo n.º 1
0
        public void Initialize()
        {
            var endPoint = new CollectionEndPoint(
                TestableClientTransaction,
                _customerEndPointID,
                _collectionManagerMock,
                _lazyLoaderMock,
                _endPointProviderStub,
                _transactionEventSinkStub,
                _dataManagerFactoryStub);

            Assert.That(endPoint.ID, Is.EqualTo(_customerEndPointID));
            Assert.That(endPoint.CollectionManager, Is.SameAs(_collectionManagerMock));
            Assert.That(endPoint.LazyLoader, Is.SameAs(_lazyLoaderMock));
            Assert.That(endPoint.EndPointProvider, Is.SameAs(_endPointProviderStub));
            Assert.That(endPoint.TransactionEventSink, Is.SameAs(_transactionEventSinkStub));
            Assert.That(endPoint.DataManagerFactory, Is.SameAs(_dataManagerFactoryStub));

            var loadState = CollectionEndPointTestHelper.GetLoadState(endPoint);

            Assert.That(loadState, Is.TypeOf(typeof(IncompleteCollectionEndPointLoadState)));
            Assert.That(((IncompleteCollectionEndPointLoadState)loadState).DataManagerFactory, Is.SameAs(_dataManagerFactoryStub));
            Assert.That(
                ((IncompleteCollectionEndPointLoadState)loadState).EndPointLoader,
                Is.TypeOf <CollectionEndPoint.EndPointLoader>().With.Property <CollectionEndPoint.EndPointLoader> (l => l.LazyLoader).SameAs(_lazyLoaderMock));
        }
        public static CollectionEndPoint CreateCollectionEndPoint(
            RelationEndPointID endPointID,
            IEnumerable <DomainObject> initialContents,
            ClientTransaction clientTransaction = null)
        {
            clientTransaction = clientTransaction ?? ClientTransactionScope.CurrentTransaction;
            var dataManager             = ClientTransactionTestHelper.GetDataManager(clientTransaction);
            var changeDetectionStrategy = new RootCollectionEndPointChangeDetectionStrategy();
            var dataStrategyFactory     = new AssociatedCollectionDataStrategyFactory(dataManager);
            var collectionEndPoint      = new CollectionEndPoint(
                clientTransaction,
                endPointID,
                new CollectionEndPointCollectionManager(endPointID, new CollectionEndPointCollectionProvider(dataStrategyFactory), dataStrategyFactory),
                dataManager,
                dataManager,
                ClientTransactionTestHelper.GetEventBroker(clientTransaction),
                new CollectionEndPointDataManagerFactory(changeDetectionStrategy));

            if (initialContents != null)
            {
                CollectionEndPointTestHelper.FillCollectionEndPointWithInitialContents(collectionEndPoint, initialContents);
            }

            return(collectionEndPoint);
        }
Exemplo n.º 3
0
        public void MarkDataComplete()
        {
            Action <ICollectionEndPointDataManager> stateSetter = null;

            var items = new DomainObject[0];

            _loadStateMock
            .Expect(mock => mock.MarkDataComplete(Arg.Is(_endPoint), Arg.Is(items), Arg <Action <ICollectionEndPointDataManager> > .Is.Anything))
            .WhenCalled(mi => { stateSetter = (Action <ICollectionEndPointDataManager>)mi.Arguments[2]; });
            _loadStateMock.Replay();

            _endPoint.MarkDataComplete(items);

            _loadStateMock.VerifyAllExpectations();

            Assert.That(CollectionEndPointTestHelper.GetLoadState(_endPoint), Is.SameAs(_loadStateMock));

            var dataManagerStub = MockRepository.GenerateStub <ICollectionEndPointDataManager>();

            stateSetter(dataManagerStub);

            var newLoadState = CollectionEndPointTestHelper.GetLoadState(_endPoint);

            Assert.That(newLoadState, Is.TypeOf(typeof(CompleteCollectionEndPointLoadState)));

            Assert.That(((CompleteCollectionEndPointLoadState)newLoadState).DataManager, Is.SameAs(dataManagerStub));
            Assert.That(((CompleteCollectionEndPointLoadState)newLoadState).TransactionEventSink, Is.SameAs(_transactionEventSinkStub));
            Assert.That(((CompleteCollectionEndPointLoadState)newLoadState).EndPointProvider, Is.SameAs(_endPointProviderStub));
        }
Exemplo n.º 4
0
        public void SetDataFromSubTransaction()
        {
            var source = RelationEndPointObjectMother.CreateCollectionEndPoint(_customerEndPointID, new[] { _order3 });

            _loadStateMock.Stub(stub => stub.HasChanged()).Return(false);
            _loadStateMock.Expect(mock => mock.SetDataFromSubTransaction(_endPoint, CollectionEndPointTestHelper.GetLoadState(source)));
            _loadStateMock.Replay();

            _collectionManagerMock.Stub(stub => stub.HasCollectionReferenceChanged()).Return(false);

            _endPoint.SetDataFromSubTransaction(source);

            _loadStateMock.VerifyAllExpectations();
        }
Exemplo n.º 5
0
        public void EndPointLoader_LoadEndPointAndGetNewState()
        {
            var endPointLoader = new CollectionEndPoint.EndPointLoader(_lazyLoaderMock);
            var loadStateFake  = MockRepository.GenerateStub <ICollectionEndPointLoadState> ();

            _lazyLoaderMock
            .Expect(mock => mock.LoadLazyCollectionEndPoint(_customerEndPointID))
            .WhenCalled(mi => CollectionEndPointTestHelper.SetLoadState(_endPoint, loadStateFake));

            _lazyLoaderMock.Replay();

            var result = endPointLoader.LoadEndPointAndGetNewState(_endPoint);

            _lazyLoaderMock.VerifyAllExpectations();
            Assert.That(result, Is.SameAs(loadStateFake));
        }
Exemplo n.º 6
0
        public void SetDataFromSubTransaction_DoesNotTouchEndPoint_WhenSourceUntouched_AndTargetUnchanged()
        {
            var source = RelationEndPointObjectMother.CreateCollectionEndPoint(_customerEndPointID, new[] { _order3 });

            _loadStateMock.Stub(stub => stub.HasChanged()).Return(false);
            _loadStateMock.Stub(stub => stub.SetDataFromSubTransaction(_endPoint, CollectionEndPointTestHelper.GetLoadState(source)));
            _loadStateMock.Replay();

            _collectionManagerMock.Stub(stub => stub.HasCollectionReferenceChanged()).Return(false);

            Assert.That(_endPoint.HasBeenTouched, Is.False);

            _endPoint.SetDataFromSubTransaction(source);

            Assert.That(_endPoint.HasBeenTouched, Is.False);
        }
Exemplo n.º 7
0
        public void MarkDataIncomplete()
        {
            Action stateSetter = null;

            _loadStateMock
            .Expect(mock => mock.MarkDataIncomplete(Arg.Is(_endPoint), Arg <Action> .Is.Anything))
            .WhenCalled(mi => { stateSetter = (Action)mi.Arguments[1]; });
            _loadStateMock.Replay();

            _endPoint.MarkDataIncomplete();

            _loadStateMock.VerifyAllExpectations();

            Assert.That(CollectionEndPointTestHelper.GetLoadState(_endPoint), Is.SameAs(_loadStateMock));

            stateSetter();

            var newLoadState = CollectionEndPointTestHelper.GetLoadState(_endPoint);

            Assert.That(newLoadState, Is.TypeOf(typeof(IncompleteCollectionEndPointLoadState)));
            Assert.That(
                ((IncompleteCollectionEndPointLoadState)newLoadState).EndPointLoader,
                Is.TypeOf <CollectionEndPoint.EndPointLoader> ().With.Property <CollectionEndPoint.EndPointLoader> (l => l.LazyLoader).SameAs(_lazyLoaderMock));
        }