public void Initialization()
        {
            var endPoint = new VirtualObjectEndPoint(
                ClientTransaction.Current,
                _endPointID,
                _lazyLoaderMock,
                _endPointProviderStub,
                _transactionEventSinkStub,
                _dataManagerFactory);

            Assert.That(endPoint.ID, Is.EqualTo(_endPointID));
            Assert.That(endPoint.ClientTransaction, Is.SameAs(TestableClientTransaction));
            Assert.That(endPoint.LazyLoader, Is.SameAs(_lazyLoaderMock));
            Assert.That(endPoint.EndPointProvider, Is.SameAs(_endPointProviderStub));
            Assert.That(endPoint.DataManagerFactory, Is.SameAs(_dataManagerFactory));
            Assert.That(endPoint.HasBeenTouched, Is.False);
            Assert.That(endPoint.IsDataComplete, Is.False);

            var loadState = VirtualObjectEndPointTestHelper.GetLoadState(endPoint);

            Assert.That(loadState, Is.TypeOf(typeof(IncompleteVirtualObjectEndPointLoadState)));
            Assert.That(((IncompleteVirtualObjectEndPointLoadState)loadState).DataManagerFactory, Is.SameAs(_dataManagerFactory));
            Assert.That(
                ((IncompleteVirtualObjectEndPointLoadState)loadState).EndPointLoader,
                Is.TypeOf <VirtualObjectEndPoint.EndPointLoader> ().With.Property <VirtualObjectEndPoint.EndPointLoader> (l => l.LazyLoader).SameAs(_lazyLoaderMock));
        }
        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(VirtualObjectEndPointTestHelper.GetLoadState(_endPoint), Is.SameAs(_loadStateMock));

            stateSetter();

            var newLoadState = VirtualObjectEndPointTestHelper.GetLoadState(_endPoint);

            Assert.That(newLoadState, Is.Not.SameAs(_loadStateMock));
            Assert.That(newLoadState, Is.TypeOf(typeof(IncompleteVirtualObjectEndPointLoadState)));

            Assert.That(((IncompleteVirtualObjectEndPointLoadState)newLoadState).DataManagerFactory, Is.SameAs(_dataManagerFactory));
            Assert.That(
                ((IncompleteVirtualObjectEndPointLoadState)newLoadState).EndPointLoader,
                Is.TypeOf <VirtualObjectEndPoint.EndPointLoader> ()
                .With.Property <VirtualObjectEndPoint.EndPointLoader> (l => l.LazyLoader).SameAs(_lazyLoaderMock));
        }
        public void MarkDataComplete()
        {
            Action <IVirtualObjectEndPointDataManager> stateSetter = null;

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

            _endPoint.MarkDataComplete(_oppositeObject);

            _loadStateMock.VerifyAllExpectations();

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

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

            stateSetter(dataManagerStub);

            var newLoadState = VirtualObjectEndPointTestHelper.GetLoadState(_endPoint);

            Assert.That(newLoadState, Is.Not.SameAs(_loadStateMock));
            Assert.That(newLoadState, Is.TypeOf(typeof(CompleteVirtualObjectEndPointLoadState)));

            Assert.That(((CompleteVirtualObjectEndPointLoadState)newLoadState).DataManager, Is.SameAs(dataManagerStub));
            Assert.That(((CompleteVirtualObjectEndPointLoadState)newLoadState).TransactionEventSink, Is.SameAs(_transactionEventSinkStub));
            Assert.That(((CompleteVirtualObjectEndPointLoadState)newLoadState).EndPointProvider, Is.SameAs(_endPointProviderStub));
        }
        public void SetOppositeObjectDataFromSubTransaction()
        {
            var source = RelationEndPointObjectMother.CreateVirtualObjectEndPoint(_endPointID, TestableClientTransaction);

            _loadStateMock.Expect(mock => mock.SetDataFromSubTransaction(_endPoint, VirtualObjectEndPointTestHelper.GetLoadState(source)));
            _loadStateMock.Stub(mock => mock.HasChanged()).Return(true);
            _loadStateMock.Replay();

            PrivateInvoke.InvokeNonPublicMethod(_endPoint, "SetOppositeObjectDataFromSubTransaction", source);

            _loadStateMock.VerifyAllExpectations();
        }
        public void EndPointLoader_LoadEndPointAndGetNewState()
        {
            var endPointLoader = new VirtualObjectEndPoint.EndPointLoader(_lazyLoaderMock);
            var loadStateFake  = MockRepository.GenerateStub <IVirtualObjectEndPointLoadState>();

            _lazyLoaderMock
            .Expect(mock => mock.LoadLazyVirtualObjectEndPoint(_endPointID))
            .WhenCalled(mi => VirtualObjectEndPointTestHelper.SetLoadState(_endPoint, loadStateFake));

            _lazyLoaderMock.Replay();

            var result = endPointLoader.LoadEndPointAndGetNewState(_endPoint);

            _lazyLoaderMock.VerifyAllExpectations();
            Assert.That(result, Is.SameAs(loadStateFake));
        }