Skip to content

Commit bce4d0d

Browse files
committed
Merge pull request #67 from MehdiK/multiple-storymetadataprovider
makes StoryMetadata generic to allow different story narratives
2 parents dab3337 + 7f61915 commit bce4d0d

15 files changed

Lines changed: 139 additions & 71 deletions
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using NUnit.Framework;
2+
3+
namespace TestStack.BDDfy.Tests.Stories
4+
{
5+
class InOrderToStoryAttribute : StoryNarrativeAttribute
6+
{
7+
// ReSharper disable InconsistentNaming
8+
private const string As_a_prefix = "As a";
9+
private const string In_order_to_prefix = "In order to";
10+
private const string I_want_prefix = "I want";
11+
// ReSharper restore InconsistentNaming
12+
13+
public string InOrderTo
14+
{
15+
get { return Narrative1; }
16+
set { Narrative1 = CleanseProperty(value, In_order_to_prefix); }
17+
}
18+
19+
public string AsA
20+
{
21+
get { return Narrative2; }
22+
set { Narrative2 = CleanseProperty(value, As_a_prefix); }
23+
}
24+
25+
public string IWant
26+
{
27+
get { return Narrative3; }
28+
set { Narrative3 = CleanseProperty(value, I_want_prefix); }
29+
}
30+
}
31+
32+
[TestFixture]
33+
[InOrderToStory(
34+
InOrderTo = "do something",
35+
AsA = "programmer",
36+
IWant = "this to work")]
37+
public class CanUseACustomStoryAttribute
38+
{
39+
[Test]
40+
public void When_InOrderTo_is_specified_the_InOrderTo_syntax_is_used()
41+
{
42+
var story = new DummyScenario().BDDfy<CanUseACustomStoryAttribute>();
43+
44+
Assert.That(story.Metadata.Narrative1, Is.EqualTo("In order to do something"));
45+
Assert.That(story.Metadata.Narrative2, Is.EqualTo("As a programmer"));
46+
Assert.That(story.Metadata.Narrative3, Is.EqualTo("I want this to work"));
47+
}
48+
}
49+
}

TestStack.BDDfy.Tests/Stories/StoryClassAndScenarioClassAreTheSame.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ void andTheNarrativeIsReturnedAsExpected()
4242
{
4343
var expectedNarrative = (StoryAttribute)typeof(StoryAsScenario).GetCustomAttributes(typeof(StoryAttribute), false).First();
4444
Assert.That(_story.Metadata, Is.Not.Null);
45-
Assert.That(_story.Metadata.AsA, Is.EqualTo(expectedNarrative.AsA));
46-
Assert.That(_story.Metadata.IWant, Is.EqualTo(expectedNarrative.IWant));
47-
Assert.That(_story.Metadata.SoThat, Is.EqualTo(expectedNarrative.SoThat));
45+
Assert.That(_story.Metadata.Narrative1, Is.EqualTo(expectedNarrative.AsA));
46+
Assert.That(_story.Metadata.Narrative2, Is.EqualTo(expectedNarrative.IWant));
47+
Assert.That(_story.Metadata.Narrative3, Is.EqualTo(expectedNarrative.SoThat));
4848
}
4949

5050
[Test]

TestStack.BDDfy.Tests/Stories/WhenStoryAttibuteMissesAsATextInAsAProperty.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ public void Then_it_is_injected_by_BDDfy()
1414
{
1515
var story = new DummyScenario().BDDfy<WhenStoryAttibuteMissesAsATextInAsAProperty>();
1616

17-
Assert.That(story.Metadata.AsA, Is.EqualTo("As a programmer"));
18-
Assert.That(story.Metadata.IWant, Is.EqualTo("I want the missing 'As a' to be added to story metadata"));
19-
Assert.That(story.Metadata.SoThat, Is.EqualTo("So that I don't have to duplicate it on the string"));
17+
Assert.That(story.Metadata.Narrative1, Is.EqualTo("As a programmer"));
18+
Assert.That(story.Metadata.Narrative2, Is.EqualTo("I want the missing 'As a' to be added to story metadata"));
19+
Assert.That(story.Metadata.Narrative3, Is.EqualTo("So that I don't have to duplicate it on the string"));
2020
}
2121
}
2222
}

TestStack.BDDfy.Tests/Stories/WhenStoryAttibuteMissesDuplicateTextsInProperties.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ public void Then_it_is_injected_by_BDDfy()
1414
{
1515
var story = new DummyScenario().BDDfy<WhenStoryAttibuteMissesDuplicateTextsInProperties>();
1616

17-
Assert.That(story.Metadata.AsA, Is.EqualTo("As a programmer"));
18-
Assert.That(story.Metadata.IWant, Is.EqualTo("I want the missing texts to be added to story metadata"));
19-
Assert.That(story.Metadata.SoThat, Is.EqualTo("So that I don't have to duplicate it on the string"));
17+
Assert.That(story.Metadata.Narrative1, Is.EqualTo("As a programmer"));
18+
Assert.That(story.Metadata.Narrative2, Is.EqualTo("I want the missing texts to be added to story metadata"));
19+
Assert.That(story.Metadata.Narrative3, Is.EqualTo("So that I don't have to duplicate it on the string"));
2020
}
2121
}
2222
}

