public State AddState(Action<State> initializer) { var state = new State { Id = _states.Count + 1 }; _states.Add(state); if (initializer != null) initializer(state); return state; }
private CreatePathExpression State(State state) { if (_selectingTo) { _to = state; _createdPath = _machine.CreatePath(_from, _to); return this; } else { _from = state; return this; } }
protected override void Because() { _state = sut.AddState(s => s.Name = _name); sut.Start(); }
public Context(StateMachine stateMachine, State associatedState) { AssociatedState = associatedState; _stateMachine = stateMachine; }
public void AddDestination(State destination) { destinations.Add(destination); }
public Path(State fromState) { FromState = fromState; }
public ContextStub(StateMachine stateMachine, State associatedState) : base(stateMachine, associatedState) { }
public UseSwordContext(StateMachine stateMachine, State associatedState) : base(stateMachine, associatedState) { }
public UseBareHandsContext(StateMachine stateMachine, State associatedState) : base(stateMachine, associatedState) { }
public SamuraiContext(StateMachine stateMachine, State associatedState) : base(stateMachine, associatedState) { }
public Path CreatePath(State from, State to) { if (from == to) throw new ArgumentException("Can't add a path between two equal states"); Path path = _paths.SingleOrDefault(p => p.FromState == from); if (path == null) { path = new Path(from); _paths.Add(path); } if (path.Destinations.Any(d => d == to)) throw new ArgumentException(string.Format("There is already a destination {0} for state {1}", to.Id, from.Id)); path.AddDestination(to); return path; }
private void SetCurrentState(State state) { CurrentState = state; }