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

Fix entry function being shown on internal transitions in dot graph #589

Merged
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
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