コード例 #1
0
        public void FullEventChain_WithReiterationDueToAddedObject_InExtension()
        {
            using (MockRepository.Ordered())
            {
                ExpectCommittingEventsWithCustomOptions(
                    Tuple.Create(ChangedObject, ChangedObjectEventReceiverMock),
                    Tuple.Create(NewObject, NewObjectEventReceiverMock),
                    Tuple.Create(DeletedObject, DeletedObjectEventReceiverMock))
                // This triggers one additional run
                .ExtensionOptions
                .WhenCalled(mi => Transaction.ExecuteInScope(() => UnchangedObject.RegisterForCommit()));

                ExpectCommittingEventsWithCustomOptions(Tuple.Create(UnchangedObject, UnchangedObjectEventReceiverMock))
                // This does not trigger an additional run because the object is no longer new to the commit set
                .ExtensionOptions
                .WhenCalled(mi => Transaction.ExecuteInScope(() => UnchangedObject.RegisterForCommit()));

                ExpectCommitValidateEvents(ChangedObject, NewObject, DeletedObject, UnchangedObject);

                ExpectCommittedEvents(
                    Tuple.Create(ChangedObject, ChangedObjectEventReceiverMock),
                    Tuple.Create(NewObject, NewObjectEventReceiverMock),
                    Tuple.Create(UnchangedObject, UnchangedObjectEventReceiverMock));
            }
            MockRepository.ReplayAll();

            Transaction.Commit();

            MockRepository.VerifyAll();
        }
コード例 #2
0
        public void FullEventChain_WithReiterationDueToAddedObject_InDomainObject()
        {
            using (MockRepository.Ordered())
            {
                ExpectRollingBackEventsWithCustomOptions(
                    Tuple.Create(ChangedObject, ChangedObjectEventReceiverMock),
                    Tuple.Create(NewObject, NewObjectEventReceiverMock),
                    Tuple.Create(DeletedObject, DeletedObjectEventReceiverMock))
                .DomainObjectOptions[1]
                // This triggers one additional run
                .WhenCalled(mi => Transaction.ExecuteInScope(() => UnchangedObject.RegisterForCommit()));

                ExpectRollingBackEventsWithCustomOptions(
                    Tuple.Create(UnchangedObject, UnchangedObjectEventReceiverMock))
                .DomainObjectOptions[0]
                // This does not trigger an additional run because the object is no longer new to the Rollback set
                .WhenCalled(mi => Transaction.ExecuteInScope(() => UnchangedObject.RegisterForCommit()));

                ExpectRolledBackEvents(
                    Tuple.Create(ChangedObject, ChangedObjectEventReceiverMock),
                    Tuple.Create(DeletedObject, DeletedObjectEventReceiverMock),
                    Tuple.Create(UnchangedObject, UnchangedObjectEventReceiverMock));
            }
            MockRepository.ReplayAll();

            Transaction.Rollback();

            MockRepository.VerifyAll();
        }
        public void FullEventChain_WithReiterationDueToAddedObjectAndRegisterForAdditionalCommittingEvents()
        {
            using (MockRepository.Ordered())
            {
                ExpectCommittingEventsWithCustomOptions(
                    Tuple.Create(ChangedObject, ChangedObjectEventReceiverMock),
                    Tuple.Create(NewObject, NewObjectEventReceiverMock),
                    Tuple.Create(DeletedObject, DeletedObjectEventReceiverMock))
                .ExtensionOptions
                // This triggers _one_ (not two) additional run for _unchangedObject
                .WhenCalled(
                    mi => Transaction.ExecuteInScope(
                        () =>
                {
                    Assert.That(
                        () => ((ICommittingEventRegistrar)mi.Arguments[2]).RegisterForAdditionalCommittingEvents(UnchangedObject),
                        Throws.ArgumentException.With.Message.EqualTo(
                            string.Format(
                                "The given DomainObject '{0}' cannot be registered due to its state (Unchanged). "
                                + "Only objects that are part of the commit set can be registered. Use RegisterForCommit to add an unchanged "
                                + "object to the commit set.\r\nParameter name: domainObjects",
                                UnchangedObject.ID)));
                    UnchangedObject.RegisterForCommit();
                    ((ICommittingEventRegistrar)mi.Arguments[2]).RegisterForAdditionalCommittingEvents(UnchangedObject);
                }));

                // No more additional runs
                ExpectCommittingEvents(Tuple.Create(UnchangedObject, UnchangedObjectEventReceiverMock));

                ExpectCommitValidateEvents(ChangedObject, NewObject, DeletedObject, UnchangedObject);

                ExpectCommittedEvents(
                    Tuple.Create(ChangedObject, ChangedObjectEventReceiverMock),
                    Tuple.Create(NewObject, NewObjectEventReceiverMock),
                    Tuple.Create(UnchangedObject, UnchangedObjectEventReceiverMock));
            }
            MockRepository.ReplayAll();

            Transaction.Commit();

            MockRepository.VerifyAll();
        }