Exemplo n.º 1
0
        public void BuildTest()
        {
            var builder = new CodeStateMachineBuilder <TestStates, TestActions>();

            builder
            .StartWith(TestStates.Default)
            .Move(TestStates.Default, TestActions.Save, TestStates.Draft)
            .Move(TestStates.Draft, TestActions.Check, TestStates.Checked)
            .Move(TestStates.Draft, TestActions.Delete, TestStates.Deleted)
            .Move(TestStates.Checked, TestActions.Check, TestStates.DoubleChecked)
            .Move(TestStates.Checked, TestActions.Recall, TestStates.Recalled)
            .Move(TestStates.DoubleChecked, TestActions.Recall, TestStates.Recalled)
            ;
            var        machine = builder.Build();
            TestStates ts      = TestStates.Default;

            machine.Pushed += (sender, e) =>
            {
                ts = e.NewState;
            };
            machine.Push(TestActions.Save);
            Assert.AreEqual(TestStates.Draft, ts);
            machine.Push(TestActions.Check);
            Assert.AreEqual(TestStates.Checked, ts);
            machine.Push(TestActions.Check);
            Assert.AreEqual(TestStates.DoubleChecked, ts);
        }
    public void TestLastStatePropBeforeChange()
    {
        var fsm = new StateMachine <TestStates, StateDriverUnity>(behaviour);

        Assert.Throws <NullReferenceException>(() =>
        {
            TestStates state = fsm.LastState;
        });
        Assert.IsFalse(fsm.LastStateExists);


        fsm.ChangeState(TestStates.StateInit);

        //Conflicted about this. Prefer to return default values, or the current state
        //but that would undermine correctness
        Assert.Throws <NullReferenceException>(() =>
        {
            TestStates state = fsm.LastState;
        });
        Assert.IsFalse(fsm.LastStateExists);

        fsm.ChangeState(TestStates.StatePlay);

        Assert.AreEqual(TestStates.StateInit, fsm.LastState);
        Assert.IsTrue(fsm.LastStateExists);
    }
Exemplo n.º 3
0
 private void Reset()
 {
     _curPart = -1;
     state = TestStates.Ready;
     wrongWords = new List<Word>();
     selectedWords = getTestWords(_dictionary);
 }
Exemplo n.º 4
0
        public void TestGetStates(int i, string expected)
        {
            TestStates   myTestRepo  = new TestStates();
            List <State> result      = myTestRepo.GetStates();
            string       stateAbbrev = result[i].StateAbbreviation;

            Assert.AreEqual(expected, stateAbbrev);
        }
Exemplo n.º 5
0
        public void TestStateComponentInitialisation()
        {
            StateComponent <TestStates> actual = new StateComponent <TestStates>(TestStates.s1);

            TestStates expected = TestStates.s1;

            Assert.AreEqual(expected, actual.Peek(),
                            "Test that the initialising state is the one passed in the constructor");
        }
Exemplo n.º 6
0
 public JsUnitTest(IWebBrowser browser, string inputJs, string evaluateJs, string expectedJavaScriptResult)
 {
     _browser   = browser;
     InputJs    = inputJs;
     EvaluateJs = evaluateJs;
     ExpectedJavaScriptResult = expectedJavaScriptResult;
     InputState = TestStates.NotRunning;
     CheckState = TestStates.NotRunning;
 }
Exemplo n.º 7
0
        public void TestStateSwitch()
        {
            StateComponent <TestStates> actual = new StateComponent <TestStates>(TestStates.s1);

            actual.Switch(TestStates.s3);

            TestStates expected = TestStates.s3;

            Assert.AreEqual(expected, actual.Peek(),
                            "Test that the state has changed once the stateis asked to switch");
        }
Exemplo n.º 8
0
        public void TestStateComponentPush()
        {
            StateComponent <TestStates> actual = new StateComponent <TestStates>(TestStates.s1);

            actual.Push(TestStates.s2);

            TestStates expected = TestStates.s2;

            Assert.AreEqual(expected, actual.Peek(),
                            "Test that the peeked state after a push is the topmost state");
        }
