diff --git a/src/Stateless/StateMachine.Async.cs b/src/Stateless/StateMachine.Async.cs index 685c751e..cafc6f97 100644 --- a/src/Stateless/StateMachine.Async.cs +++ b/src/Stateless/StateMachine.Async.cs @@ -216,7 +216,7 @@ private async Task InternalFireOneAsync(TTrigger trigger, params object[] args) if (foundHandler == null || foundHandler.UnmetGuardConditions.Any()) { - await _unhandledTriggerAction.ExecuteAsync(representativeState.UnderlyingState, trigger, null); + await _unhandledTriggerAction.ExecuteAsync(representativeState.UnderlyingState, trigger, foundHandler?.UnmetGuardConditions); return; } diff --git a/test/Stateless.Tests/AsyncActionsFixture.cs b/test/Stateless.Tests/AsyncActionsFixture.cs index e038a76a..b3b0cb0b 100644 --- a/test/Stateless.Tests/AsyncActionsFixture.cs +++ b/test/Stateless.Tests/AsyncActionsFixture.cs @@ -314,6 +314,46 @@ public async Task CanInvokeOnUnhandledTriggerAsyncAction() Assert.Equal("foo", test); // Should await action } + + [Fact] + public async Task CanInvokeOnUnhandledTriggerAsyncActionWithUnmetGuardDescriptions() + { + const string guardDescription = "Guard failed"; + ICollection guardDescriptions = null; + var sm = new StateMachine(State.A); + + sm.Configure(State.A) + .PermitIfAsync(Trigger.X, State.B, async () => await Task.FromResult(false), guardDescription); + + sm.OnUnhandledTriggerAsync((s, t, u) => + { + guardDescriptions = u; + return TaskResult.Done; + }); + + await sm.FireAsync(Trigger.X).ConfigureAwait(false); + + Assert.Equal(State.A, sm.State); + Assert.NotNull(guardDescriptions); + Assert.Single(guardDescriptions); + Assert.Contains(guardDescription, guardDescriptions); + } + + [Fact] + public async Task FireAsyncThrowsGuardDescriptionsWhenGuardFails() + { + const string guardDescription = "Guard failed"; + var sm = new StateMachine(State.A); + + sm.Configure(State.A) + .PermitIfAsync(Trigger.X, State.B, async () => await Task.FromResult(false), guardDescription); + + var exception = await Assert.ThrowsAsync( + () => sm.FireAsync(Trigger.X)).ConfigureAwait(false); + + Assert.Contains(guardDescription, exception.Message); + } + [Fact] public void WhenSyncFireOnUnhandledTriggerAsyncTask() { diff --git a/test/Stateless.Tests/Stateless.Tests.csproj b/test/Stateless.Tests/Stateless.Tests.csproj index 2eed06a8..134641d0 100644 --- a/test/Stateless.Tests/Stateless.Tests.csproj +++ b/test/Stateless.Tests/Stateless.Tests.csproj @@ -3,7 +3,7 @@ $(DefineConstants);TASKS true - net462;net8.0;net9.0 + net462;net8.0;net9.0;net10.0 false Stateless.Tests ../../asset/Stateless.snk