コード例 #1
0
        /// <summary>
        /// Creates an ExpectedExceptionAttribute object. This constructor takes
        /// a array of objects to be used as parameters to instantiate an object
        /// of the exception type. That way not only the type but exception objects
        /// can be compared.
        /// </summary>
        /// <remarks>According to the description of Exception.Message in the .NET
        /// documentation, the Message propery "should completely describe the
        /// error". The implementation of ExpectedExceptionAttribute uses the
        /// Message property to compare the actual exception with the expected
        /// exception.
        /// </remarks>
        /// <param name="expectedExceptionType"></param>
        /// <param name="parameters"></param>
        public ExpectedExceptionAttribute(Type expectedExceptionType, params object[] parameters)
        {
            ValidateExceptionType(expectedExceptionType);
            Type[] types = new Type[parameters.Length];
            for (int i = 0; i < parameters.Length; i++)
            {
                types[i] = parameters[i].GetType();
            }
            ConstructorInfo ci = _expectedExceptionType.GetConstructor(types);

            if (ci != null)
            {
                _exception = ci.Invoke(parameters) as Exception;
            }
            else
            {
                _exceptionToThrow = new TestFailed(string.Empty,
                                                   "No constructor available for this set of "
                                                   + "parameters.");
            }
        }
コード例 #2
0
 /// <summary>
 /// Creates an ExpectedExceptionAttribute object. This constructor takes
 /// a array of objects to be used as parameters to instantiate an object
 /// of the exception type. That way not only the type but exception objects
 /// can be compared.
 /// </summary>
 /// <remarks>According to the description of Exception.Message in the .NET
 /// documentation, the Message propery "should completely describe the 
 /// error". The implementation of ExpectedExceptionAttribute uses the
 /// Message property to compare the actual exception with the expected
 /// exception.
 /// </remarks>
 /// <param name="expectedExceptionType"></param>
 /// <param name="parameters"></param>
 public ExpectedExceptionAttribute(Type expectedExceptionType, params object[] parameters) {
    ValidateExceptionType(expectedExceptionType);
    Type[] types = new Type[parameters.Length];
    for(int i = 0; i < parameters.Length; i++ ) {
       types[i] = parameters[i].GetType();
    }
    ConstructorInfo ci = _expectedExceptionType.GetConstructor(types);
    if( ci != null ) {
       _exception = ci.Invoke(parameters) as Exception;
    }
    else {
       _exceptionToThrow = new TestFailed(string.Empty,
          "No constructor available for this set of " 
          + "parameters.");
    }
 }