Beispiel #1
0
        public static Task CaseAsync(string name, Func <Task> handler)
        {
            var testResult = new TestDefinition();

            testResult.Name = name;
            var stopwatch = Stopwatch.StartNew();

            try
            {
                var task = handler();
                task.Wait();
                testResult.Result = TestResult.Succeeded;
            }
            catch (TestFailureException)
            {
                testResult.Result = TestResult.Failed;
            }
            catch (Exception ex)
            {
                testResult.Result    = TestResult.Errored;
                testResult.Exception = ex;
                onError(name, ex);
            }
            finally
            {
                stopwatch.Stop();
                testResult.RunTime = stopwatch.ElapsedMilliseconds;
            }

            var lastModule = testModules.Count - 1;

            testModules[lastModule].Tests.Add(testResult);

            return(Task.Run(() => { }));
        }
Beispiel #2
0
        public static void Case(string name, Action handler)
        {
            var testResult = new TestDefinition();

            testResult.Name = name;
            var stopwatch = Stopwatch.StartNew();

            try
            {
                handler();
            }
            catch (TestFailureException)
            {
                testResult.Result = TestResult.Failed;
            }
            catch (Exception ex)
            {
                testResult.Result    = TestResult.Errored;
                testResult.Exception = ex;
                onError(name, ex);
            }
            finally
            {
                stopwatch.Stop();
                testResult.RunTime = stopwatch.ElapsedMilliseconds;
            }

            var lastModule = testModules.Count - 1;

            testModules[lastModule].Tests.Add(testResult);
        }