Skip to content

Commit

Permalink
Add FireAsync(TTrigger, params object[]) overload
Browse files Browse the repository at this point in the history
The ability for this was recently added for TriggersWithParameters.  Need similar functionality to reduce the need for reflection to get to the internal method.
  • Loading branch information
RLittlesII committed Apr 10, 2024
1 parent 66eee8f commit 3826628
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Stateless/StateMachine.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ public Task FireAsync(TTrigger trigger)
return InternalFireAsync(trigger, new object[0]);
}

/// <summary>
/// Transition from the current state via the specified trigger in async fashion.
/// The target state is determined by the configuration of the current state.
/// Actions associated with leaving the current state and entering the new one
/// will be invoked.
/// </summary>
/// <param name="trigger">The trigger to fire.</param>
/// <param name="args">A variable-length parameters list containing arguments. </param>
public Task FireAsync(TTrigger trigger, params object[] args)
{
return InternalFireAsync(trigger, args);
}

/// <summary>
/// Transition from the current state via the specified trigger in async fashion.
/// The target state is determined by the configuration of the current state.
Expand Down
23 changes: 23 additions & 0 deletions test/Stateless.Tests/AsyncActionsFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,29 @@ public async Task OnEntryFromAsync_WhenEnteringByAnotherTrigger_InvokesAction()
Assert.False(wasInvoked);
}

[Fact]
public async Task FireAsyncTriggerWithParametersArray()
{
const string expectedParam = "42-Stateless-True-420.69-Y";
string actualParam = null;

var sm = new StateMachine<State, Trigger>(State.A);

sm.Configure(State.A)
.Permit(Trigger.X, State.B);

sm.Configure(State.B)
.OnEntryAsync(t =>
{
actualParam = string.Join("-", t.Parameters);
return Task.CompletedTask;
});

await sm.FireAsync(Trigger.X, 42, "Stateless", true, 420.69, Trigger.Y);

Assert.Equal(expectedParam, actualParam);
}

[Fact]
public async Task FireAsync_TriggerWithMoreThanThreeParameters()
{
Expand Down

0 comments on commit 3826628

Please sign in to comment.