public UnitTestFrameworkNamer() { Approvals.SetCaller(); stackTraceParser = new StackTraceParser(); stackTraceParser.Parse(Approvals.CurrentCaller.StackTrace); HandleSubdirectory(); }
public void Parse_UsingStaticInitialize_DontThrowInvalidOperationException() { // ARRANGE var parser = new StackTraceParser(); // ACT + ASSERT try { Parallel.ForEach(Enumerable.Range(1, 20), (_) => { try { var stackTrace = new StackTrace(); parser.Parse(stackTrace); } catch (InvalidOperationException e) { Assert.Fail( "InvalidOperationException when trying to parse stacktrace. " + "This is caused by the parser collection not being thread-safe. " + "Original exception message : {0} and stacktrace : {1}", e.Message, e.StackTrace ); } // Because the current stacktrace passed to the parse method doesn't contains any trace of a compliant stacktrace parser // it's normal that we receive an exception here so let's ignore it. catch (Exception e) { if ( !e.Message.StartsWith("Approvals is not set up to use your test framework", StringComparison.OrdinalIgnoreCase)) { Assert.Fail("Any other exception"); } } }); } catch (AggregateException e) { // Throw the first inner exception of the AggretateException, this way NUnit shows a much clearer result. throw e.InnerException; } }