/// <summary> /// Modify a newly constructed test by checking for ExpectedExceptionAttribute /// and setting properties on the test accordingly. /// </summary> /// <param name="attributes">An array of attributes possibly including NUnit attributes /// <param name="test">The test to which the attributes apply</param> public static void ApplyExpectedExceptionAttribute(MethodInfo method, TestMethod testMethod) { Attribute attribute = Reflect.GetAttribute( method, NUnitFramework.ExpectedExceptionAttribute, false); if (attribute != null) { testMethod.ExceptionProcessor = new ExpectedExceptionProcessor(testMethod, attribute); } }
// public Test Decorate(Test test, MethodInfo method) // { // return DecorateTest( test, method ); // } // // public Test Decorate(Test test, Type fixtureType) // { // return DecorateTest( test, fixtureType ); // } public Test Decorate(Test test, MemberInfo member) { Attribute ignoreAttribute = Reflect.GetAttribute(member, NUnitFramework.IgnoreAttribute, false); if (ignoreAttribute != null) { test.RunState = RunState.Ignored; test.IgnoreReason = NUnitFramework.GetIgnoreReason(ignoreAttribute); } return(test); }
// TODO: Handle this with a separate ExceptionProcessor object public static void ApplyExpectedExceptionAttribute(MethodInfo method, TestMethod testMethod) { Attribute attribute = Reflect.GetAttribute( method, NUnitFramework.ExpectedExceptionAttribute, false); if (attribute != null) { testMethod.ExceptionExpected = true; Type expectedExceptionType = GetExceptionType(attribute); string expectedExceptionName = GetExceptionName(attribute); if (expectedExceptionType != null) { testMethod.ExpectedExceptionType = expectedExceptionType; } else if (expectedExceptionName != null) { testMethod.ExpectedExceptionName = expectedExceptionName; } testMethod.ExpectedMessage = GetExpectedMessage(attribute); testMethod.MatchType = GetMatchType(attribute); testMethod.UserMessage = GetUserMessage(attribute); string handlerName = GetHandler(attribute); if (handlerName == null) { testMethod.ExceptionHandler = GetDefaultExceptionHandler(testMethod.FixtureType); } else { MethodInfo handler = GetExceptionHandler(testMethod.FixtureType, handlerName); if (handler != null) { testMethod.ExceptionHandler = handler; } else { testMethod.RunState = RunState.NotRunnable; testMethod.IgnoreReason = string.Format( "The specified exception handler {0} was not found", handlerName); } } } }