public static void ExceptionReport(Exception exception) { if (exception == null) { return; } while (true) { switch (exception) { case TargetInvocationException targetInvocationException when targetInvocationException.InnerException != null: exception = targetInvocationException.InnerException; continue; case AggregateException aggregateException when aggregateException.InnerException != null: exception = aggregateException.InnerException; continue; default: break; } break; } if (exception is AssertionFailedException) { Console.WriteLine(exception.Message); Console.WriteLine(StringEx.Implode("\r\n", exception.StackTrace.Split(CharHelper.GetNewLineChars()).Skip(1))); return; } var report = new StringBuilder(); report.Append("Exception"); report.Append("\r\n\r\n"); var current = exception; for (; current != null; current = current.InnerException) { report.Append(StringEx.Join("\r\n\r\n", "== Exception Type ==", current.GetType().Name, "== Exception Message ==", current.Message, "== Source ==", current.Source, "== Stacktrace ==", current.StackTrace)); report.Append("\r\n\r\n"); } Console.WriteLine(report); }
public static void Main() { var ignoredCategories = new[] { "Performance" }; var tests = GetAllTests(ignoredCategories); var stopwatch = new Stopwatch(); Console.WriteLine(); foreach (var test in tests) { using (test) { object capturedResult = null; Exception capturedException = null; Console.Write($"{test.Name}"); var parameters = test.GenerateParameters(); Console.Write($"({StringEx.Implode(", ", parameters)})"); try { stopwatch.Restart(); capturedResult = test.Invoke(parameters); stopwatch.Stop(); } catch (Exception exception) { stopwatch.Stop(); capturedException = exception; } if (capturedException == null) { Console.Write($"-> ok {capturedResult} ({stopwatch.Elapsed})"); } else { Console.WriteLine($"-> error ({stopwatch.Elapsed})"); ExceptionReport(capturedException); } } Console.WriteLine(); } Exit(); }