Skip to content

Commit fc8e7b9

Browse files
committed
added In order to support
1 parent 9967741 commit fc8e7b9

4 files changed

Lines changed: 39 additions & 3 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using NUnit.Framework;
2+
3+
namespace TestStack.BDDfy.Tests.Stories
4+
{
5+
[TestFixture]
6+
[Story(
7+
InOrderTo = "do something",
8+
AsA = "programmer",
9+
IWant = "this to work")]
10+
public class CanUseInOrderToSyntax
11+
{
12+
[Test]
13+
public void When_InOrderTo_is_specified_the_InOrderTo_syntax_is_used()
14+
{
15+
var story = new DummyScenario().BDDfy<CanUseInOrderToSyntax>();
16+
17+
Assert.That(story.Metadata.Narrative1, Is.EqualTo("In order to do something"));
18+
Assert.That(story.Metadata.Narrative2, Is.EqualTo("As a programmer"));
19+
Assert.That(story.Metadata.Narrative3, Is.EqualTo("I want this to work"));
20+
}
21+
}
22+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
<Compile Include="Scanner\WhenCombinationOfExecutableAttributeAndMethodNamingConventionIsUsed.cs" />
100100
<Compile Include="Scanner\WhenStepsAreDefinedInABaseClass.cs" />
101101
<Compile Include="Scanner\WhenStepsReturnTheirText.cs" />
102+
<Compile Include="Stories\CanUseInOrderToSyntax.cs" />
102103
<Compile Include="Stories\WhenStoryAttibuteMissesDuplicateTextsInProperties.cs" />
103104
<Compile Include="Stories\WhenStoryAttibuteMissesSoThatTextInSoThatProperty.cs" />
104105
<Compile Include="Stories\WhenStoryAttibuteMissesIWantTextInIWantProperty.cs" />

TestStack.BDDfy/Scanners/StoryAttributeMetaDataScanner.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class StoryAttributeMetadataScanner : IStoryMetadataScanner
1111
private const string I_want_prefix = "I want";
1212
private const string So_that_prefix = "So that";
1313
private const string As_a_prefix = "As a";
14+
private const string In_order_to_prefix = "In order to";
1415
// ReSharper restore InconsistentNaming
1516

1617
public virtual StoryMetadata Scan(object testObject, Type explicitStoryType = null)
@@ -47,9 +48,20 @@ static StoryMetadata CreateStoryMetadata(Type storyType, StoryAttribute storyAtt
4748
if (string.IsNullOrEmpty(title))
4849
title = NetToString.Convert(storyType.Name);
4950

50-
var narrative1 = CleanseProperty(storyAttribute.AsA, As_a_prefix);
51-
var narrative2 = CleanseProperty(storyAttribute.IWant, I_want_prefix);
52-
var narrative3 = CleanseProperty(storyAttribute.SoThat, So_that_prefix);
51+
string narrative1, narrative2, narrative3;
52+
53+
if (!string.IsNullOrWhiteSpace(storyAttribute.InOrderTo))
54+
{
55+
narrative1 = CleanseProperty(storyAttribute.InOrderTo, In_order_to_prefix);
56+
narrative2 = CleanseProperty(storyAttribute.AsA, As_a_prefix);
57+
narrative3 = CleanseProperty(storyAttribute.IWant, I_want_prefix);
58+
}
59+
else
60+
{
61+
narrative1 = CleanseProperty(storyAttribute.AsA, As_a_prefix);
62+
narrative2 = CleanseProperty(storyAttribute.IWant, I_want_prefix);
63+
narrative3 = CleanseProperty(storyAttribute.SoThat, So_that_prefix);
64+
}
5365

5466
return new StoryMetadata(storyType, narrative1, narrative2, narrative3, title);
5567
}

TestStack.BDDfy/StoryAttribute.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ public class StoryAttribute : Attribute
99
public string AsA { get; set; }
1010
public string IWant { get; set; }
1111
public string SoThat { get; set; }
12+
public string InOrderTo { get; set; }
1213
}
1314
}

0 commit comments

Comments
 (0)