using System; using NUnit.Framework; namespace Chernobyl.Switch { /// /// A set of tests for testing types which implement the /// interface. /// public abstract class SwitchTests where TSwitch : ISwitch { [Test, Description("A test which ensures the ISwitch.SwitchedOn event " + "is properly fired.")] public void SwitchedOnTest() { TSwitch testSwitch = CreateSwitch(); testSwitch.SwitchedOn += (sender, e) => Assert.Pass(); FireSwitchedOnEvent(testSwitch); Assert.Fail("The ISwitch.SwitchedOn event did not get fired."); } [Test, Description("A test which ensures the ISwitch.SwitchedOff event " + "is properly fired.")] public void SwitchedOffTest() { TSwitch testSwitch = CreateSwitch(); testSwitch.SwitchedOff += (sender, e) => Assert.Pass(); FireSwitchedOffEvent(testSwitch); Assert.Fail("The ISwitch.SwitchedOff event did not get fired."); } [Test, Description("A test which ensures the Reset() method properly " + "handles the firing of ISwitch.SwitchedOff event.")] public void ResetTest() { TSwitch testSwitch = CreateSwitch(); testSwitch.SwitchedOff += (sender, e) => Assert.Pass(); testSwitch.Reset(); Assert.Fail("The ISwitch.SwitchedOff event did not get fired."); } [Test, Description("A test which ensures the reset(object, EventArgs) " + "method properly handles firing of ISwitch.SwitchedOff event.")] public void ResetEventHandlerTest() { TSwitch testSwitch = CreateSwitch(); testSwitch.SwitchedOff += (sender, e) => Assert.Pass(); testSwitch.Reset(this, EventArgs.Empty); Assert.Fail("The ISwitch.SwitchedOff event did not get fired."); } /// /// Creates the that should be tested. This method /// should always return a new and never reuse /// instances. /// /// The new to test. protected abstract TSwitch CreateSwitch(); /// /// Fires the event on the /// passed in. This method should fire the event /// through normally means that would occur in a client application. /// /// The whose /// should be fired. protected abstract void FireSwitchedOnEvent(TSwitch testSwitch); /// /// Fires the event on the /// passed in. This method should fire the event /// through normally means that would occur in a client application. /// /// The whose /// should be fired. protected abstract void FireSwitchedOffEvent(TSwitch testSwitch); } }