using System; using System.Reflection; using Chernobyl.Creation; using NUnit.Framework; namespace Chernobyl.Event { [TestFixture, Description("Tests for the CreationEventArgs type.")] public class CreationEventArgsTest { [Test, Description("Test to ensure " + "CreationEventArgs.CreationEventArgs(TCreated) " + "constructor sets the CreationEventArgs.CreatedInstance " + "to a proper value.")] public void ConstructorTCreatedTest() { CreationEventArgs args = new CreationEventArgs(2); Assert.AreEqual(2, args.CreatedInstance, "CreationEventArgs.CreatedInstance was not the " + "expected value."); } [Test, Description("Test to ensure " + "CreationEventArgs.CreationEventArgs(TCreated, Object) " + "constructor sets the CreationEventArgs.CreatedInstance " + "and CreationEventArgs.UserState to proper values.")] public void ConstructorTCreatedObjectTest() { String userState = new string('A', 1); CreationEventArgs args = new CreationEventArgs(2, userState); Assert.AreEqual(2, args.CreatedInstance, "CreationEventArgs.CreatedInstance was not the " + "expected value."); Assert.AreEqual(userState, args.UserState, "CreationEventArgs.UserState was not the " + "expected value."); } [Test, Description("Test to ensure " + "CreationEventArgs.CreationEventArgs(TCreated) " + "constructor sets the CreationEventArgs.Canceled " + "to a the proper value.")] public void ConstructorBoolTest() { CreationEventArgs args = new CreationEventArgs(true); Assert.AreEqual(true, args.Cancelled, "CreationEventArgs.Canceled was not the " + "expected value."); } [Test, Description("Test to ensure " + "CreationEventArgs.CreationEventArgs(TCreated) " + "constructor sets the CreationEventArgs.Canceled " + "and CreationEventArgs.UserState to proper values.")] public void ConstructorBoolObjectTest() { String userState = new string('A', 1); CreationEventArgs args = new CreationEventArgs(true, userState); Assert.AreEqual(true, args.Cancelled, "CreationEventArgs.Canceled was not the " + "expected value."); Assert.AreEqual(userState, args.UserState, "CreationEventArgs.UserState was not the " + "expected value."); } [Test, Description("Test to ensure " + "CreationEventArgs.CreationEventArgs(Exception) " + "constructor sets the CreationEventArgs.Error " + "to a the proper value.")] public void ConstructorExceptionTest() { Exception exception = new Exception(); CreationEventArgs args = new CreationEventArgs(exception); Assert.AreEqual(exception, args.Error, "CreationEventArgs.Error was not the " + "expected value."); } [Test, Description("Test to ensure " + "CreationEventArgs.CreationEventArgs(Exception) " + "constructor sets the CreationEventArgs.Error " + "and CreationEventArgs.UserState to proper values.")] public void ConstructorExceptionObjectTest() { Exception exception = new Exception(); String userState = new string('A', 1); CreationEventArgs args = new CreationEventArgs(exception, userState); Assert.AreEqual(exception, args.Error, "CreationEventArgs.Error was not the " + "expected value."); Assert.AreEqual(userState, args.UserState, "CreationEventArgs.UserState was not the " + "expected value."); } [Test, Description("Test to ensure " + "CreationEventArgs.CreatedInstance " + "throws an exception when CreationEventArgs.Error is set " + "to a non-null value.")] public void CreatedInstanceErrorExceptionTest() { ArgumentException exception = new ArgumentException(); CreationEventArgs args = new CreationEventArgs(exception); Assert.Throws(() => Console.Write(args.CreatedInstance)); } [Test, Description("Test to ensure " + "CreationEventArgs.CreatedInstance " + "does not throw an exception when CreationEventArgs.Error is " + "set to null value.")] public void CreatedInstanceErrorNoExceptionTest() { CreationEventArgs args = new CreationEventArgs(null); Console.Write(args.CreatedInstance); } [Test, Description("Test to ensure " + "CreationEventArgs.CreatedInstance " + "throws an exception when CreationEventArgs.Canceled is set " + "to true.")] public void CreatedInstanceCanceledExceptionTest() { CreationEventArgs args = new CreationEventArgs(true); Assert.Throws(() => Console.Write(args.CreatedInstance)); } [Test, Description("Test to ensure " + "CreationEventArgs.CreatedInstance " + "does not throw an exception when CreationEventArgs.Canceled " + "is set to false.")] public void CreatedInstanceCanceledNoExceptionTest() { CreationEventArgs args = new CreationEventArgs(false); Console.Write(args.CreatedInstance); } } }