private static async Task <TestResultInfo> ExecuteTest(MethodInfo test, MethodInfo preTest, MethodInfo postTest, object testClass) { var testResult = new TestResultInfo { ClassName = testClass.GetType().Name, TestName = test.Name, Result = TestResult.NotRun }; var tasks = new List <Task>(); try { if (preTest != null) { tasks.Add((Task)preTest.Invoke(testClass, new object[] {})); } tasks.Add((Task)test.Invoke(testClass, new object[] {})); if (postTest != null) { tasks.Add((Task)postTest.Invoke(testClass, new object[] {})); } testResult.Result = TestResult.Pass; await Task.WhenAll(tasks); } catch (Exception e) { testResult.Result = TestResult.Fail; testResult.Exception = e; } return(testResult); }
private static async Task<TestResultInfo> ExecuteTest(MethodInfo test, MethodInfo preTest, MethodInfo postTest, object testClass) { var testResult = new TestResultInfo {ClassName = testClass.GetType().Name ,TestName = test.Name, Result = TestResult.NotRun}; var tasks = new List<Task>(); try { if (preTest != null) { tasks.Add((Task) preTest.Invoke(testClass, new object[] {})); } tasks.Add((Task) test.Invoke(testClass, new object[] {})); if (postTest != null) { tasks.Add((Task) postTest.Invoke(testClass, new object[] {})); } testResult.Result = TestResult.Pass; await Task.WhenAll(tasks); } catch (Exception e) { testResult.Result = TestResult.Fail; testResult.Exception = e; } return testResult; }