From ad72495348dbd6dfe1c5dd38beb062fecc9f4916 Mon Sep 17 00:00:00 2001 From: Chris Patterson Date: Mon, 20 Nov 2017 10:53:02 -0600 Subject: [PATCH] Fixed #34, conditional activiites not being properly bound. --- src/Automatonymous.Tests/Condition_Specs.cs | 8 +++--- .../Binders/ConditionalActivityBinder.cs | 26 ++++++++++++++----- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/Automatonymous.Tests/Condition_Specs.cs b/src/Automatonymous.Tests/Condition_Specs.cs index 0b10df6..f4470ee 100644 --- a/src/Automatonymous.Tests/Condition_Specs.cs +++ b/src/Automatonymous.Tests/Condition_Specs.cs @@ -75,8 +75,8 @@ public InstanceStateMachine() During(Initial, When(ExplicitFilterStarted, context => true) - .If(context => false, binder => - binder.Then(context => Console.WriteLine("Should not be here!")) + .If(context => false, binder => binder + .Then(context => Console.WriteLine("Should not be here!")) .TransitionTo(ShouldNotBeHere)) .If(context => true, binder => binder.Then(context => Console.WriteLine("Initializing Only!")))); @@ -104,6 +104,8 @@ class Start } - class StartedExplicitFilter {} + class StartedExplicitFilter + { + } } } \ No newline at end of file diff --git a/src/Automatonymous/Binders/ConditionalActivityBinder.cs b/src/Automatonymous/Binders/ConditionalActivityBinder.cs index 62f113d..29e458b 100644 --- a/src/Automatonymous/Binders/ConditionalActivityBinder.cs +++ b/src/Automatonymous/Binders/ConditionalActivityBinder.cs @@ -34,7 +34,7 @@ public ConditionalActivityBinder(Event @event, StateMachineCondition public bool IsStateTransitionEvent(State state) { return Equals(_event, state.Enter) || Equals(_event, state.BeforeEnter) - || Equals(_event, state.AfterLeave) || Equals(_event, state.Leave); + || Equals(_event, state.AfterLeave) || Equals(_event, state.Leave); } public void Bind(State state) @@ -53,13 +53,20 @@ public void Bind(State state) public void Bind(BehaviorBuilder builder) { + var stateBuilder = new ActivityBehaviorBuilder(); + foreach (var activity in _activities.GetStateActivityBinders()) { - activity.Bind(builder); + activity.Bind(stateBuilder); } + + var conditionActivity = new ConditionActivity(_condition, stateBuilder.Behavior); + + builder.Add(conditionActivity); } } + public class ConditionalActivityBinder : ActivityBinder where TInstance : class @@ -68,7 +75,8 @@ public class ConditionalActivityBinder : readonly StateMachineCondition _condition; readonly Event _event; - public ConditionalActivityBinder(Event @event, StateMachineCondition condition, EventActivities activities) + public ConditionalActivityBinder(Event @event, StateMachineCondition condition, + EventActivities activities) { _activities = activities; _condition = condition; @@ -78,7 +86,7 @@ public ConditionalActivityBinder(Event @event, StateMachineCondition state) @@ -90,17 +98,23 @@ public void Bind(State state) activity.Bind(builder); } - var conditionActivity = new ConditionActivity(_condition, builder.Behavior); + var conditionActivity = new ConditionActivity(_condition, builder.Behavior); state.Bind(_event, conditionActivity); } public void Bind(BehaviorBuilder builder) { + var stateBuilder = new ActivityBehaviorBuilder(); + foreach (var activity in _activities.GetStateActivityBinders()) { - activity.Bind(builder); + activity.Bind(stateBuilder); } + + var conditionActivity = new ConditionActivity(_condition, stateBuilder.Behavior); + + builder.Add(conditionActivity); } } } \ No newline at end of file