TestStack.BDDfy.Tests/Stories/WhenStoryAttibuteMissesIWantTextInIWantProperty.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ public void Then_it_is_injected_by_BDDfy()
1414
{
1515
var story = new DummyScenario().BDDfy<WhenStoryAttibuteMissesIWantTextInIWantProperty>();
1616

17-
Assert.That(story.Metadata.AsA, Is.EqualTo("As a programmer"));
18-
Assert.That(story.Metadata.IWant, Is.EqualTo("I want the missing 'I want' to be added to story metadata"));
19-
Assert.That(story.Metadata.SoThat, Is.EqualTo("So that I don't have to duplicate it on the string"));
17+
Assert.That(story.Metadata.Narrative1, Is.EqualTo("As a programmer"));
18+
Assert.That(story.Metadata.Narrative2, Is.EqualTo("I want the missing 'I want' to be added to story metadata"));
19+
Assert.That(story.Metadata.Narrative3, Is.EqualTo("So that I don't have to duplicate it on the string"));
2020
}
2121
}
2222
}

TestStack.BDDfy.Tests/Stories/WhenStoryAttibuteMissesSoThatTextInSoThatProperty.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ public void Then_it_is_injected_by_BDDfy()
1414
{
1515
var story = new DummyScenario().BDDfy<WhenStoryAttibuteMissesSoThatTextInSoThatProperty>();
1616

17-
Assert.That(story.Metadata.AsA, Is.EqualTo("As a programmer"));
18-
Assert.That(story.Metadata.IWant, Is.EqualTo("I want the missing 'So that' to be added to story metadata"));
19-
Assert.That(story.Metadata.SoThat, Is.EqualTo("So that I don't have to duplicate it on the string"));
17+
Assert.That(story.Metadata.Narrative1, Is.EqualTo("As a programmer"));
18+
Assert.That(story.Metadata.Narrative2, Is.EqualTo("I want the missing 'So that' to be added to story metadata"));
19+
Assert.That(story.Metadata.Narrative3, Is.EqualTo("So that I don't have to duplicate it on the string"));
2020
}
2121
}
2222
}

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\CanUseACustomStoryAttribute.cs" />
102103
<Compile Include="Stories\WhenStoryAttibuteMissesDuplicateTextsInProperties.cs" />
103104
<Compile Include="Stories\WhenStoryAttibuteMissesSoThatTextInSoThatProperty.cs" />
104105
<Compile Include="Stories\WhenStoryAttibuteMissesIWantTextInIWantProperty.cs" />

TestStack.BDDfy/Reporters/ConsoleReporter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ private static void ReportStoryHeader(Story story)
3838
return;
3939

4040
Console.WriteLine("Story: " + story.Metadata.Title);
41-
Console.WriteLine("\t" + story.Metadata.AsA);
42-
Console.WriteLine("\t" + story.Metadata.IWant);
43-
Console.WriteLine("\t" + story.Metadata.SoThat);
41+
Console.WriteLine("\t" + story.Metadata.Narrative1);
42+
Console.WriteLine("\t" + story.Metadata.Narrative2);
43+
Console.WriteLine("\t" + story.Metadata.Narrative3);
4444
}
4545

4646
static string PrefixWithSpaceIfRequired(Step step)

TestStack.BDDfy/Reporters/Html/HtmlReportBuilder.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,13 @@ private void AddStoryMetadataAndNarrative(Story story)
224224
AddLine(string.Format("<div class='storyTitle'>{0}</div>", story.Metadata.Title));
225225
}
226226

227-
if (story.Metadata != null && !string.IsNullOrEmpty(story.Metadata.AsA))
227+
if (story.Metadata != null && !string.IsNullOrEmpty(story.Metadata.Narrative1))
228228
{
229229
using (OpenTag("<ul class='storyNarrative'>", HtmlTag.ul))
230230
{
231-
AddLine(string.Format("<li>{0}</li>", story.Metadata.AsA));
232-
AddLine(string.Format("<li>{0}</li>", story.Metadata.IWant));
233-
AddLine(string.Format("<li>{0}</li>", story.Metadata.SoThat));
231+
AddLine(string.Format("<li>{0}</li>", story.Metadata.Narrative1));
232+
AddLine(string.Format("<li>{0}</li>", story.Metadata.Narrative2));
233+
AddLine(string.Format("<li>{0}</li>", story.Metadata.Narrative3));
234234
}
235235
}
236236
}

TestStack.BDDfy/Reporters/MarkDown/MarkDownReportBuilder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ public string CreateReport(FileReportModel model)
1313
if (story.Metadata != null)
1414
{
1515
report.AppendLine(string.Format("## Story: {0}", story.Metadata.Title));
16-
report.AppendLine(string.Format(" **{0}** ", story.Metadata.AsA));
17-
report.AppendLine(string.Format(" **{0}** ", story.Metadata.IWant));
18-
report.AppendLine(string.Format(" **{0}** ", story.Metadata.SoThat));
16+
report.AppendLine(string.Format(" **{0}** ", story.Metadata.Narrative1));
17+
report.AppendLine(string.Format(" **{0}** ", story.Metadata.Narrative2));
18+
report.AppendLine(string.Format(" **{0}** ", story.Metadata.Narrative3));
1919
}
2020

2121
report.AppendLine(); // separator

0 commit comments

Comments
 (0)