Exemplo n.º 9
0
        public void TestStateComponentPop()
        {
            StateComponent <TestStates> actual = new StateComponent <TestStates>(TestStates.s1);

            actual.Push(TestStates.s2);
            actual.Pop();

            TestStates expected = TestStates.s1;

            Assert.AreEqual(expected, actual.Peek(),
                            "Test that the peeked state is the same after a push and pop");
        }
    public void TestStatePropBeforeChange()
    {
        var fsm = new StateMachine <TestStates, StateDriverUnity>(behaviour);

        Assert.Throws <NullReferenceException>(() =>
        {
            TestStates state = fsm.State;
        });

        fsm.ChangeState(TestStates.StateInit);

        Assert.AreEqual(TestStates.StateInit, fsm.State);
    }
Exemplo n.º 11
0
        private TestStates getNextState(TestStates state)
        {
            switch (state)
            {
            case TestStates.State1:
                return(TestStates.State2);

            case TestStates.State2:
                return(TestStates.State3);

            case TestStates.State3:
                return(TestStates.State1);
            }

            return(TestStates.State1);
        }
Exemplo n.º 12
0
            public async Task RunTest()
            {
                InputState = TestStates.Running;
                var response = await _browser.EvaluateScriptAsync(InputJs);

                InputState    = response.Success ? TestStates.Passed : TestStates.Failed;
                InputJsResult = response.Result?.ToString() ?? "";
                if (InputState == TestStates.Failed)
                {
                    return;
                }
                var evalResponse = await _browser.EvaluateScriptAsync(EvaluateJs);

                ActualJavaScriptResult = evalResponse.Result?.ToString() ?? "";
                CheckState             = ActualJavaScriptResult == ExpectedJavaScriptResult ? TestStates.Passed : TestStates.Failed;
            }
Exemplo n.º 13
0
        public void PushAndCheckStateIsRightByEventOfPushed()
        {
            var builder = CsvStateMachineBuilder <TestStates, TestActions> .FromFile("./Resources/Doc.csv");

            var        machine = builder.Build();
            TestStates ts      = TestStates.Default;

            machine.Pushed += (sender, e) =>
            {
                ts = e.NewState;
            };
            machine.Push(TestActions.Save);
            Assert.AreEqual(TestStates.Draft, ts);
            machine.Push(TestActions.Check);
            Assert.AreEqual(TestStates.Checked, ts);
            machine.Push(TestActions.Check);
            Assert.AreEqual(TestStates.DoubleChecked, ts);
        }
        public void Convert_MatchingKeyExcludeFallback_ReturnsDictionaryValue(TestStates state, string expected)
        {
            var converted = Convert(state, null, new Tuple <IDictionary <TestStates, string>, string, bool>(_testStatedictionary, default(string), false), CultureInfo.CurrentUICulture);

            Assert.Equal(expected, converted);
        }
Exemplo n.º 15
0
		private void FSM_SwitchingFromStateTwoToStateThree (TestStates oldState, TestStates newState)
		{
			Debug.Log ("Switching from Two to Three");
		}
Exemplo n.º 16
0
		private void FSM_ExitStateTwo (TestStates nextState)
		{
			Debug.Log ("Exit State Two");
			switchCondition = false;
		}
Exemplo n.º 17
0
		private void FSM_EnterStateTwo (TestStates previousState)
		{
			Debug.Log ("Enter State Two");
		}
Exemplo n.º 18
0
		private void FSM_SwitchingFromStateOneToStateTwo (TestStates oldState, TestStates newState)
		{
			Debug.Log ("Switching from One to Two");
		}
Exemplo n.º 19
0
		private void FSM_EnterStateOne (TestStates previousState)
		{
			Debug.Log ("Enter State One");
		}
Exemplo n.º 20
0
        public void TestStripSpaces(string input, string expected)
        {
            string result = TestStates.StripSpaces(input);

            Assert.AreEqual(expected, result);
        }
Exemplo n.º 21
0
 private void changeState(TestStates state)
 {
     this.State = state;
 }
Exemplo n.º 22
0
 public void Cancel()
 {
     if (this.CurrentPart != null)
         this.CurrentPart.Cancel();
     this.State = TestStates.Cancelled;
 }