using System; using NUnit.Framework; namespace Chernobyl { // ReSharper disable ObjectCreationAsStatement [TestFixture, Description("Tests for the ActionCombiner type.")] public class ActionCombinerT1T2Tests { [Test, Description("Ensures the constructor throws an ArgumentNullException " + "when it is passed a null argument")] public void ConstructorArgumentNullException() { Assert.Throws(() => new ActionCombiner(null)); } [Test, Description("Ensures the main action method passed to the " + "ActionCombiner is invoked at the proper time with the " + "correct arguments.")] public void ActionInvokedWithProperArguments() { Tester tester = new Tester(); ActionCombiner actionCombiner = new ActionCombiner(tester.Action); actionCombiner.Second(2); tester.MainActionInvocationImminent = true; actionCombiner.First(1); } /// /// A utility type used to help test . /// class Tester { public bool MainActionInvocationImminent; public void Action(int x, int y) { Assert.True(MainActionInvocationImminent, "The main action method " + "was invoked at the incorrect time."); Assert.AreEqual(1, x, "First argument is not correct."); Assert.AreEqual(2, y, "Second argument is not correct."); } } } [TestFixture, Description("Tests for the ActionCombiner type.")] public class ActionCombinerT1T2T3Tests { [Test, Description("Ensures the constructor throws an ArgumentNullException " + "when it is passed a null argument")] public void ConstructorArgumentNullException() { Assert.Throws(() => new ActionCombiner(null)); } [Test, Description("Ensures the main action method passed to the " + "ActionCombiner is invoked at the proper time with the " + "correct arguments.")] public void ActionInvokedWithProperArguments() { Tester tester = new Tester(); ActionCombiner actionCombiner = new ActionCombiner(tester.Action); actionCombiner.Third(3); actionCombiner.First(1); tester.MainActionInvocationImminent = true; actionCombiner.Second(2); } /// /// A utility type used to help test . /// class Tester { public bool MainActionInvocationImminent; public void Action(int x, int y, int z) { Assert.True(MainActionInvocationImminent, "The main action method " + "was invoked at the incorrect time."); Assert.AreEqual(1, x, "First argument is not correct."); Assert.AreEqual(2, y, "Second argument is not correct."); Assert.AreEqual(3, z, "Third argument is not correct."); } } } // ReSharper restore ObjectCreationAsStatement }