/// <summary> /// Executes the test method. Creates a new instance of the class /// under tests and passes it to the inner command. Also catches /// any exceptions and converts them into <see cref="FailedResult"/>s. /// </summary> /// <param name="testClass">The instance of the test class</param> /// <returns>Returns information about the test run</returns> public override MethodResult Execute(object testClass) { try { if (testClass == null) { testClass = method.CreateInstance(); } } catch (TargetInvocationException ex) { ExceptionUtility.RethrowWithNoStackTraceLoss(ex.InnerException); } try { return(InnerCommand.Execute(testClass)); } finally { IDisposable disposable = testClass as IDisposable; if (disposable != null) { disposable.Dispose(); } } }
/// <summary> /// Sets the fixtures on the test class by calling SetFixture, then /// calls the inner command. /// </summary> /// <param name="testClass">The instance of the test class</param> /// <returns>Returns information about the test run</returns> public override MethodResult Execute(object testClass) { try { if (testClass != null) { foreach (KeyValuePair <MethodInfo, object> fixture in fixtures) { fixture.Key.Invoke(testClass, new object[] { fixture.Value }); } } } catch (TargetInvocationException ex) { ExceptionUtility.RethrowWithNoStackTraceLoss(ex.InnerException); } return(InnerCommand.Execute(testClass)); }
public void Invoke(object testClass, params object[] parameters) { if (taskType != null && taskWaitMethod == null) { taskWaitMethod = taskType.GetMethod("Wait", new Type[0]); aggregateExceptionInnerExceptions = aggregateExceptionType.GetProperty("InnerExceptions"); } try { try { object result = method.Invoke(testClass, parameters); if (taskType != null && result != null && taskType.IsAssignableFrom(result.GetType())) { taskWaitMethod.Invoke(result, null); } } catch (TargetParameterCountException) { throw new ParameterCountMismatchException(); } catch (TargetInvocationException ex) { ExceptionUtility.RethrowWithNoStackTraceLoss(ex.InnerException); } } catch (Exception ex) { if (aggregateExceptionType != null && aggregateExceptionType.IsAssignableFrom(ex.GetType())) { ReadOnlyCollection <Exception> exceptions = (ReadOnlyCollection <Exception>)aggregateExceptionInnerExceptions.GetValue(ex, null); ExceptionUtility.RethrowWithNoStackTraceLoss(exceptions[0]); } throw; } }