Skip to content

Commit c896d66

Browse files
authored
Merge pull request #589 from mclift/bugfix/dotgraph-internal-transitions
Fix entry function being shown on internal transitions in dot graph
2 parents d58e33b + 48ce60a commit c896d66

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

src/Stateless/Graph/StateGraph.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void AddTransitions(StateMachineInfo machineInfo)
137137
State toState = States[fix.DestinationState.UnderlyingState.ToString()];
138138
if (fromState == toState)
139139
{
140-
StayTransition stay = new StayTransition(fromState, fix.Trigger, fix.GuardConditionsMethodDescriptions, true);
140+
StayTransition stay = new StayTransition(fromState, fix.Trigger, fix.GuardConditionsMethodDescriptions, !fix.IsInternalTransition);
141141
Transitions.Add(stay);
142142
fromState.Leaving.Add(stay);
143143
fromState.Arriving.Add(stay);

src/Stateless/Reflection/FixedTransitionInfo.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ internal static FixedTransitionInfo Create<TState, TTrigger>(StateMachine<TState
1515
Trigger = new TriggerInfo(behaviour.Trigger),
1616
DestinationState = destinationStateInfo,
1717
GuardConditionsMethodDescriptions = behaviour.Guard == null
18-
? new List<InvocationInfo>() : behaviour.Guard.Conditions.Select(c => c.MethodDescription)
18+
? new List<InvocationInfo>() : behaviour.Guard.Conditions.Select(c => c.MethodDescription),
19+
IsInternalTransition = behaviour is StateMachine<TState, TTrigger>.InternalTriggerBehaviour
1920
};
2021

2122
return transition;

src/Stateless/Reflection/TransitionInfo.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,10 @@ public abstract class TransitionInfo
1717
/// Returns a non-null but empty list if there are no guard conditions
1818
/// </summary>
1919
public IEnumerable<InvocationInfo> GuardConditionsMethodDescriptions;
20+
21+
/// <summary>
22+
/// When true, the transition is internal and does not invoke the entry/exit actions of the state.
23+
/// </summary>
24+
public bool IsInternalTransition { get; protected set; }
2025
}
2126
}

test/Stateless.Tests/DotGraphFixture.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,30 @@ public void TransitionWithIgnoreAndEntry()
537537
Assert.Equal(expected, dotGraph);
538538
}
539539

540+
[Fact]
541+
public void Internal_Transition_Does_Not_Show_Entry_Exit_Functions()
542+
{
543+
var expected = Prefix(Style.UML)
544+
+ Box(Style.UML, "A", new List<string> { "DoEntry" }, new List<string> { "DoExit" })
545+
+ Line("A", "A", "X [Function]")
546+
+ suffix;
547+
548+
var sm = new StateMachine<State, Trigger>(State.A);
549+
550+
sm.Configure(State.A)
551+
.OnEntry(x => { }, "DoEntry")
552+
.OnExit(x => { }, "DoExit")
553+
.InternalTransition(Trigger.X, x => { });
554+
555+
string dotGraph = UmlDotGraph.Format(sm.GetInfo());
556+
557+
#if WRITE_DOTS_TO_FOLDER
558+
System.IO.File.WriteAllText(DestinationFolder + "Internal_Transition_Does_Not_Show_Entry_Exit_Functions.dot", dotGraph);
559+
#endif
560+
561+
Assert.Equal(expected, dotGraph);
562+
}
563+
540564
[Fact]
541565
public void Initial_State_Not_Changed_After_Trigger_Fired()
542566
{

0 commit comments

Comments
 (0)