public void CreateSubTransaction()
        {
            var  counter = new OrderedExpectationCounter();
            bool subTransactionCreatingCalled = false;

            _thisEventSinkWithStrictMock.Expect(mock => mock.RaiseSubTransactionCreatingEvent())
            .WhenCalledOrdered(counter, mi =>
            {
                Assert.That(_manager.IsWriteable, Is.True);
                subTransactionCreatingCalled = true;
            });

            ClientTransaction fakeSubTransaction = ClientTransactionObjectMother.CreateWithParent(_thisTransaction);
            Func <ClientTransaction, ClientTransaction> factory = tx =>
            {
                Assert.That(tx, Is.SameAs(_thisTransaction));
                Assert.That(subTransactionCreatingCalled, Is.True);
                Assert.That(_manager.IsWriteable, Is.False, "IsWriteable needs to be set before the factory is called.");
                ClientTransactionTestHelper.SetIsWriteable(_thisTransaction, false); // required by assertion in ReadOnlyClientTransactionListener
                return(fakeSubTransaction);
            };

            _hierarchyStrictMock.Expect(mock => mock.AppendLeafTransaction(fakeSubTransaction)).Ordered(counter);
            _thisEventSinkWithStrictMock.Expect(mock => mock.RaiseSubTransactionCreatedEvent(fakeSubTransaction)).Ordered(counter);

            var result = _manager.CreateSubTransaction(factory);

            Assert.That(result, Is.Not.Null.And.SameAs(fakeSubTransaction));
            Assert.That(_manager.SubTransaction, Is.SameAs(fakeSubTransaction));
            Assert.That(_manager.IsWriteable, Is.False);

            _hierarchyStrictMock.VerifyAllExpectations();
        }
Ejemplo n.º 2
0
 private IMethodOptions <RhinoMocksExtensions.VoidType> ExpectTransactionCommitting(params DomainObject[] domainObjects)
 {
     return(_eventSinkWithMock.Expect(mock => mock.RaiseTransactionCommittingEvent(
                                          Arg <ReadOnlyCollection <DomainObject> > .List.Equivalent(domainObjects),
                                          Arg <CommittingEventRegistrar> .Is.TypeOf))
            .WhenCalled(mi => Assert.That(((CommittingEventRegistrar)mi.Arguments[1]).ClientTransaction, Is.SameAs(_clientTransaction))));
 }
        public void Begin()
        {
            _transactionEventSinkWithMock.Expect(mock => mock.RaiseObjectDeletingEvent(_order1));
            _transactionEventSinkWithMock.Replay();

            _deleteOrder1Command.Begin();

            _transactionEventSinkWithMock.VerifyAllExpectations();
        }
        public void Begin()
        {
            _dataContainerMap.Register(_existingDataContainer);
            _dataContainerMap.Register(_newDataContainer);

            // Order of registration
            _transactionEventSinkWithMock.Expect(mock => mock.RaiseObjectsUnloadingEvent(
                                                     Arg <ReadOnlyCollection <DomainObject> > .List.Equal(new[] { _existingDomainObject, _newDomainObject })));
            _transactionEventSinkWithMock.Replay();

            _unloadCommand.Begin();

            _transactionEventSinkWithMock.VerifyAllExpectations();
        }
        public void OnBeforeObjectRegistration()
        {
            var loadedObjectIDs = Array.AsReadOnly(new[] { DomainObjectIDs.Order1, DomainObjectIDs.Order3 });

            using (_mockRepository.Ordered())
            {
                _hierarchyManagerMock.Expect(mock => mock.OnBeforeObjectRegistration(loadedObjectIDs));
                _eventSinkWithMock.Expect(mock => mock.RaiseObjectsLoadingEvent(loadedObjectIDs));
            }
            _mockRepository.ReplayAll();

            _decorator.OnBeforeObjectRegistration(loadedObjectIDs);

            _mockRepository.VerifyAll();
        }
        public void Begin()
        {
            _unloadDataCommandMock.Stub(stub => stub.GetAllExceptions()).Return(new Exception[0]);

            using (_mockRepository.Ordered())
            {
                _transactionEventSinkWithMock.Expect(mock => mock.RaiseObjectsUnloadingEvent(
                                                         Arg <ReadOnlyCollection <DomainObject> > .List.Equal(new[] { _domainObject1, _domainObject2 })));
                _unloadDataCommandMock.Expect(mock => mock.Begin());
            }
            _mockRepository.ReplayAll();

            _unloadCommand.Begin();

            _mockRepository.VerifyAll();
        }
        public void MarkInvalid()
        {
            Assert.That(_manager.IsInvalid(_order1.ID), Is.False);
            Assert.That(_manager.InvalidObjectCount, Is.EqualTo(0));

            _transactionEventSinkWithMock.Expect(mock => mock.RaiseObjectMarkedInvalidEvent(_order1));
            _transactionEventSinkWithMock.Replay();

            var result = _manager.MarkInvalid(_order1);

            _transactionEventSinkWithMock.VerifyAllExpectations();

            Assert.That(result, Is.True);
            Assert.That(_manager.IsInvalid(_order1.ID), Is.True);
            Assert.That(_manager.InvalidObjectCount, Is.EqualTo(1));
        }
        public void Begin()
        {
            _commandPartialMock
            .Expect(mock => mock.Begin())
            .CallOriginalMethod(OriginalCallOptions.CreateExpectation);
            _commandPartialMock.Replay();

            _transactionEventSinkWithMock
            .Expect(mock => mock.RaiseRelationChangingEvent(_domainObject, _endPointDefinition, _oldRelatedObject, _newRelatedObject));
            _transactionEventSinkWithMock.Replay();

            _commandPartialMock.Begin();

            _commandPartialMock.VerifyAllExpectations();
            _transactionEventSinkWithMock.VerifyAllExpectations();
        }
        public void OnBeforeTransactionInitialize()
        {
            _parentEventSinkWithStrictMock.Expect(mock => mock.RaiseSubTransactionInitializeEvent(_thisTransaction));
            ClientTransactionTestHelper.SetIsWriteable(_parentTransaction, false); // required by assertion in ReadOnlyClientTransactionListener

            _manager.OnBeforeTransactionInitialize();

            _parentEventSinkWithStrictMock.VerifyAllExpectations();
        }
