Exemplo n.º 1
0
        public async Task ShouldCommitTransactionAfterSuccessfulCommandExecution()
        {
            var behavior = new TransactionalCommandsBehavior <Command, Result <int> >(_transactionProviderMock.Object, _transactionalBehaviorValidator);
            await behavior.Handle(new Command(), CancellationToken.None, () => Task.FromResult(Result.Ok(2)));

            _transactionProviderMock.Verify(provider => provider.CommitTransactionAsync(), Times.Once);
        }
Exemplo n.º 2
0
        public async Task ShouldIgnoreMediatorRequests()
        {
            var behavior = new TransactionalCommandsBehavior <WrongCommand, int>(_transactionProviderMock.Object, _transactionalBehaviorValidator);
            await behavior.Handle(new WrongCommand(), CancellationToken.None, () => Task.FromResult(2));

            _transactionProviderMock.Verify(provider => provider.BeginTransactionAsync(), Times.Never);
        }
Exemplo n.º 3
0
        public void ShouldRollbackTransactionAfterExceptionInCommandExecution()
        {
            var         behavior     = new TransactionalCommandsBehavior <Command, Result <int> >(_transactionProviderMock.Object, _transactionalBehaviorValidator);
            Func <Task> handleAction = async() => await behavior.Handle(new Command(), CancellationToken.None, () => throw new Exception("Inavlid execution"));

            handleAction.Should().ThrowAsync <Exception>();
            _transactionProviderMock.Verify(provider => provider.RollbackTransactionAsync(), Times.Once);
        }
Exemplo n.º 4
0
        public async Task ShouldRollbackTransactionAfterFailureCommandExecution()
        {
            var invalidExecutionError = new Error.ErrorType("INVALID_EXECUTION", "Invalid execution").Build();
            var behavior = new TransactionalCommandsBehavior <Command, Result <int> >(_transactionProviderMock.Object, _transactionalBehaviorValidator);
            await behavior.Handle(new Command(), CancellationToken.None, () => Task.FromResult(Result.Fail <int>(invalidExecutionError)));

            _transactionProviderMock.Verify(provider => provider.RollbackTransactionAsync(), Times.Once);
        }