Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permit state reentry from dynamic transitions. #571

Merged

Conversation

mclift
Copy link
Member

@mclift mclift commented Apr 19, 2024

To address issue #565, this PR restores the pre-v5.15 behavior so that state re-entry is possible when dynamic transitions are used.

Example:

var sm = new StateMachine<State, Trigger>(State.A);
sm.Configure(State.A).PermitDynamic(Trigger.X, () => State.A);
Console.WriteLine($"Initial state: {sm.State}");

// Firing Trigger.X does not cause InvalidOperation to be thrown.
sm.Fire(Trigger.X);
Console.WriteLine($"Final state: {sm.State}");

// Output:
// Initial state: A
// Final state: A


Assert.Equal(expectedParam, actualParam);
}

[Fact]
public async Task FireAsync_TriggerWithMoreThanThreeParameters()
{
const string expectedParam = "42-Stateless-True-420.69-Y";
const string expectedParam = "42-Stateless-True-123.45-Y";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The behavior of ToString is based on the current user's locale setting.
This test will fail on machines with a different locale.
One could either use ToString in the input as well or pin the locale.
Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
string expectedParam = $"42-Stateless-True-{123.45}-Y";

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot, @Fieslix, thank you. Should be resolved now.

mclift and others added 11 commits April 21, 2024 11:51
…yncActionsFixture_unit_test_and_a_potential_null_reference_exception_in_InvocationInfo_class

Fix NullReferenceException in the InvocationInfo class. Fix a FireAsync_TriggerWithMoreThanThreeParameters test failure because of a different system locale.
…ift/stateless into 565-reentry-from-dynamic-transitions
@mclift mclift merged commit 67b18fa into dotnet-state-machine:dev Apr 24, 2024
1 check passed
@mclift mclift deleted the 565-reentry-from-dynamic-transitions branch April 24, 2024 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants