Skip to content
Merged
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
1 change: 1 addition & 0 deletions source/Lite.State.Tests/Lite.State.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="10.0.1" />
<PackageReference Include="MSTest" Version="4.0.1" />
</ItemGroup>

Expand Down
12 changes: 10 additions & 2 deletions source/Lite.State.Tests/StateTests/BasicStateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Linq;

namespace Lite.State.Tests.StateTests;

Expand Down Expand Up @@ -38,9 +39,17 @@ public void RegisterState_Transition_SuccessTest()

// Assert Results
var ctxFinalParams = machine.Context.Parameters;

Assert.IsNotNull(ctxFinalParams);
Assert.AreEqual(TestValue, ctxFinalParams[ParameterKeyTest]);

var enums = Enum.GetValues(typeof(StateId)).Cast<StateId>();

// Ensure all states are hit
Assert.AreEqual(enums.Count(), machine.States.Count());
Assert.IsTrue(enums.All(k => machine.States.Keys.Contains(k)));

// Ensure they're in order
Assert.IsTrue(enums.SequenceEqual(machine.States.Keys));
}

/// <summary>Defines State Enum ID and `OnSuccess` transitions from the `RegisterStateEx` method.</summary>
Expand All @@ -62,7 +71,6 @@ public void RegisterStateEx_Transitions_SuccessTest()

// Assert Results
var ctxFinalParams = machine.Context.Parameters;

Assert.IsNotNull(ctxFinalParams);
Assert.AreEqual(TestValue, ctxFinalParams[ParameterKeyTest]);
}
Expand Down
6 changes: 6 additions & 0 deletions source/Lite.State/StateMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,16 @@ private StateMachine(StateMachine<TState> parentMachine, ICompositeState<TState>
_logger = logs;
}

/// <summary>Gets the context payload passed between the states, and contains methods for transitioning to the next state.</summary>
public Context<TState> Context { get; private set; } = default!;

/// <summary>Gets or sets the default timeout (3000ms default) to be used by <see cref="CommandState{TState}"/>'s OnTimeout.</summary>
public int DefaultTimeoutMs { get; set; } = 3000;

/// <summary>Gets the collection of all registered states.</summary>
/// <remarks>Exposed for validations, debugging, etc.</remarks>
public Dictionary<TState, IState<TState>> States => _states;

public void RegisterState(IState<TState> state)
{
ArgumentNullException.ThrowIfNull(state);
Expand Down