Ejemplo n.º 10
0
        public void GetCollection_CallsFilterQueryResult()
        {
            _loadedObjectDataStub1.Stub(stub => stub.GetDomainObjectReference()).Return(_fakeOrder1);
            _objectLoaderMock
            .Stub(
                mock =>
                mock.GetOrLoadCollectionQueryResult(_collectionQuery))
            .Return(new[] { _loadedObjectDataStub1 });
            _objectLoaderMock.Replay();

            var filteredResult = new QueryResult <Order> (_collectionQuery, new[] { _fakeOrder2 });

            _transactionEventSinkWithMock.Expect(mock => mock.RaiseFilterQueryResultEvent(
                                                     Arg <QueryResult <Order> > .Matches(qr => qr.ToArray().SequenceEqual(new[] { _fakeOrder1 }))))
            .Return(filteredResult);
            _transactionEventSinkWithMock.Replay();

            var result = _queryManager.GetCollection <Order> (_collectionQuery);

            _transactionEventSinkWithMock.VerifyAllExpectations();
            Assert.That(result, Is.SameAs(filteredResult));
        }
Ejemplo n.º 11
0
        public void Remove_RaisesNotification_BeforeRemoving()
        {
            var dataContainer = DataContainer.CreateForExisting(DomainObjectIDs.Order1, null, pd => pd.DefaultValue);

            _map.Register(dataContainer);

            Assert.That(_map[dataContainer.ID], Is.Not.Null);

            _eventSinkWithDynamicMock.Expect(mock => mock.RaiseDataContainerMapUnregisteringEvent(dataContainer))
            .WhenCalled(mi => Assert.That(_map[dataContainer.ID], Is.Not.Null));

            _map.Remove(dataContainer.ID);

            _eventSinkWithDynamicMock.VerifyAllExpectations();
        }
Ejemplo n.º 12
0
        public void NewObject()
        {
            var constructorParameters = ParamList.Create("Some Product");

            _eventSinkWithMock.Expect(mock => mock.RaiseNewObjectCreatingEvent(_typeDefinitionWithCreatorMock.ClassType));
            _persistenceStrategyMock.Expect(mock => mock.CreateNewObjectID(_typeDefinitionWithCreatorMock)).Return(_objectID1);

            _domainObjectCreatorMock
            .Expect(
                mock => mock.CreateNewObject(Arg <IObjectInitializationContext> .Is.Anything, Arg.Is(constructorParameters), Arg.Is(_transaction)))
            .WhenCalled(mi => CheckInitializationContext <NewObjectInitializationContext> (mi.Arguments[0], _objectID1, _transaction))
            .Return(_domainObject1);

            var result = _agent.NewObject(_typeDefinitionWithCreatorMock, constructorParameters);

            _eventSinkWithMock.VerifyAllExpectations();
            _persistenceStrategyMock.VerifyAllExpectations();
            _domainObjectCreatorMock.VerifyAllExpectations();

            Assert.That(result, Is.SameAs(_domainObject1));
        }
        public void MarkDataIncomplete_RaisesEvent()
        {
            var endPointID = RelationEndPointObjectMother.CreateRelationEndPointID(DomainObjectIDs.Order1, "OrderItems");

            _virtualEndPointMock
            .Stub(stub => stub.ID)
            .Return(endPointID);
            _virtualEndPointMock.Replay();

            _dataManagerMock.Stub(stub => stub.HasDataChanged()).Return(false);
            _dataManagerMock.Replay();

            _loadState.StubOriginalOppositeEndPoints(new IRealObjectEndPoint[0]);

            _transactionEventSinkWithMock.Expect(mock => mock.RaiseRelationEndPointBecomingIncompleteEvent(endPointID));
            _transactionEventSinkWithMock.Replay();

            _loadState.MarkDataIncomplete(_virtualEndPointMock, () => { });

            _virtualEndPointMock.VerifyAllExpectations();
            _dataManagerMock.VerifyAllExpectations();
            _transactionEventSinkWithMock.VerifyAllExpectations();
        }