diff --git a/src/Stateless/Reflection/DynamicTransitionInfo.cs b/src/Stateless/Reflection/DynamicTransitionInfo.cs index a8179256..7b2cc6fb 100644 --- a/src/Stateless/Reflection/DynamicTransitionInfo.cs +++ b/src/Stateless/Reflection/DynamicTransitionInfo.cs @@ -68,16 +68,7 @@ public class DynamicTransitionInfo : TransitionInfo /// public DynamicStateInfos PossibleDestinationStates { get; private set; } - /// - /// Creates a new instance of . - /// - /// The trigger type. - /// The trigger associated with this transition. - /// The guard conditions associated with this transition. - /// The destination selector associated with this transition. - /// The possible destination states. - /// - public static DynamicTransitionInfo Create(TTrigger trigger, IEnumerable guards, + internal static DynamicTransitionInfo Create(TTrigger trigger, IEnumerable guards, InvocationInfo selector, DynamicStateInfos possibleStates) { var transition = new DynamicTransitionInfo diff --git a/src/Stateless/StateConfiguration.Async.cs b/src/Stateless/StateConfiguration.Async.cs index 53a8c918..e409ea40 100644 --- a/src/Stateless/StateConfiguration.Async.cs +++ b/src/Stateless/StateConfiguration.Async.cs @@ -9,23 +9,6 @@ public partial class StateMachine { public partial class StateConfiguration { - /// - /// Add an internal transition to the state machine. An internal action does not cause the Exit and Entry actions to be triggered, and does not change the state of the state machine - /// - /// - /// The accepted trigger - /// Function that must return true in order for the trigger to be accepted. - /// The asynchronous action performed by the internal transition - /// - [Obsolete("Use InternalTransitionAsyncIf(TTrigger, Func, Func) instead.")] - public StateConfiguration InternalTransitionAsyncIf(TTrigger trigger, Func guard, Func internalAction) - { - if (internalAction == null) throw new ArgumentNullException(nameof(internalAction)); - - _representation.AddTriggerBehaviour(new InternalTriggerBehaviour.Async(trigger, guard, (t, args) => internalAction(t))); - return this; - } - /// /// Add an internal transition to the state machine. An internal action does not cause the Exit and Entry actions to be triggered, and does not change the state of the state machine /// @@ -88,19 +71,6 @@ public StateConfiguration InternalTransitionAsyncIf(Trigger return this; } - /// - /// Add an internal transition to the state machine. An internal action does not cause the Exit and Entry actions to be triggered, and does not change the state of the state machine - /// - /// - /// The accepted trigger - /// The asynchronous action performed by the internal transition - /// - [Obsolete("Use InternalTransitionAsync(TTrigger, Func) instead.")] - public StateConfiguration InternalTransitionAsync(TTrigger trigger, Func internalAction) - { - return InternalTransitionAsyncIf(trigger, () => true, internalAction); - } - /// /// Add an internal transition to the state machine. An internal action does not cause the Exit and Entry actions to be triggered, and does not change the state of the state machine /// diff --git a/src/Stateless/StateConfiguration.cs b/src/Stateless/StateConfiguration.cs index beec0168..700f75e2 100644 --- a/src/Stateless/StateConfiguration.cs +++ b/src/Stateless/StateConfiguration.cs @@ -48,27 +48,27 @@ public StateConfiguration Permit(TTrigger trigger, TState destinationState) /// /// Add an internal transition to the state machine. An internal action does not cause the Exit and Entry actions to be triggered, and does not change the state of the state machine /// - /// - /// + /// The accepted trigger + /// The action performed by the internal transition /// - public StateConfiguration InternalTransition(TTrigger trigger, Action entryAction) + public StateConfiguration InternalTransition(TTrigger trigger, Action internalAction) { - return InternalTransitionIf(trigger, t => true, entryAction); + return InternalTransitionIf(trigger, t => true, internalAction); } /// /// Add an internal transition to the state machine. An internal action does not cause the Exit and Entry actions to be triggered, and does not change the state of the state machine /// - /// + /// The accepted trigger /// Function that must return true in order for the trigger to be accepted. - /// + /// The action performed by the internal transition /// A description of the guard condition /// - public StateConfiguration InternalTransitionIf(TTrigger trigger, Func guard, Action entryAction, string guardDescription = null) + public StateConfiguration InternalTransitionIf(TTrigger trigger, Func guard, Action internalAction, string guardDescription = null) { - if (entryAction == null) throw new ArgumentNullException(nameof(entryAction)); + if (internalAction == null) throw new ArgumentNullException(nameof(internalAction)); - _representation.AddTriggerBehaviour(new InternalTriggerBehaviour.Sync(trigger, guard, (t, args) => entryAction(t), guardDescription)); + _representation.AddTriggerBehaviour(new InternalTriggerBehaviour.Sync(trigger, guard, (t, args) => internalAction(t), guardDescription)); return this; } @@ -99,35 +99,6 @@ public StateConfiguration InternalTransitionIf(TTrigger trigger, Func - /// Add an internal transition to the state machine. An internal action does not cause the Exit and Entry actions to be triggered, and does not change the state of the state machine - /// - /// - /// The accepted trigger - /// Function that must return true in order for the trigger to be accepted. - /// The action performed by the internal transition - /// A description of the guard condition - /// - public StateConfiguration InternalTransitionIf(TTrigger trigger, Func guard, Action internalAction, string guardDescription = null) - { - if (internalAction == null) throw new ArgumentNullException(nameof(internalAction)); - - _representation.AddTriggerBehaviour(new InternalTriggerBehaviour.Sync(trigger, guard, (t, args) => internalAction(t), guardDescription)); - return this; - } - - /// - /// Add an internal transition to the state machine. An internal action does not cause the Exit and Entry actions to be triggered, and does not change the state of the state machine - /// - /// - /// The accepted trigger - /// The action performed by the internal transition - /// - public StateConfiguration InternalTransition(TTrigger trigger, Action internalAction) - { - return InternalTransitionIf(trigger, t => true, internalAction); - } - /// /// Add an internal transition to the state machine. An internal action does not cause the Exit and Entry actions to be triggered, and does not change the state of the state machine /// diff --git a/src/Stateless/StateMachine.cs b/src/Stateless/StateMachine.cs index 270cc620..9317e1d9 100644 --- a/src/Stateless/StateMachine.cs +++ b/src/Stateless/StateMachine.cs @@ -246,7 +246,7 @@ public void Fire(TriggerWithParameters trigger, params object[] args) public TriggerWithParameters SetTriggerParameters(TTrigger trigger, params Type[] argumentTypes) { var configuration = new TriggerWithParameters(trigger, argumentTypes); - SaveTriggerConfiguration(configuration); + SetTriggerParameters(configuration); return configuration; } @@ -600,7 +600,7 @@ public override string ToString() public TriggerWithParameters SetTriggerParameters(TTrigger trigger) { var configuration = new TriggerWithParameters(trigger); - SaveTriggerConfiguration(configuration); + SetTriggerParameters(configuration); return configuration; } @@ -615,7 +615,7 @@ public TriggerWithParameters SetTriggerParameters(TTrigger trigger public TriggerWithParameters SetTriggerParameters(TTrigger trigger) { var configuration = new TriggerWithParameters(trigger); - SaveTriggerConfiguration(configuration); + SetTriggerParameters(configuration); return configuration; } @@ -631,11 +631,15 @@ public TriggerWithParameters SetTriggerParameters(TT public TriggerWithParameters SetTriggerParameters(TTrigger trigger) { var configuration = new TriggerWithParameters(trigger); - SaveTriggerConfiguration(configuration); + SetTriggerParameters(configuration); return configuration; } - void SaveTriggerConfiguration(TriggerWithParameters trigger) + /// + /// Specify the arguments that must be supplied when a specific trigger is fired. + /// + /// The underlying trigger value and the argument types expected by the trigger. + public void SetTriggerParameters(TriggerWithParameters trigger) { if (_triggerConfiguration.ContainsKey(trigger.Trigger)) throw new InvalidOperationException( diff --git a/test/Stateless.Tests/InternalTransitionAsyncFixture.cs b/test/Stateless.Tests/InternalTransitionAsyncFixture.cs index 1cc9e68e..255899fb 100644 --- a/test/Stateless.Tests/InternalTransitionAsyncFixture.cs +++ b/test/Stateless.Tests/InternalTransitionAsyncFixture.cs @@ -217,27 +217,6 @@ public async Task InternalTransitionAsyncIf_DeprecatedOverload_AllowGuardWithThr Assert.True(callbackInvoked); } - [Fact] - [Obsolete] - public async Task InternalTransitionAsyncIf_DeprecatedOverload_GuardExecutedOnlyOnce() - { - var guardCalls = 0; - var order = new Order - { - Status = OrderStatus.OrderPlaced, - PaymentStatus = PaymentStatus.Pending, - }; - var stateMachine = new StateMachine(order.Status); - stateMachine.Configure(OrderStatus.OrderPlaced) - .InternalTransitionAsyncIf(OrderStateTrigger.PaymentCompleted, - () => PreCondition(ref guardCalls), - _ => ChangePaymentState(order, PaymentStatus.Completed)); - - await stateMachine.FireAsync(OrderStateTrigger.PaymentCompleted); - - Assert.Equal(1, guardCalls); - } - /// /// This unit test demonstrated bug report #417 ///