using NUnit.Framework; namespace Chernobyl.StateMachine { public class StateExtensionsTests { [Test, Description("A test to ensure that StateExtensions.IsActive(IState) " + "returns true when an IState is active and false when it is inactive.")] public void IsActiveTest() { IState state = new State(); Assert.False(state.IsActive(), "The IState.IsActive(IState) should " + "return false as the IState is inactive."); state.ParentState = new State(); Assert.True(state.IsActive(), "The IState.IsActive(IState) should " + "return true as the IState is active."); } [Test, Description("A test to ensure that " + "StateExtensions.CheckedLeftAdd(IState, EventHandler) invokes " + "the EventHandler passed to it if the IState is active.")] public void CheckedEnteredAddInvokeWhenActive() { IState state = new State(); state.ParentState = new State(); state.CheckedEnteredAdd((sender, e) => Assert.Pass()); } [Test, Description("A test to ensure that " + "StateExtensions.CheckedLeftAdd(IState, EventHandler) does not invoke " + "the EventHandler passed to it if the IState is active.")] public void CheckedEnteredAddDoesNotInvokeWhenInactive() { IState state = new State(); state.CheckedEnteredAdd((sender, e) => Assert.Fail("The event handler " + "should not have been invoked.")); } [Test, Description("A test to ensure that " + "StateExtensions.CheckedLeftAdd(IState, EventHandler) does not invoke " + "the EventHandler passed to it if the IState is active.")] public void CheckedLeftAddDoesNotInvokeWhenActive() { IState state = new State(); state.ParentState = new State(); state.CheckedLeftAdd((sender, e) => Assert.Fail("The event handler " + "should not have been invoked.")); } [Test, Description("A test to ensure that " + "StateExtensions.CheckedLeftAdd(IState, EventHandler) invokes " + "the EventHandler passed to it if the IState is inactive.")] public void CheckedLeftAddInvokeWhenInactive() { IState state = new State(); state.CheckedLeftAdd((sender, e) => Assert.Pass()); } [Test, Description("A test to ensure the StateExtensions.EnterWith(IState, IState) " + "method properly makes a one state the child of another when the " + "parent's IState.Entered event is raised.")] public void EnterWithTest() { IState grandParent = new State(); IState parent = new State(); IState child = new State(); parent.EnterWith(child); Assert.AreEqual(null, child.ParentState, "The IState.ParentState of " + "the child was set before the parent state was activated."); parent.ParentState = grandParent; Assert.AreEqual(parent, child.ParentState, "The IState.ParentState of " + "the child was not set after the parent state was activated."); } } }