Skip to content

Commit

Permalink
Merge pull request #589 from mclift/bugfix/dotgraph-internal-transitions
Browse files Browse the repository at this point in the history
Fix entry function being shown on internal transitions in dot graph
  • Loading branch information
mclift authored Jul 7, 2024
2 parents d58e33b + 48ce60a commit c896d66
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Stateless/Graph/StateGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void AddTransitions(StateMachineInfo machineInfo)
State toState = States[fix.DestinationState.UnderlyingState.ToString()];
if (fromState == toState)
{
StayTransition stay = new StayTransition(fromState, fix.Trigger, fix.GuardConditionsMethodDescriptions, true);
StayTransition stay = new StayTransition(fromState, fix.Trigger, fix.GuardConditionsMethodDescriptions, !fix.IsInternalTransition);
Transitions.Add(stay);
fromState.Leaving.Add(stay);
fromState.Arriving.Add(stay);
Expand Down
3 changes: 2 additions & 1 deletion src/Stateless/Reflection/FixedTransitionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ internal static FixedTransitionInfo Create<TState, TTrigger>(StateMachine<TState
Trigger = new TriggerInfo(behaviour.Trigger),
DestinationState = destinationStateInfo,
GuardConditionsMethodDescriptions = behaviour.Guard == null
? new List<InvocationInfo>() : behaviour.Guard.Conditions.Select(c => c.MethodDescription)
? new List<InvocationInfo>() : behaviour.Guard.Conditions.Select(c => c.MethodDescription),
IsInternalTransition = behaviour is StateMachine<TState, TTrigger>.InternalTriggerBehaviour
};

return transition;
Expand Down
5 changes: 5 additions & 0 deletions src/Stateless/Reflection/TransitionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,10 @@ public abstract class TransitionInfo
/// Returns a non-null but empty list if there are no guard conditions
/// </summary>
public IEnumerable<InvocationInfo> GuardConditionsMethodDescriptions;

/// <summary>
/// When true, the transition is internal and does not invoke the entry/exit actions of the state.
/// </summary>
public bool IsInternalTransition { get; protected set; }
}
}
24 changes: 24 additions & 0 deletions test/Stateless.Tests/DotGraphFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,30 @@ public void TransitionWithIgnoreAndEntry()
Assert.Equal(expected, dotGraph);
}

[Fact]
public void Internal_Transition_Does_Not_Show_Entry_Exit_Functions()
{
var expected = Prefix(Style.UML)
+ Box(Style.UML, "A", new List<string> { "DoEntry" }, new List<string> { "DoExit" })
+ Line("A", "A", "X [Function]")
+ suffix;

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

sm.Configure(State.A)
.OnEntry(x => { }, "DoEntry")
.OnExit(x => { }, "DoExit")
.InternalTransition(Trigger.X, x => { });

string dotGraph = UmlDotGraph.Format(sm.GetInfo());

#if WRITE_DOTS_TO_FOLDER
System.IO.File.WriteAllText(DestinationFolder + "Internal_Transition_Does_Not_Show_Entry_Exit_Functions.dot", dotGraph);
#endif

Assert.Equal(expected, dotGraph);
}

[Fact]
public void Initial_State_Not_Changed_After_Trigger_Fired()
{
Expand Down

0 comments on commit c896d66

Please sign in to comment.