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

- Method CanFire supports trigger with parameters #467

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/BuildAndTestOnPullRequests.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CI for Pull Requests

on:
on:
workflow_dispatch:
push:
branches: [ dev, master ]
pull_request:
Expand All @@ -25,14 +25,14 @@ jobs:

- name: Pack alpha version
if: github.ref == 'refs/heads/dev' && github.event_name == 'push'
run: dotnet pack src/stateless/stateless.csproj --version-suffix dev-${{github.run_id}} --configuration Release
run: dotnet pack src/Stateless/Stateless.csproj --version-suffix dev-${{github.run_id}} --configuration Release
- name: Publish alpha version
if: github.ref == 'refs/heads/dev' && github.event_name == 'push'
run: dotnet nuget push src\stateless\bin\Release\*.nupkg -s nuget.org --api-key ${{ secrets.NUGETAPIKEY }}
run: dotnet nuget push src\Stateless\bin\Release\*.nupkg -s nuget.org --api-key ${{ secrets.NUGETAPIKEY }}

- name: Pack Release version
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
run: dotnet pack src/stateless/stateless.csproj --configuration Release
run: dotnet pack src/Stateless/Stateless.csproj --configuration Release
- name: Publish Release version
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
run: dotnet nuget push src\stateless\bin\Release\*.nupkg -s nuget.org --api-key ${{ secrets.NUGETAPIKEY }}
run: dotnet nuget push src\Stateless\bin\Release\*.nupkg -s nuget.org --api-key ${{ secrets.NUGETAPIKEY }}
12 changes: 12 additions & 0 deletions src/Stateless/StateMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,18 @@ public bool CanFire(TTrigger trigger)
{
return CurrentRepresentation.CanHandle(trigger);
}
/// <summary>
/// Returns true if <paramref name="trigger"/> can be fired
/// in the current state.
/// </summary>
/// <param name="trigger">The trigger to fire.</param>
/// <param name="args">A variable-length parameters list containing arguments. </param>
/// <returns>True if the trigger can be fired, false otherwise.</returns>
/// <exception cref="ArgumentNullException"></exception>
public bool CanFire(TriggerWithParameters trigger, params object[] args) {
if (trigger == null) throw new ArgumentNullException(nameof(trigger));
return CurrentRepresentation.CanHandle(trigger.Trigger, args);
}

/// <summary>
/// Returns true if <paramref name="trigger"/> can be fired
Expand Down
3 changes: 2 additions & 1 deletion src/Stateless/Stateless.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
<PackageIcon>Stateless.png</PackageIcon>
<PackageProjectUrl>https://github.com/dotnet-state-machine/stateless</PackageProjectUrl>
<PackageProjectUrl>https://github.com/josellm/stateless</PackageProjectUrl>
<license>http://www.apache.org/licenses/LICENSE-2.0</license>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<PackageId>Stateless.josellm</PackageId>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.0' OR '$(TargetFramework)' == 'netstandard2.0' ">
Expand Down
9 changes: 9 additions & 0 deletions test/Stateless.Tests/StateMachineFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,15 @@ public void WhenConfigureConditionallyPermittedTransitionOnTriggerWithParameters
Assert.True(sm.CanFire(trigger));
}

[Fact]
public void WhenParameterizedGuardTrue_ThenStateMachineCanFireTrigger() {
var sm = new StateMachine<State, Trigger>(State.A);
var x = sm.SetTriggerParameters<int>(Trigger.X);
sm.Configure(State.A).PermitIf(x, State.B, i => i == 2);
Assert.False(sm.CanFire(x, 1));
Assert.True(sm.CanFire(x, 2));
}

[Fact]
public void WhenConfigureConditionallyPermittedTransitionOnTriggerWithParameters_ThenStateMachineCanEnumeratePermittedTriggers()
{
Expand Down