Skip to content

Commit

Permalink
Fixed #34, conditional activiites not being properly bound.
Browse files Browse the repository at this point in the history
  • Loading branch information
phatboyg committed Nov 20, 2017
1 parent 8e4d03b commit ad72495
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
8 changes: 5 additions & 3 deletions src/Automatonymous.Tests/Condition_Specs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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!"))));

Expand Down Expand Up @@ -104,6 +104,8 @@ class Start
}


class StartedExplicitFilter {}
class StartedExplicitFilter
{
}
}
}
26 changes: 20 additions & 6 deletions src/Automatonymous/Binders/ConditionalActivityBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public ConditionalActivityBinder(Event @event, StateMachineCondition<TInstance>
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<TInstance> state)
Expand All @@ -53,13 +53,20 @@ public void Bind(State<TInstance> state)

public void Bind(BehaviorBuilder<TInstance> builder)
{
var stateBuilder = new ActivityBehaviorBuilder<TInstance>();

foreach (var activity in _activities.GetStateActivityBinders())
{
activity.Bind(builder);
activity.Bind(stateBuilder);
}

var conditionActivity = new ConditionActivity<TInstance>(_condition, stateBuilder.Behavior);

builder.Add(conditionActivity);
}
}


public class ConditionalActivityBinder<TInstance, TData> :
ActivityBinder<TInstance>
where TInstance : class
Expand All @@ -68,7 +75,8 @@ public class ConditionalActivityBinder<TInstance, TData> :
readonly StateMachineCondition<TInstance, TData> _condition;
readonly Event _event;

public ConditionalActivityBinder(Event @event, StateMachineCondition<TInstance, TData> condition, EventActivities<TInstance> activities)
public ConditionalActivityBinder(Event @event, StateMachineCondition<TInstance, TData> condition,
EventActivities<TInstance> activities)
{
_activities = activities;
_condition = condition;
Expand All @@ -78,7 +86,7 @@ public ConditionalActivityBinder(Event @event, StateMachineCondition<TInstance,
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<TInstance> state)
Expand All @@ -90,17 +98,23 @@ public void Bind(State<TInstance> state)
activity.Bind(builder);
}

var conditionActivity = new ConditionActivity<TInstance,TData>(_condition, builder.Behavior);
var conditionActivity = new ConditionActivity<TInstance, TData>(_condition, builder.Behavior);

state.Bind(_event, conditionActivity);
}

public void Bind(BehaviorBuilder<TInstance> builder)
{
var stateBuilder = new ActivityBehaviorBuilder<TInstance>();

foreach (var activity in _activities.GetStateActivityBinders())
{
activity.Bind(builder);
activity.Bind(stateBuilder);
}

var conditionActivity = new ConditionActivity<TInstance, TData>(_condition, stateBuilder.Behavior);

builder.Add(conditionActivity);
}
}
}

0 comments on commit ad72495

Please sign in to comment.