Beispiel #1
0
        public void TestPerformTransitionToAnotherState()
        {
            // arrange
            var mockedContext = new Mock <TrackingContext>();
            var mockedState   = new Mock <StateBase>(FSMStateId.Idle);
            var mockedState2  = new Mock <StateBase>(FSMStateId.Recording);
            var fsm           = new GesturesFSM <TrackingContext>(mockedContext.Object);

            int stateChangedRaisedCount = 0;

            fsm.AddTransition(FSMStateId.Unknown, FSMEventId.Unknown, mockedState.Object);
            fsm.AddTransition(FSMStateId.Idle, FSMEventId.Record, mockedState2.Object);

            fsm.StateChanged += new StateChangedEventHandler((obj, args) => ++ stateChangedRaisedCount);
            mockedState.Setup(x => x.StateEntered(mockedContext.Object));
            mockedState.Setup(x => x.StateExited());
            mockedState2.Setup(x => x.StateEntered(mockedContext.Object));

            // act
            fsm.PerformTransition(FSMEventId.Unknown);
            fsm.PerformTransition(FSMEventId.Record);

            // assert
            Assert.AreEqual(2, stateChangedRaisedCount, "state changed event raised for all states");
            mockedState.VerifyAll();
            mockedState2.VerifyAll();
        }
Beispiel #2
0
        public void TestPerformTransitionToSameState()
        {
            // arrange
            var mockedContext = new Mock <TrackingContext>();
            var mockedState   = new Mock <StateBase>(FSMStateId.Idle);
            var fsm           = new GesturesFSM <TrackingContext>(mockedContext.Object);

            int stateEntranceCount      = 0;
            int stateChangedRaisedCount = 0;

            fsm.AddTransition(FSMStateId.Unknown, FSMEventId.Unknown, mockedState.Object);
            fsm.AddTransition(FSMStateId.Idle, FSMEventId.GoIdle, mockedState.Object);

            fsm.StateChanged += new StateChangedEventHandler((obj, args) => ++ stateChangedRaisedCount);
            mockedState.Setup(x => x.StateEntered(mockedContext.Object)).Callback(() => ++ stateEntranceCount);
            mockedState.Setup(x => x.StateExited()).Callback(() => Assert.Fail("Should not exit state"));

            // act
            fsm.PerformTransition(FSMEventId.Unknown);
            fsm.PerformTransition(FSMEventId.GoIdle);

            // assert
            Assert.AreEqual(1, stateEntranceCount, "state entered only once");
            Assert.AreEqual(1, stateChangedRaisedCount, "state changed event raised only once");
        }
Beispiel #3
0
        public void TestAddTransitionNotCalled()
        {
            // arrange
            var fsm = new GesturesFSM <TrackingContext>(new Mock <TrackingContext>().Object);

            // act
            fsm.PerformTransition(FSMEventId.Unknown);

            // assert
            Assert.Fail();
        }
Beispiel #4
0
 private void btnRecord_Click(object sender, RoutedEventArgs e)
 {
     if (cmbGestureId.SelectedIndex == -1)
     {
         this.AddMessage("Select a gesture id to be recorded");
     }
     else if (this.context.CurrentCue == null)
     {
         this.AddMessage("Raise one of your hands to select a gesture with it");
     }
     else
     {
         fsm.PerformTransition(FSMEventId.Record);
     }
 }
Beispiel #5
0
        public void TestAddTransition()
        {
            // arrange
            var mockedContext = new Mock <TrackingContext>();
            var mockedState   = new Mock <IState <TrackingContext> >();
            var fsm           = new GesturesFSM <TrackingContext>(mockedContext.Object);

            // act
            fsm.AddTransition(FSMStateId.Unknown, FSMEventId.Unknown, mockedState.Object);
            fsm.PerformTransition(FSMEventId.Unknown);

            // assert
            mockedState.VerifySet(x => x.Controller = fsm, "controller successfully set to state");

            Assert.IsTrue(object.ReferenceEquals(mockedState.Object, fsm.Current), "state successfully added");
        }