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); }
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); }
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); }
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); }