Skip to content

Commit 273ace1

Browse files
committed
Fixed broken tests
1 parent 4286834 commit 273ace1

File tree

4 files changed

+51
-17
lines changed

4 files changed

+51
-17
lines changed

src/TestStack.BDDfy.Tests/Stories/StoryDouble.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ public class StoryDouble
1414
public void ScanningAScenarioWithoutArgsFromAStoryClass()
1515
{
1616
var testObject = new DummyScenario();
17-
var scanner = new DefaultScanner(TestContext.GetContext(testObject), new ReflectiveScenarioScanner(new DefaultMethodNameStepScanner()));
17+
var scanner = new DefaultScanner(TestContext.GetContext(testObject), new ReflectiveScenarioScanner(new DefaultMethodNameStepScanner()), typeof(StoryDouble));
1818
var story = scanner.Scan();
1919

2020
story.Metadata.Type.ShouldBe(typeof(StoryDouble));
2121
story.Scenarios.Count().ShouldBe(1);
2222
story.Scenarios.Single().TestObject.ShouldBeAssignableTo<DummyScenario>();
23+
2324
}
2425
}
2526
}

src/TestStack.BDDfy/BDDfyExtensions.cs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
using System;
22
using System.Linq;
3+
using System.Runtime.CompilerServices;
34
using TestStack.BDDfy.Configuration;
45

56
namespace TestStack.BDDfy
67
{
78
public static class BDDfyExtensions
89
{
10+
#if StackTrace
911
/// <summary>
1012
/// Extension method to BDDfy an object instance.
1113
/// </summary>
@@ -28,18 +30,57 @@ public static Engine LazyBDDfy(this object testObject, string scenarioTitle = nu
2830
/// <typeparam name="TStory">The type representing the story.</typeparam>
2931
/// <param name="testObject">The test object representing a scenario.</param>
3032
/// <param name="scenarioTitle">Overrides the default scenario title and is displayed in the reports.</param>
33+
/// <param name="caller">Caller (populated by [CallerMemberName])</param>
3134
/// <returns></returns>
3235
public static Story BDDfy<TStory>(this object testObject, string scenarioTitle = null)
3336
where TStory : class
3437
{
35-
return testObject.LazyBDDfy<TStory>(scenarioTitle).Run();
38+
return InternalLazyBDDfy(testObject, scenarioTitle, typeof(TStory)).Run();
3639
}
3740

3841
public static Engine LazyBDDfy<TStory>(this object testObject, string scenarioTitle = null)
3942
where TStory : class
4043
{
4144
return InternalLazyBDDfy(testObject, scenarioTitle, typeof(TStory));
4245
}
46+
#else
47+
/// <summary>
48+
/// Extension method to BDDfy an object instance.
49+
/// </summary>
50+
/// <param name="testObject">The test object representing a scenario.</param>
51+
/// <param name="scenarioTitle">Overrides the default scenario title and is displayed in the reports.</param>
52+
/// <param name="caller">Caller (populated by [CallerMemberName])</param>
53+
/// <returns></returns>
54+
public static Story BDDfy(this object testObject, string scenarioTitle = null, [CallerMemberName] string caller = null)
55+
{
56+
return InternalLazyBDDfy(testObject, scenarioTitle ?? Configurator.Scanners.Humanize(caller)).Run();
57+
}
58+
59+
public static Engine LazyBDDfy(this object testObject, string scenarioTitle = null, [CallerMemberName] string caller = null)
60+
{
61+
return InternalLazyBDDfy(testObject, scenarioTitle ?? Configurator.Scanners.Humanize(caller));
62+
}
63+
64+
/// <summary>
65+
/// Extension method to BDDfy an object instance.
66+
/// </summary>
67+
/// <typeparam name="TStory">The type representing the story.</typeparam>
68+
/// <param name="testObject">The test object representing a scenario.</param>
69+
/// <param name="scenarioTitle">Overrides the default scenario title and is displayed in the reports.</param>
70+
/// <param name="caller">Caller (populated by [CallerMemberName])</param>
71+
/// <returns></returns>
72+
public static Story BDDfy<TStory>(this object testObject, string scenarioTitle = null, [CallerMemberName] string caller = null)
73+
where TStory : class
74+
{
75+
return InternalLazyBDDfy(testObject, scenarioTitle ?? Configurator.Scanners.Humanize(caller), typeof(TStory)).Run();
76+
}
77+
78+
public static Engine LazyBDDfy<TStory>(this object testObject, string scenarioTitle = null, [CallerMemberName] string caller = null)
79+
where TStory : class
80+
{
81+
return InternalLazyBDDfy(testObject, scenarioTitle ?? Configurator.Scanners.Humanize(caller), typeof(TStory));
82+
}
83+
#endif
4384

4485
static Engine InternalLazyBDDfy(
4586
object testObject,

src/TestStack.BDDfy/Scanners/StoryAttributeMetaDataScanner.cs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,9 @@ protected virtual Type GetCandidateStory(object testObject, Type explicitStoryTy
3939
if (explicitStoryType != null)
4040
return explicitStoryType;
4141

42-
// ReSharper disable once JoinDeclarationAndInitializer
43-
StackTrace stackTrace;
4442
#if STACKTRACE
45-
stackTrace = new StackTrace();
46-
#else
47-
try
48-
{
49-
throw new Exception();
50-
}
51-
catch (Exception e)
52-
{
53-
stackTrace = new StackTrace(e, false);
54-
}
55-
#endif
43+
StackTrace stackTrace = new StackTrace();
44+
5645
var frames = stackTrace.GetFrames();
5746
if (frames == null)
5847
return null;
@@ -63,6 +52,8 @@ protected virtual Type GetCandidateStory(object testObject, Type explicitStoryTy
6352
return null;
6453

6554
return firstFrame.GetMethod().DeclaringType;
55+
#endif
56+
return null;
6657
}
6758

6859
static StoryNarrativeAttribute GetStoryAttribute(Type candidateStoryType)

src/TestStack.BDDfy/Story.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections.Generic;
23
using System.Linq;
34

@@ -18,8 +19,8 @@ public Story(StoryMetadata metadata, params Scenario[] scenarios)
1819
}
1920
}
2021

21-
public StoryMetadata Metadata { get; private set; }
22-
22+
public StoryMetadata Metadata { get; }
23+
2324
/// <summary>
2425
/// Currently used only when scenario doesn't have a story and we use the namespace instead
2526
/// </summary>

0 commit comments

Comments
 (0)