using System; using NUnit.Framework; namespace Chernobyl.Switch { [TestFixture, Description("A set of tests which test the CountdownSwitch class.")] public class CountdownSwitchTests : SwitchTests { [Test, Description("A test that ensures an ArgumentException is properly " + "thrown a zero count is given to the constructor of a CountdownSwitch")] public void ConstructionArgumentExceptionTest() { // ReSharper disable ObjectCreationAsStatement Assert.Throws(() => new CountdownSwitch(0)); // ReSharper restore ObjectCreationAsStatement } [Test, Description("A test that ensures the count given to the " + "CountdownSwitch is what gets set on the CountdownSwitch.Count " + "property and the CountdownSwitch.StartingCount property.")] public void ConstructionCountTest() { const uint expectedCount = 3; CountdownSwitch testSwitch = new CountdownSwitch(expectedCount); Assert.AreEqual(expectedCount, testSwitch.Count, "Count is not set to the appropriate value."); Assert.AreEqual(expectedCount, testSwitch.StartingCount, "StartingCount is not set to the appropriate value."); } [Test, Description("A test that ensures the count is properly reduced " + "by one if the Countdown(object, EventArgs) method is invoked.")] public void CountReductionTest() { const uint expectedCount = 3; CountdownSwitch testSwitch = new CountdownSwitch(expectedCount); testSwitch.Countdown(this, EventArgs.Empty); Assert.AreEqual(expectedCount - 1, testSwitch.Count, "Count is not set to the appropriate value."); } [Test, Description("A test that ensures the count given to the " + "CountdownSwitch is still the value of the StartingCount after " + "Countdown(object, EventArgs) method is invoked.")] public void StartingCountTest() { const uint expectedCount = 3; CountdownSwitch testSwitch = new CountdownSwitch(3); testSwitch.Countdown(this, EventArgs.Empty); Assert.AreEqual(expectedCount, testSwitch.StartingCount, "StartingCount is not set to the appropriate value."); } protected override CountdownSwitch CreateSwitch() { return new CountdownSwitch(3); } protected override void FireSwitchedOnEvent(CountdownSwitch testSwitch) { while(testSwitch.Count != 0) testSwitch.Countdown(this, EventArgs.Empty); } protected override void FireSwitchedOffEvent(CountdownSwitch testSwitch) { testSwitch.Reset(); } } }