using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Windows.Forms; namespace Infrastructure.Tests { [TestClass] public class WhenChangingState : GivenWhenThen { public enum States { Display, Edit }; protected ControlStateMachine sut; protected Control owner; protected override void Arrange() { owner = new Control(); sut = new ControlStateMachine(owner); } protected override void Act() { sut.ChangeStateTo(States.Display); } [TestClass] public class GivenControlChangesAreAssociatedWithTheState : WhenChangingState { protected bool executedDisplay; protected bool executedEdit; protected override void Arrange() { base.Arrange(); executedDisplay = false; sut.WhenStateChangesTo(States.Display) .Do(() => executedDisplay = true); executedEdit = false; sut.WhenStateChangesTo(States.Edit) .Do(() => executedEdit = true); } [TestMethod] public void ShouldExecuteTheControlChangesThatAreAssociatedWithTheState() { Assert.IsTrue(executedDisplay); } [TestMethod] public void ShouldNotExecuteTheControlChangesThatAreAssociatedWithOtherState() { Assert.IsFalse(executedEdit); } } [TestClass] public class GivenNoControlChangesAreAssociatedWithTheState : WhenChangingState { [TestMethod] public void ShouldNotThrowAnException() { } } } }