public void GoBack() { var sm = new SolidMachine <TelephoneTrigger>(); var isGoingToDialling = false; sm.State <IdleState>() .On(TelephoneTrigger.PickingUpPhone).GoesTo <DiallingState>(); sm.State <DiallingState>() .On(TelephoneTrigger.Answered, () => isGoingToDialling).GoesTo <ConversationState>() .On(TelephoneTrigger.Answered, () => !isGoingToDialling).GoesTo <WaitForAnswerState>(); sm.Start(); sm.Trigger(TelephoneTrigger.PickingUpPhone); sm.Trigger(TelephoneTrigger.Answered); Assert.IsTrue(sm.CurrentState is WaitForAnswerState, "Expected state WaitForAnswerState"); sm.GoBack(); Assert.IsTrue(sm.CurrentState is DiallingState, string.Format("Expected state DiallingState, was {0}", sm.CurrentState.GetType().Name)); // Shift the track isGoingToDialling = true; sm.Trigger(TelephoneTrigger.Answered); Assert.IsTrue(sm.CurrentState is ConversationState, "Expected state ConversationState"); sm.GoBack(); Assert.IsTrue(sm.CurrentState is DiallingState, "Expected state DiallingState... again"); }
/// <summary> /// The Back button has been clicked. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnBack_Click(object sender, EventArgs e) { _sm.GoBack(); }
public void GoBack() { var sm = new SolidMachine<TelephoneTrigger>(); var isGoingToDialling = false; sm.State<IdleState>() .On(TelephoneTrigger.PickingUpPhone).GoesTo<DiallingState>(); sm.State<DiallingState>() .On(TelephoneTrigger.Answered, () => isGoingToDialling).GoesTo<ConversationState>() .On(TelephoneTrigger.Answered, () => !isGoingToDialling).GoesTo<WaitForAnswerState>(); sm.Start(); sm.Trigger(TelephoneTrigger.PickingUpPhone); sm.Trigger(TelephoneTrigger.Answered); Assert.IsTrue(sm.CurrentState is WaitForAnswerState, "Expected state WaitForAnswerState"); sm.GoBack(); Assert.IsTrue(sm.CurrentState is DiallingState, string.Format("Expected state DiallingState, was {0}", sm.CurrentState.GetType().Name)); // Shift the track isGoingToDialling = true; sm.Trigger(TelephoneTrigger.Answered); Assert.IsTrue(sm.CurrentState is ConversationState, "Expected state ConversationState"); sm.GoBack(); Assert.IsTrue(sm.CurrentState is DiallingState, "Expected state DiallingState... again"); }