public void Run_OnRethrowOfException_StackTraceStartsWithRaisedSource() { var pipeRaisingEx = Scenario("Test scenario") .Given(null, () => new { A = 5, B = 10 }) .And("a null reference exception is raised", () => { var testClass = new ExceptionTestNamespace.TestClass(); testClass.CauseNullReferenceException(); }); Action run = () => pipeRaisingEx.Run(result => { /*mute*/ }); run.Should().ThrowExactly <NullReferenceException>() .Which .StackTrace.Should().StartWith(ExpectedStacktraceStart); }
public void Run_OnRethrowOfException_StackTraceRefersToThrownLocation() { var pipeRaisingEx = Scenario("Test scenario") .Given(null, () => new { A = 5, B = 10 }) .And("a null reference exception is raised", () => { var testClass = new ExceptionTestNamespace.TestClass(); testClass.CauseNullReferenceException(); }) .When("the numbers are summed", args => new { Result = args.A + args.B }) .Then("sum should be as expected", arg => { arg.Result.Should().Be(15); }); var raisedExceptionStackTrace = pipeRaisingEx.Match( ctnValue => throw new InconclusiveException("Expecting an exception was raised by a step"), ctnError => { try { ctnError.Content.Throw(); } catch (Exception ex) { return(ex.StackTrace); } throw new Exception("Could not return stacktrace"); }); var expected = GetStackTraceUntilPreviousLocationMarker(raisedExceptionStackTrace); expected.Should().StartWith(ExpectedStacktraceStart); expected.Should().EndWith(StacktraceSectionMarker); Console.WriteLine("==============="); Console.WriteLine($"Expected stack trace to start with this initial stack trace:"); Console.WriteLine(expected); Console.WriteLine("==============="); Action run = () => pipeRaisingEx.Run(result => { /*mute*/ }); run.Should().ThrowExactly <NullReferenceException>() .Which .StackTrace.Should().StartWith(expected); }