public void When_executing_it_it_should_call_the_executor_given_via_ctor()
        {
            var theCommand = new DummyCommand();
            var theExecutor = MockRepository.GenerateMock<ICommandExecutor<DummyCommand>>();
            var theWrapper = new TransactionalCommandExecutorWrapper<DummyCommand>(theExecutor);

            theWrapper.Execute(theCommand);

            theExecutor.AssertWasCalled((e) => e.Execute(theCommand));
        }
        public void Executing_a_command_with_it_should_call_the_executor_that_was_set_at_construct()
        {
            var aExecutor = MockRepository.GenerateMock<ICommandExecutor<ICommand>>();

            var aCommand = MockRepository.GenerateMock<ICommand>();
            var theWrapper = new TransactionalCommandExecutorWrapper<ICommand>(aExecutor);

            theWrapper.Execute(aCommand);

            aExecutor.AssertWasCalled(e=>e.Execute(aCommand));
        }
Exemplo n.º 3
0
        public void Executing_a_command_with_it_should_call_the_executor_that_was_set_at_construct()
        {
            var aExecutor = MockRepository.GenerateMock <ICommandExecutor <ICommand> >();

            var aCommand   = MockRepository.GenerateMock <ICommand>();
            var theWrapper = new TransactionalCommandExecutorWrapper <ICommand>(aExecutor);

            theWrapper.Execute(aCommand);

            aExecutor.AssertWasCalled(e => e.Execute(aCommand));
        }
        /// <summary>
        /// Executes the command.
        /// </summary>
        /// <param name="command">The command to execute. This should not be null.</param>
        /// <exception cref="ArgumentNullException">Occurs when <i>command</i> is null.</exception>
        void ICommandExecutor <TCommand> .Execute(TCommand command)
        {
            var factory  = new AttributeBasedMappingFactory();
            var executor = factory.CreateExecutorForCommand <TCommand>();

            if (command.GetType().IsDefined(typeof(TransactionalAttribute), true))
            {
                executor = new TransactionalCommandExecutorWrapper <TCommand>(executor);
            }

            executor.Execute(command);
        }
        public void When_creating_with_creation_callback_the_callback_should_be_called_for_TransactionScope_creation()
        {
            var callCount = 0;
            var creationCallback = new Func<TransactionScope>(() =>
            {
                callCount++;
                return new TransactionScope();
            });

            var aExecutor = MockRepository.GenerateMock<ICommandExecutor<DummyCommand>>();
            var theWrapper = new TransactionalCommandExecutorWrapper<DummyCommand>(aExecutor, creationCallback);

            theWrapper.Execute(new DummyCommand());
            callCount.Should().Be(1);

            theWrapper.Execute(new DummyCommand());
            callCount.Should().Be(2);
        }
        public void When_creating_with_creation_callback_the_callback_should_be_called_for_TransactionScope_creation()
        {
            var callCount        = 0;
            var creationCallback = new Func <TransactionScope>(() =>
            {
                callCount++;
                return(new TransactionScope());
            });

            var aExecutor  = MockRepository.GenerateMock <ICommandExecutor <DummyCommand> >();
            var theWrapper = new TransactionalCommandExecutorWrapper <DummyCommand>(aExecutor, creationCallback);

            theWrapper.Execute(new DummyCommand());
            callCount.Should().Be(1);

            theWrapper.Execute(new DummyCommand());
            callCount.Should().Be(2);
        }