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