using Chernobyl; using NUnit.Framework; namespace System { /// /// A utility type that is used to ensure that methods, constructors, /// properties and the like throw an /// exception when they receive an invalid argument. /// /// The type of exception to test for. /// The type of the first argument. public abstract class ArgumentExceptionTests where TException : Exception where T1 : class { [Test, Description("Ensures a TException is thrown when an invalid first " + "argument is passed in.")] public virtual void FirstArgumentException() { Assert.Throws(() => OneArgInvoke(InvalidArg1), "Exception of type \"{0}\" was not thrown " + "as expected on receipt of invalid value.", typeof(TException).FullName); } /// /// The method that is invoked to test whether an /// is thrown on input of a /// /// first argument. /// protected abstract Action OneArgInvoke { get; } /// /// A valid value to the first argument that will not cause an exception /// to be thrown. /// protected abstract T1 ValidArg1 { get; } /// /// An invalid value to the first argument that will cause an exception /// to be thrown. /// protected abstract T1 InvalidArg1 { get; } } /// /// A utility type that is used to ensure that methods, constructors, /// properties and the like throw an /// exception when they receive an invalid argument. /// /// The type of exception to test for. /// The type of the first argument. /// The type of the second argument. public abstract class ArgumentExceptionTests : ArgumentExceptionTests where TException : Exception where T1 : class where T2 : class { [Test, Description("Ensures a TException is thrown when an invalid" + "second argument is passed in.")] public virtual void SecondArgumentException() { Assert.Throws(() => TwoArgInvoke(ValidArg1, InvalidArg2), "Exception of type \"{0}\" was not thrown " + "as expected on receipt of invalid value.", typeof(TException).FullName); } /// /// The method that is invoked to test whether an /// is thrown on input of invalid arguments. /// protected abstract Action TwoArgInvoke { get; } /// /// A valid value to the second argument that will not cause an exception /// to be thrown. /// protected abstract T2 ValidArg2 { get; } /// /// An invalid value to the second argument that will cause an exception /// to be thrown. /// protected abstract T2 InvalidArg2 { get; } /// /// The method that is invoked to test whether an /// is thrown on input of a /// /// first argument. /// protected override Action OneArgInvoke { get { return arg => TwoArgInvoke(arg, ValidArg2); } } } /// /// A utility type that is used to ensure that methods, constructors, /// properties and the like throw an /// exception when they receive an invalid argument. /// /// The type of exception to test for. /// The type of the first argument. /// The type of the second argument. /// The type of the third argument. public abstract class ArgumentExceptionTests : ArgumentExceptionTests where TException : Exception where T1 : class where T2 : class where T3 : class { [Test, Description("Ensures a TException is thrown when an invalid" + "third argument is passed in.")] public virtual void ThirdArgumentException() { Assert.Throws(() => ThreeArgInvoke(ValidArg1, ValidArg2, InvalidArg3), "Exception of type \"{0}\" was not thrown " + "as expected on receipt of invalid value.", typeof(TException).FullName); } /// /// The method that is invoked to test whether an /// is thrown on input of invalid arguments. /// protected abstract Action ThreeArgInvoke { get; } /// /// A valid value to the third argument that will not cause an exception /// to be thrown. /// protected abstract T3 ValidArg3 { get; } /// /// An invalid value to the third argument that will cause an exception /// to be thrown. /// protected abstract T3 InvalidArg3 { get; } /// /// The method that is invoked to test whether an /// is thrown on input of invalid arguments. /// protected override Action TwoArgInvoke { get { return (arg1, arg2) => ThreeArgInvoke(arg1, arg2, ValidArg3); } } } /// /// A utility type that is used to ensure that methods, constructors, /// properties and the like throw an /// exception when they receive an invalid argument. /// /// The type of exception to test for. /// The type of the first argument. /// The type of the second argument. /// The type of the third argument. /// The type of the fourth argument. public abstract class ArgumentExceptionTests : ArgumentExceptionTests where TException : Exception where T1 : class where T2 : class where T3 : class where T4 : class { [Test, Description("Ensures a TException is thrown when an invalid" + "fourth argument is passed in.")] public virtual void FourthArgumentException() { Assert.Throws(() => FourArgInvoke(ValidArg1, ValidArg2, ValidArg3, InvalidArg4), "Exception of type \"{0}\" was not thrown " + "as expected on receipt of invalid value.", typeof(TException).FullName); } /// /// The method that is invoked to test whether an /// is thrown on input of invalid arguments. /// protected abstract Action FourArgInvoke { get; } /// /// A valid value to the fourth argument that will not cause an exception /// to be thrown. /// protected abstract T4 ValidArg4 { get; } /// /// An invalid value to the fourth argument that will cause an exception /// to be thrown. /// protected abstract T4 InvalidArg4 { get; } /// /// The method that is invoked to test whether an /// is thrown on input of invalid arguments. /// protected override Action ThreeArgInvoke { get { return (arg1, arg2, arg3) => FourArgInvoke(arg1, arg2, arg3, ValidArg4); } } } /// /// A utility type that is used to ensure that methods, constructors, /// properties and the like throw an /// exception when they receive an invalid argument. /// /// The type of exception to test for. /// The type of the first argument. /// The type of the second argument. /// The type of the third argument. /// The type of the fourth argument. /// The type of the fifth argument. public abstract class ArgumentExceptionTests : ArgumentExceptionTests where TException : Exception where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class { [Test, Description("Ensures a TException is thrown when an invalid" + "fifth argument is passed in.")] public virtual void FifthArgumentException() { Assert.Throws(() => FiveArgInvoke(ValidArg1, ValidArg2, ValidArg3, ValidArg4, InvalidArg5), "Exception of type \"{0}\" was not thrown " + "as expected on receipt of invalid value.", typeof(TException).FullName); } /// /// The method that is invoked to test whether an /// is thrown on input of invalid arguments. /// protected abstract Action FiveArgInvoke { get; } /// /// A valid value to the fifth argument that will not cause an exception /// to be thrown. /// protected abstract T5 ValidArg5 { get; } /// /// An invalid value to the fifth argument that will cause an exception /// to be thrown. /// protected abstract T5 InvalidArg5 { get; } /// /// The method that is invoked to test whether an /// is thrown on input of invalid arguments. /// protected override Action FourArgInvoke { get { return (arg1, arg2, arg3, arg4) => FiveArgInvoke(arg1, arg2, arg3, arg4, ValidArg5); } } } }