コード例 #1
0
        public void Constructor_WhenCalled_CopiesTransitionTable()
        {
            var transitionTable =
                new List<Transition>
                    {
                        new Transition("Locked", "coin", "Unlocked")
                    };

            var sut = new StateMachine(transitionTable);

            transitionTable.Add(new Transition("Unlocked", "pass", "Locked"));

            Assert.Throws<InvalidOperationException>(
                () => sut.GetNewState("Unlocked", "pass"));
        }
コード例 #2
0
        public void GetNewState_WhenTriggeringEventIsNull_Throws()
        {
            var sut = new StateMachine(GetTestTransitionTable());

            Assert.Throws<ArgumentNullException>(
                () => sut.GetNewState("Locked", null));
        }
コード例 #3
0
        public void GetNewState_WhenTerminalCurrentState_Throws()
        {
            const string TerminalState = "Terminal";
            const string TriggeringEvent = "ev";

            var transitionTable =
                new List<Transition>
                    {
                        new Transition("Whatever", TriggeringEvent, TerminalState)
                    };

            var sut = new StateMachine(transitionTable);

            Assert.Throws<InvalidOperationException>(
                () => sut.GetNewState(TerminalState, TriggeringEvent));
        }
コード例 #4
0
        public void GetNewState_WhenValidArguments_ReturnsNewState(
            string currentState, string triggeringEvent, string expectedNewState)
        {
            var sut = new StateMachine(GetTestTransitionTable());

            string result = sut.GetNewState(currentState, triggeringEvent);

            Assert.Equal(expectedNewState, result);
        }
コード例 #5
0
        public void GetNewState_WhenInvalidEvent_Throws()
        {
            var sut = new StateMachine(GetTestTransitionTable());

            Assert.Throws<InvalidOperationException>(
                () => sut.GetNewState("Locked", "bogus"));
        }
コード例 #6
0
        public void GetNewState_WhenInvalidCurrentState_Throws()
        {
            var sut = new StateMachine(GetTestTransitionTable());

            var ex = Assert.Throws<InvalidOperationException>(
                () => sut.GetNewState("Bogus", "coin"));

            Assert.Equal("Invalid state transition: state 'Bogus', event 'coin'.", ex.Message);
        }
コード例 #7
0
        public void GetNewState_WhenCurrentStateIsNull_Throws()
        {
            var sut = new StateMachine(GetTestTransitionTable());

            Assert.Throws<ArgumentNullException>(
                () => sut.GetNewState(null, "coin"));
        }