Skip to content

Commit

Permalink
Remove explicit name of child state machine, using parent state's name
Browse files Browse the repository at this point in the history
  • Loading branch information
canton7 committed Sep 1, 2015
1 parent 4de7e5b commit 64b7a44
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 31 deletions.
5 changes: 2 additions & 3 deletions src/StateMechanic/State.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,10 @@ public State WithExit(Action<StateHandlerInfo<State>> exitHandler)
/// <summary>
/// Create a StateMachine belonging to this state, which will be started when this State is entered
/// </summary>
/// <param name="name">Name of the state machine</param>
/// <returns>The created state machine</returns>
public ChildStateMachine CreateChildStateMachine(string name)
public ChildStateMachine CreateChildStateMachine()
{
this.ChildStateMachine = new ChildStateMachine(name, this.ParentStateMachine.InnerStateMachine.Kernel, this);
this.ChildStateMachine = new ChildStateMachine(this.Name, this.ParentStateMachine.InnerStateMachine.Kernel, this);
this.innerState.ChildStateMachine = this.ChildStateMachine;
return this.ChildStateMachine;
}
Expand Down
5 changes: 2 additions & 3 deletions src/StateMechanic/State`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,10 @@ public State<TStateData> WithExit(Action<StateHandlerInfo<State<TStateData>>> ex
/// <summary>
/// Create a StateMachine belonging to this state, which will be started when this State is entered
/// </summary>
/// <param name="name">Name of the state machine</param>
/// <returns>The created state machine</returns>
public ChildStateMachine<TStateData> CreateChildStateMachine(string name)
public ChildStateMachine<TStateData> CreateChildStateMachine()
{
this.ChildStateMachine = new ChildStateMachine<TStateData>(name, this.ParentStateMachine.InnerStateMachine.Kernel, this);
this.ChildStateMachine = new ChildStateMachine<TStateData>(this.Name, this.ParentStateMachine.InnerStateMachine.Kernel, this);
this.innerState.ChildStateMachine = this.ChildStateMachine;
return this.ChildStateMachine;
}
Expand Down
16 changes: 8 additions & 8 deletions src/StateMechanicUnitTests/AssertionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void ThrowsIfParentStateUsedInChildStateMachine()
{
var sm = new StateMachine("State Machine");
var state = sm.CreateInitialState("Initial State");
var subSm = state.CreateChildStateMachine("Child SM");
var subSm = state.CreateChildStateMachine();
var subState = subSm.CreateInitialState("Child Initial State");
var evt = sm.CreateEvent("Event");

Expand All @@ -30,7 +30,7 @@ public void ThrowsIfChildStateUsedInParentStateMachine()
{
var sm = new StateMachine("State Machine");
var state = sm.CreateInitialState("Initial State");
var subSm = state.CreateChildStateMachine("Child SM");
var subSm = state.CreateChildStateMachine();
var subState = subSm.CreateInitialState("Child Initial State");
var evt = sm.CreateEvent("Event");

Expand All @@ -44,7 +44,7 @@ public void ThrowsIfChildEventUsedInParentStateMachine()
{
var sm = new StateMachine("State Machine");
var state = sm.CreateInitialState("Initial State");
var subSm = state.CreateChildStateMachine("Child SM");
var subSm = state.CreateChildStateMachine();
var evt = subSm.CreateEvent("Event");

var e = Assert.Throws<InvalidEventTransitionException>(() => state.TransitionOn(evt).To(state));
Expand All @@ -57,7 +57,7 @@ public void DoesNotThrowIfParentEventUsedInChildStateMachine()
{
var sm = new StateMachine("State Machine");
var state = sm.CreateInitialState("Initial State");
var subSm = state.CreateChildStateMachine("Child SM");
var subSm = state.CreateChildStateMachine();
var subState = subSm.CreateInitialState("Child Initial State");
var evt = sm.CreateEvent("Event");

Expand All @@ -70,7 +70,7 @@ public void ThrowsIfForcedTransitionToAStateBelongingToAChildStateMachine()
var sm = new StateMachine("State Machine");
var evt = sm.CreateEvent("Event");
var state = sm.CreateInitialState("Initial State");
var subSm = state.CreateChildStateMachine("Child SM");
var subSm = state.CreateChildStateMachine();
var subState = subSm.CreateInitialState("Child Initial State");

Assert.Throws<InvalidStateTransitionException>(() => sm.ForceTransition(subState, evt));
Expand All @@ -82,7 +82,7 @@ public void ThrowsIfForcedTransitionOnAChildEvent()
var sm = new StateMachine("State Machine");
var state1 = sm.CreateInitialState("Initial State");
var state2 = sm.CreateState("State 2");
var subSm = state1.CreateChildStateMachine("Child SM");
var subSm = state1.CreateChildStateMachine();
var evt = subSm.CreateEvent("Event");

Assert.Throws<InvalidEventTransitionException>(() => sm.ForceTransition(state2, evt));
Expand All @@ -94,7 +94,7 @@ public void DoesNotThrowIfForcedTransitionOnAParentEvent()
var sm = new StateMachine("State Machine");
var evt = sm.CreateEvent("Event");
var state = sm.CreateInitialState("Initial State");
var subSm = state.CreateChildStateMachine("Child SM");
var subSm = state.CreateChildStateMachine();
var subState1 = subSm.CreateInitialState("Child Initial State");
var subState2 = subSm.CreateState("Sub State 2");

Expand All @@ -107,7 +107,7 @@ public void ThrowsIfEventFiredOnStateMachineThatIsNotActive()
var sm = new StateMachine("State Machine");
var state1 = sm.CreateInitialState("Initial State");
var state2 = sm.CreateState("State 2");
var subSm = state2.CreateChildStateMachine("Child SM");
var subSm = state2.CreateChildStateMachine();
var evt = subSm.CreateEvent("Event");
var subState1 = subSm.CreateInitialState("Child Initial State");
subState1.InnerSelfTransitionOn(evt);
Expand Down
2 changes: 1 addition & 1 deletion src/StateMechanicUnitTests/FaultTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public void StateMachineThrowsFaultExceptionWhenAccessingCurrentStateOnceFaulted
[Test]
public void FaultingChildStateMachineFaultsParent()
{
var childStateMachine = this.state1.CreateChildStateMachine("Child State Machine");
var childStateMachine = this.state1.CreateChildStateMachine();

var subState1 = childStateMachine.CreateInitialState("State 1.1");
var subState2 = childStateMachine.CreateState("State 1.2");
Expand Down
8 changes: 4 additions & 4 deletions src/StateMechanicUnitTests/HandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public void TransitioningToChildStateMachineCallsEntryHandlerOnInitialState()
var evt = sm.CreateEvent("Event");
var state1 = sm.CreateInitialState("State 1");
var state2 = sm.CreateState("State 2");
var subSm = state2.CreateChildStateMachine("Child State Machine");
var subSm = state2.CreateChildStateMachine();
var state21 = subSm.CreateInitialState("State 2.1").WithEntry(i => state21EntryInfo = i);
state1.TransitionOn(evt).To(state2);

Expand All @@ -201,7 +201,7 @@ public void TransitioningFromChildStateMachineCallsExitHandlerOnCurrentState()
var evt2 = sm.CreateEvent("Event 2");
var state1 = sm.CreateInitialState("State 1");
var state2 = sm.CreateState("State 2");
var subSm = state2.CreateChildStateMachine("Child State Machine");
var subSm = state2.CreateChildStateMachine();
var state21 = subSm.CreateInitialState("State 2.1");
var state22 = subSm.CreateState("State 2.2").WithExit(i => state22ExitInfo = i);

Expand Down Expand Up @@ -231,7 +231,7 @@ public void ForcefullyTransitioningToChildStateMachineCallsEntryHandlerOnInitial
var evt = sm.CreateEvent("Event");
var state1 = sm.CreateInitialState("State 1");
var state2 = sm.CreateState("State 2");
var subSm = state2.CreateChildStateMachine("Child State Machine");
var subSm = state2.CreateChildStateMachine();
var state21 = subSm.CreateInitialState("State 2.1").WithEntry(i => state21EntryInfo = i);

sm.ForceTransition(state2, evt);
Expand All @@ -251,7 +251,7 @@ public void ForcefullyTransitioningFromChildStateMachineCallsExitHandlerOnCurren
var evt1 = sm.CreateEvent("Event 1");
var state1 = sm.CreateInitialState("State 1");
var state2 = sm.CreateState("State 2");
var subSm = state2.CreateChildStateMachine("Child State Machine");
var subSm = state2.CreateChildStateMachine();
var state21 = subSm.CreateInitialState("State 2.1");
var state22 = subSm.CreateState("State 2.2").WithExit(i => state22ExitInfo = i);

Expand Down
6 changes: 3 additions & 3 deletions src/StateMechanicUnitTests/IntrospectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public void StateMachineReportsCurrentStateCorrectly()
var state1 = stateMachine.CreateInitialState("State 1");
var state2 = stateMachine.CreateState("State 2");
var evt = stateMachine.CreateEvent("Event");
var subSm = state2.CreateChildStateMachine("Sub State Machine");
var subSm = state2.CreateChildStateMachine();
var state21 = subSm.CreateInitialState("State 2.1");

state1.TransitionOn(evt).To(state2);
Expand All @@ -171,7 +171,7 @@ public void StateMachineReportsRecursiveCurrentStateCorrectly()
var state1 = stateMachine.CreateInitialState("State 1");
var state2 = stateMachine.CreateState("State 2");
var evt = stateMachine.CreateEvent("Event");
var subSm = state2.CreateChildStateMachine("Sub State Machine");
var subSm = state2.CreateChildStateMachine();
var state21 = subSm.CreateInitialState("State 2.1");
var state22 = subSm.CreateState("State 2.2");

Expand All @@ -196,7 +196,7 @@ public void StateReportsIsCurrentCorrectly()
var state1 = stateMachine.CreateInitialState("State 1");
var state2 = stateMachine.CreateState("State ");
var evt = stateMachine.CreateEvent("Event");
var subSm = state2.CreateChildStateMachine("Sub State Machine");
var subSm = state2.CreateChildStateMachine();
var state21 = subSm.CreateInitialState("State 2.1");
var state22 = subSm.CreateState("State 2.2");

Expand Down
2 changes: 1 addition & 1 deletion src/StateMechanicUnitTests/ResetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void ResetResetsStateOfChildStateMachines()
var parent = new StateMachine("parent");
var initialState = parent.CreateInitialState("initialState");
var state1 = parent.CreateState("state1");
var child = state1.CreateChildStateMachine("child");
var child = state1.CreateChildStateMachine();
var substate1 = child.CreateInitialState("substate1");
var substate2 = child.CreateState("substate2");

Expand Down
2 changes: 1 addition & 1 deletion src/StateMechanicUnitTests/StateGroupTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void IsCurrentIncludesChildStateMachines()
{
var sm = new StateMachine("State Machine");
var state1 = sm.CreateInitialState("State 1");
var subSm = state1.CreateChildStateMachine("Child State Machine");
var subSm = state1.CreateChildStateMachine();
var state11 = subSm.CreateInitialState("State 1.1");
var state12 = subSm.CreateState("State 1.2");

Expand Down
6 changes: 3 additions & 3 deletions src/StateMechanicUnitTests/StateMachineStateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void CurrentChildStateReflectsCurrentStateOfChild()
var sm = new StateMachine("state machine");
var initialState = sm.CreateInitialState("initial state");
var state1 = sm.CreateState("state1");
var childSm = state1.CreateChildStateMachine("childsm");
var childSm = state1.CreateChildStateMachine();
var childInitialState = childSm.CreateInitialState("childInitialState");
var childState1 = childSm.CreateState("childState1");

Expand Down Expand Up @@ -75,7 +75,7 @@ public void ChildStateMachineStartsInInitialStateIfParentStateIsInitialState()
{
var parent = new StateMachine("parent");
var initial = parent.CreateInitialState("initial");
var child = initial.CreateChildStateMachine("child");
var child = initial.CreateChildStateMachine();
var childInitial = child.CreateInitialState("childInitial");

Assert.AreEqual(childInitial, child.CurrentState);
Expand All @@ -88,7 +88,7 @@ public void ChildStateMachineStartsInNoStateIfParentStateIsNotInitialState()
var parent = new StateMachine("parent");
var initial = parent.CreateInitialState("initial");
var state1 = parent.CreateState("state1");
var child = state1.CreateChildStateMachine("child");
var child = state1.CreateChildStateMachine();
var childInitial = child.CreateInitialState("childInitial");

Assert.AreEqual(null, child.CurrentState);
Expand Down
6 changes: 3 additions & 3 deletions src/StateMechanicUnitTests/TransitionNotificationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void TransitionRaisedWhenTransitionOnChild()
{
var sm = new StateMachine("sm");
var initial = sm.CreateInitialState("initial");
var child = initial.CreateChildStateMachine("child");
var child = initial.CreateChildStateMachine();
var childInitial = child.CreateInitialState("childInitial");
var childState1 = child.CreateState("childState1");
var evt = sm.CreateEvent("evt");
Expand All @@ -91,7 +91,7 @@ public void TransitionRaisedWhenInnerSelfTransitionOnChild()
{
var sm = new StateMachine("sm");
var initial = sm.CreateInitialState("initial");
var child = initial.CreateChildStateMachine("child");
var child = initial.CreateChildStateMachine();
var childInitial = child.CreateInitialState("childInitial");
var evt = sm.CreateEvent("evt");
childInitial.InnerSelfTransitionOn(evt);
Expand Down Expand Up @@ -137,7 +137,7 @@ public void TransitionNotFoundRaisedWhenTransitionNotFoundOnChild()
{
var sm = new StateMachine("sm");
var initial = sm.CreateInitialState("initial");
var child = initial.CreateChildStateMachine("child");
var child = initial.CreateChildStateMachine();
var childInitial = child.CreateInitialState("childInitial");
var evt = child.CreateEvent("evt");

Expand Down
2 changes: 1 addition & 1 deletion src/StateMechanicUnitTests/TransitionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void ParentDoesNotTransitionIfChildTransitions()
var initial = sm.CreateInitialState("initial");
var state1 = sm.CreateState("state1");

var child = initial.CreateChildStateMachine("child");
var child = initial.CreateChildStateMachine();
var childInitial = child.CreateInitialState("childInitial");
var childState1 = child.CreateState("childState1");

Expand Down

0 comments on commit 64b7a44

Please sign in to comment.