protected virtual void Run(TestResult result, TestListener listener) { IgnoreAttribute ignore = (IgnoreAttribute)Reflect.GetAttribute(method, typeof(IgnoreAttribute)); if (this.RunState == RunState.NotRunnable) { result.Failure(this.ignoreReason); } else if (ignore != null) { result.NotRun(ignore.Reason); } else { try { RunBare(); result.Success(); } catch (NUnitLiteException nex) { result.RecordException(nex.InnerException); } #if !NETCF_1_0 catch (System.Threading.ThreadAbortException) { throw; } #endif catch (Exception ex) { result.RecordException(ex); } } }
protected virtual void Run(TestResult result, TestListener listener) { //this.method = GetMethod(this.Name, BindingFlags.Public | BindingFlags.Instance); IgnoreAttribute ignore = (IgnoreAttribute)Reflect.GetAttribute(method, typeof(IgnoreAttribute)); if (ignore != null) { result.NotRun(ignore.Reason); } else { try { RunBare(); result.Success(); } catch (NUnitLiteException nex) { result.RecordException(nex.InnerException); } #if !NETCF_1_0 catch (System.Threading.ThreadAbortException) { throw; } #endif catch (Exception ex) { result.RecordException(ex); } } }
public TestSuite(Type type) { this.name = type.Name; this.fullName = type.FullName; object[] attrs = type.GetCustomAttributes(typeof(PropertyAttribute), true); foreach (PropertyAttribute attr in attrs) { this.Properties[attr.Name] = attr.Value; } IgnoreAttribute ignore = (IgnoreAttribute)Reflect.GetAttribute(type, typeof(IgnoreAttribute)); if (ignore != null) { this.runState = RunState.Ignored; this.ignoreReason = ignore.Reason; } if (!InvalidTestSuite(type)) { foreach (MethodInfo method in type.GetMethods()) { if (IsTestMethod(method)) { this.AddTest(HasValidSignature(method) ? Reflect.ConstructTestCase(method) : new InvalidTestCase(method.Name, "Test methods must have signature void MethodName()")); } } } }
private static void ProcessNoException(MethodInfo method) { ExpectedExceptionAttribute exceptionAttribute = (ExpectedExceptionAttribute)Reflect.GetAttribute(method, typeof(ExpectedExceptionAttribute)); if (exceptionAttribute != null) { Assert.Fail("Expected Exception of type <{0}>, but none was thrown", exceptionAttribute.ExceptionType); } }
public TestSuite(Type type) { TestObject = Reflect.Construct(type, null); this.name = type.Name; this.fullName = type.FullName; object[] attrs = type.GetCustomAttributes(typeof(PropertyAttribute), true); foreach (PropertyAttribute attr in attrs) { foreach (DictionaryEntry entry in attr.Properties) { this.Properties[entry.Key] = entry.Value; } } IgnoreAttribute ignore = (IgnoreAttribute)Reflect.GetAttribute(type, typeof(IgnoreAttribute)); if (ignore != null) { this.runState = RunState.Ignored; this.ignoreReason = ignore.Reason; } if (!InvalidTestSuite(type)) { foreach (MethodInfo method in type.GetMethods()) { if (TestCase.IsTestMethod(method)) { this.AddTest(new TestCase(method, TestObject)); } else if (IsTestFixtureSetup(method)) { TestFixtureSetUpMethod = method; } else if (IsTestFixtureTearDownAttribute(method)) { TestFixtureTearDownMethod = method; } } } }
private void Initialize(string name, object fixture) { this.name = name; this.fixture = fixture; this.fullName = this.fixture.GetType().FullName + "." + name; this.method = Reflect.GetMethod(this.fixture.GetType(), name); if (this.method == null) { this.runState = RunState.NotRunnable; } else { IgnoreAttribute ignore = (IgnoreAttribute)Reflect.GetAttribute(this.method, typeof(IgnoreAttribute)); if (ignore != null) { this.runState = RunState.Ignored; this.ignoreReason = ignore.Reason; } } }
public TestSuite(Type type) { this.name = type.Name; this.fullName = type.FullName; object[] attrs = type.GetCustomAttributes(typeof(PropertyAttribute), true); foreach (PropertyAttribute attr in attrs) { foreach (var entry in attr.Properties) { this.Properties[entry.Key] = entry.Value; } } IgnoreAttribute ignore = (IgnoreAttribute)Reflect.GetAttribute(type, typeof(IgnoreAttribute)); if (ignore != null) { this.runState = RunState.Ignored; this.ignoreReason = ignore.Reason; } if (!InvalidTestSuite(type)) { foreach (MethodInfo method in type.GetMethods()) { if (TestCase.IsTestMethod(method)) { this.AddTest(new TestCase(method)); } //{ // ITest test = TestCase.HasValidSignature(method) // ? (ITest)new TestCase(method) // : (ITest)new InvalidTestCase(method.Name, // "Test methods must have signature void MethodName()"); // this.AddTest(test); //} } } }
private void Initialize(MethodInfo method, object fixture) { this.name = method.Name; this.method = method; this.fullName = method.ReflectedType.FullName + "." + name; this.fixture = fixture; if (fixture == null) { this.fixture = Reflect.Construct(method.ReflectedType, null); } if (!HasValidSignature(method)) { this.runState = RunState.NotRunnable; this.ignoreReason = "Test methods must have signature void MethodName()"; } else { IgnoreAttribute ignore = (IgnoreAttribute)Reflect.GetAttribute(this.method, typeof(IgnoreAttribute)); if (ignore != null) { this.runState = RunState.Ignored; this.ignoreReason = ignore.Reason; } } foreach (MethodInfo m in method.ReflectedType.GetMethods()) { if (Reflect.HasAttribute(m, typeof(SetUpAttribute))) { this.setup = m; } if (Reflect.HasAttribute(m, typeof(TearDownAttribute))) { this.teardown = m; } } }
private void ProcessException(MethodInfo method, Exception caughtException) { ExpectedExceptionAttribute exceptionAttribute = (ExpectedExceptionAttribute)Reflect.GetAttribute(method, typeof(ExpectedExceptionAttribute)); if (exceptionAttribute == null) { throw new NUnitLiteException("", caughtException); } Type expectedType = exceptionAttribute.ExceptionType; if (expectedType != null && expectedType != caughtException.GetType()) { Assert.Fail("Expected Exception of type <{0}>, but was <{1}>", exceptionAttribute.ExceptionType, caughtException.GetType()); } MethodInfo handler = GetExceptionHandler(method.ReflectedType, exceptionAttribute.Handler); if (handler != null) { InvokeMethod(handler, caughtException); } }