diff --git a/TxCommand.Abstractions/ITxCommand.cs b/TxCommand.Abstractions/ITxCommand.cs
index 27a015a..969d66f 100644
--- a/TxCommand.Abstractions/ITxCommand.cs
+++ b/TxCommand.Abstractions/ITxCommand.cs
@@ -3,12 +3,19 @@
namespace TxCommand.Abstractions
{
+ ///
+ /// An empty interface used to identify the different variants of .
+ ///
+ public interface ICommand
+ {
+ }
+
///
/// A transaction command is an abstraction used to execute a command which requires
/// a database transaction in order to operate correctly. provides a method
/// to execute the command, providing it with a .
///
- public interface ITxCommand
+ public interface ITxCommand : ICommand
{
///
/// Executes the implementing command, providing a , allowing
@@ -34,7 +41,7 @@ public interface ITxCommand
/// this provides a type argument, , allowing the
/// command to output data.
///
- public interface ITxCommand
+ public interface ITxCommand : ICommand
{
///
/// Executes the implementing command, providing a , allowing
diff --git a/TxCommand.Abstractions/TxCommand.Abstractions.csproj b/TxCommand.Abstractions/TxCommand.Abstractions.csproj
index 829b1f6..1e0463e 100644
--- a/TxCommand.Abstractions/TxCommand.Abstractions.csproj
+++ b/TxCommand.Abstractions/TxCommand.Abstractions.csproj
@@ -8,9 +8,9 @@
https://github.com/reecerussell/tx-command
git
CQRS, commanding, sql, transaction
- 0.2.0.0
- 0.2.0.0
- 0.2.0
+ 0.3.0.0
+ 0.3.0.0
+ 0.3.0
LICENSE
https://github.com/reecerussell/tx-command
diff --git a/TxCommand.Tests/TxCommandExecutorTests.cs b/TxCommand.Tests/TxCommandExecutorTests.cs
index 531ad3c..c64424d 100644
--- a/TxCommand.Tests/TxCommandExecutorTests.cs
+++ b/TxCommand.Tests/TxCommandExecutorTests.cs
@@ -101,8 +101,18 @@ public async Task ExecuteAsync_GivenCommand_ExecutesTheCommand()
command.Setup(x => x.ExecuteAsync(connection.Object, transaction)).Returns(Task.CompletedTask).Verifiable();
var commandExecutor = new TxCommandExecutor(connection.Object);
+
+ var callbackCalled = false;
+ commandExecutor.OnComplete += (c) =>
+ {
+ callbackCalled = true;
+ Assert.Equal(command.Object, c);
+ };
+
await commandExecutor.ExecuteAsync(command.Object);
+ Assert.True(callbackCalled);
+
command.Verify(x => x.Validate(), Times.Once);
command.Verify(x => x.ExecuteAsync(connection.Object, transaction), Times.Once);
connection.Verify(x => x.BeginTransaction());
@@ -224,8 +234,18 @@ public async Task ExecuteAsyncWithResult_GivenCommand_ExecutesTheCommand()
command.Setup(x => x.ExecuteAsync(connection.Object, transaction)).ReturnsAsync(testResult).Verifiable();
var commandExecutor = new TxCommandExecutor(connection.Object);
- var result = await commandExecutor.ExecuteAsync(command.Object);
+
+ var callbackCalled = false;
+ commandExecutor.OnComplete += (c) =>
+ {
+ callbackCalled = true;
+ Assert.Equal(command.Object, c);
+ };
+
+ var result =await commandExecutor.ExecuteAsync(command.Object);
+
Assert.Equal(testResult, result);
+ Assert.True(callbackCalled);
command.Verify(x => x.Validate(), Times.Once);
command.Verify(x => x.ExecuteAsync(connection.Object, transaction), Times.Once);
diff --git a/TxCommand/TxCommand.csproj b/TxCommand/TxCommand.csproj
index 44c5e75..aa9a1e8 100644
--- a/TxCommand/TxCommand.csproj
+++ b/TxCommand/TxCommand.csproj
@@ -2,7 +2,7 @@
netstandard2.0
- 0.3.1
+ 0.4.0
Reece Russell
https://github.com/reecerussell/tx-command
git
@@ -10,8 +10,8 @@
Provides support for executing CQRS command within a database transaction.
true
- 0.3.1.0
- 0.3.1.0
+ 0.4.0.0
+ 0.4.0.0
https://github.com/reecerussell/tx-command
LICENSE
diff --git a/TxCommand/TxCommandExecutor.cs b/TxCommand/TxCommandExecutor.cs
index 6f9cc54..d921f1b 100644
--- a/TxCommand/TxCommandExecutor.cs
+++ b/TxCommand/TxCommandExecutor.cs
@@ -16,6 +16,9 @@ public class TxCommandExecutor : ITxCommandExecutor
private bool _disposed = false;
private bool _completed = true;
+ public delegate void CommandDelegate(ICommand command);
+ public CommandDelegate OnComplete;
+
///
/// Initializes a new instance of .
///
@@ -92,6 +95,8 @@ public async Task ExecuteAsync(ITxCommand command)
{
command.Validate();
await command.ExecuteAsync(_connection, _transaction);
+
+ OnComplete?.Invoke(command);
}
catch
{
@@ -137,7 +142,12 @@ public async Task ExecuteAsync(ITxCommand command)
try
{
command.Validate();
- return await command.ExecuteAsync(_connection, _transaction);
+
+ var result = await command.ExecuteAsync(_connection, _transaction);
+
+ OnComplete?.Invoke(command);
+
+ return result;
}
catch
{