Skip to content

Commit c3de2f0

Browse files
committed
Issue 17 fix. Fluent scanner returns outer exception.
1 parent 8fd7523 commit c3de2f0

File tree

5 files changed

+48
-4
lines changed

5 files changed

+48
-4
lines changed

NuGet/TestStack.BDDfy/TestStack.BDDfy.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
33
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
44
<id>TestStack.BDDfy</id>
5-
<version>3.14</version>
5+
<version>3.15</version>
66
<title>A simple to use and extend BDD framework for .Net programmers</title>
77
<authors>Mehdi Khalili, Michael Whelan</authors>
88
<owners>Mehdi Khalili, Michael Whelan</owners>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using System.Xml;
3+
using NUnit.Framework;
4+
5+
namespace TestStack.BDDfy.Tests.Exceptions.OtherExceptions
6+
{
7+
public class WhenResolvingExceptionsFromDifferentScanners
8+
{
9+
private ExceptionThrowingTest<OuterException> _sut;
10+
11+
/// <summary>
12+
/// Test to resolve issue where fluent scanner was returning the inner exception rather than the outer one.
13+
/// Issue 17: https://github.com/TestStack/TestStack.BDDfy/issues/17
14+
/// </summary>
15+
[Test]
16+
public void FluentScannerShouldReturnOriginalExceptionAndNotInnerException()
17+
{
18+
_sut = new ExceptionThrowingTest<OuterException>();
19+
Assert.Throws<OuterException>(() => _sut.Execute(ThrowingMethods.Given, true));
20+
}
21+
22+
[Test]
23+
public void ReflectiveScannerShouldReturnOriginalExceptionAndNotTargetInvocationException()
24+
{
25+
_sut = new ExceptionThrowingTest<OuterException>();
26+
Assert.Throws<OuterException>(() => _sut.Execute(ThrowingMethods.Given, false));
27+
}
28+
29+
private class OuterException : Exception
30+
{
31+
public OuterException()
32+
: base("outer", new XmlException("inner exception"))
33+
{
34+
}
35+
}
36+
}
37+
38+
}

TestStack.BDDfy.Tests/TestStack.BDDfy.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
<Compile Include="Configuration\BatchProcessorsTests.cs" />
5959
<Compile Include="Configuration\ProcessorPipelineTests.cs" />
6060
<Compile Include="Disposer\DisposingScenarios.cs" />
61+
<Compile Include="Exceptions\OtherExceptions\WhenResolvingExceptionsFromDifferentScanners.cs" />
6162
<Compile Include="Exceptions\ThrowingMethods.cs" />
6263
<Compile Include="Exceptions\WhenAnInconclusiveTestIsRun.cs" />
6364
<Compile Include="Exceptions\ExceptionThrowingTest.cs" />

TestStack.BDDfy/Core/Scenario.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Reflection;
45

56
namespace TestStack.BDDfy.Core
67
{
@@ -48,7 +49,11 @@ public StepExecutionResult ExecuteStep(ExecutionStep executionStep)
4849
catch (Exception ex)
4950
{
5051
// ToDo: more thought should be put into this. Is it safe to get the exception?
51-
var exception = ex.InnerException ?? ex;
52+
var exception = ex;
53+
if (exception is TargetInvocationException)
54+
{
55+
exception = ex.InnerException ?? ex;
56+
}
5257

5358
if (exception is NotImplementedException)
5459
{

TestStack.BDDfy/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
[assembly: AssemblyCulture("")]
1212
[assembly: ComVisible(false)]
1313

14-
[assembly: AssemblyVersion("3.14")]
15-
[assembly: AssemblyFileVersion("3.14")]
14+
[assembly: AssemblyVersion("3.15")]
15+
[assembly: AssemblyFileVersion("3.15")]

0 commit comments

Comments
 (0)