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")); }
public void GetNewState_WhenTriggeringEventIsNull_Throws() { var sut = new StateMachine(GetTestTransitionTable()); Assert.Throws<ArgumentNullException>( () => sut.GetNewState("Locked", null)); }
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)); }
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); }
public void GetNewState_WhenInvalidEvent_Throws() { var sut = new StateMachine(GetTestTransitionTable()); Assert.Throws<InvalidOperationException>( () => sut.GetNewState("Locked", "bogus")); }
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); }
public void GetNewState_WhenCurrentStateIsNull_Throws() { var sut = new StateMachine(GetTestTransitionTable()); Assert.Throws<ArgumentNullException>( () => sut.GetNewState(null, "coin")); }