// ***** public void RunTests(TestNotificationDelegate testNotificationEvent) { object instance = tfa.CreateClass(); foreach(TestAttribute ta in testList) RunTest(testNotificationEvent, instance, ta); }
private void RunTest(TestNotificationDelegate testNotificationEvent, object instance, TestAttribute ta) { if (!ta.IgnoreTest()) { try { if (sua != null) sua.Invoke(instance); ta.Invoke(instance); // If we get here, the test did not throw an exception. // Was it supposed too? if (ta.ExpectedExceptionType != null) { Trace.WriteLine("***Fail***: " + ta.TestMethod.ToString() + " Expected exception not encountered"); ta.State = TestAttribute.TestState.Fail; } else { Trace.WriteLine("***Pass***: " + ta.TestMethod.ToString()); ta.State = TestAttribute.TestState.Pass; } } catch (AssertFailedException e) { Trace.WriteLine("***Fail***: " + ta.TestMethod.ToString() + " Exception=" + e.Message); ta.State = TestAttribute.TestState.Fail; } catch (Exception e) { if (e.GetType() != ta.ExpectedExceptionType) { Trace.WriteLine("***Fail***: " + ta.TestMethod.ToString() + " Exception=" + e.Message); ta.State = TestAttribute.TestState.Fail; } else { Trace.WriteLine("***Pass***: " + ta.TestMethod.ToString() + " Exception=" + e.Message); ta.State = TestAttribute.TestState.Pass; } } finally { if (tda != null) tda.Invoke(instance); } } else { //Trace.WriteLine("***Ignore***: " + ta.TestMethod.ToString()); ta.State = TestAttribute.TestState.Ignore; } if (testNotificationEvent != null) { testNotificationEvent(ta); } }