Skip to content

Commit 29a22a8

Browse files
committed
Merge pull request #209 from liammclennan/extra-story-metadata
Extra story metadata
2 parents 2da3f61 + 47aeab0 commit 29a22a8

File tree

9 files changed

+69
-7
lines changed

9 files changed

+69
-7
lines changed

Samples/TestStack.BDDfy.Samples/Atm/AccountHolderWithdrawsCash.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ namespace TestStack.BDDfy.Samples.Atm
66
[Story(
77
AsA = "As an Account Holder",
88
IWant = "I want to withdraw cash from an ATM",
9-
SoThat = "So that I can get money when the bank is closed")]
9+
SoThat = "So that I can get money when the bank is closed",
10+
ImageUri = "https://upload.wikimedia.org/wikipedia/commons/d/d3/49024-SOS-ATM.JPG",
11+
StoryUri = "http://google.com")]
1012
public class AccountHolderWithdrawsCash
1113
{
1214
private const string GivenTheAccountBalanceIsTitleTemplate = "Given the account balance is ${0}";

Samples/TestStack.BDDfy.Samples/BDDfy_Rocks.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ namespace TestStack.BDDfy.Samples
55
[Story(
66
AsA = "As a .Net programmer",
77
IWant = "I want to use BDDfy",
8-
SoThat = "So that BDD becomes easy and fun")]
8+
SoThat = "So that BDD becomes easy and fun",
9+
ImageUri = "https://upload.wikimedia.org/wikipedia/commons/7/72/DirkvdM_rocks.jpg",
10+
StoryUri = "https://en.wikipedia.org/wiki/Rock_%28geology%29")]
911
public class BDDfy_Rocks
1012
{
1113
void Given_I_have_not_used_BDDfy_before()
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Xunit;
7+
using Shouldly;
8+
9+
namespace TestStack.BDDfy.Tests.Stories
10+
{
11+
[Story(
12+
AsA = "programmer",
13+
IWant = "to attach an uri and image metadata to a story",
14+
SoThat = "my output report communicates better to my stakeholders",
15+
StoryUri = "http://teststoryuri.com.au",
16+
ImageUri = "http://teststoryuri.com.au/storyimg.png")]
17+
public class WhenAStoryHasUriAndImageMetadata
18+
{
19+
[Fact]
20+
public void Then_it_is_injected_by_BDDfy()
21+
{
22+
var story = new DummyScenario().BDDfy<WhenAStoryHasUriAndImageMetadata>();
23+
story.Metadata.StoryUri.ShouldBe("http://teststoryuri.com.au");
24+
story.Metadata.ImageUri.ShouldBe("http://teststoryuri.com.au/storyimg.png");
25+
}
26+
}
27+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
<Compile Include="Scanner\ReflectiveScanner\WhenStepsAreDefinedInABaseClass.cs" />
137137
<Compile Include="Scanner\ReflectiveScanner\WhenStepsReturnTheirText.cs" />
138138
<Compile Include="Stories\CanUseACustomStoryAttribute.cs" />
139+
<Compile Include="Stories\WhenAStoryHasUriAndImageMetadata.cs" />
139140
<Compile Include="Stories\WhenStoryAttibuteMissesDuplicateTextsInProperties.cs" />
140141
<Compile Include="Stories\WhenStoryAttibuteMissesSoThatTextInSoThatProperty.cs" />
141142
<Compile Include="Stories\WhenStoryAttibuteMissesIWantTextInIWantProperty.cs" />

TestStack.BDDfy/Reporters/Html/ClassicReportBuilder.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,16 @@ private void AddStoryMetadataAndNarrative(Story story)
316316
{
317317
AddLine(story.Metadata == null
318318
? string.Format("<div class='namespaceName'>{0}</div>", story.Namespace)
319-
: string.Format("<div class='storyTitle'>{0}{1}</div>", story.Metadata.TitlePrefix, story.Metadata.Title));
320-
319+
: string.Format("<div class='storyTitle'>{0}</div>",
320+
string.IsNullOrWhiteSpace(story.Metadata.StoryUri)
321+
? story.Metadata.TitlePrefix + story.Metadata.Title
322+
: string.Format("<a href='{0}'>{1}{2}</a>", story.Metadata.StoryUri, story.Metadata.TitlePrefix, story.Metadata.Title)));
323+
324+
if (story.Metadata != null && !string.IsNullOrWhiteSpace(story.Metadata.ImageUri))
325+
{
326+
AddLine(string.Format("<img class='storyImg' src='{0}' alt='Image for {1}{2}'/>", story.Metadata.ImageUri, story.Metadata.TitlePrefix, story.Metadata.Title));
327+
}
328+
321329
if (story.Metadata == null || string.IsNullOrEmpty(story.Metadata.Narrative1))
322330
return;
323331

TestStack.BDDfy/Reporters/Html/MetroReportBuilder.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,20 @@ private void AddStoryMetadataAndNarrative(Story story)
331331
{
332332
AddLine(story.Metadata == null
333333
? string.Format("<h3 class='namespaceName'>{0}</h3>", story.Namespace)
334-
: string.Format("<h3 class='storyTitle'>{0}{1}</h3>", story.Metadata.TitlePrefix, story.Metadata.Title));
334+
: string.Format("<h3 class='storyTitle'>{0}</h3>",
335+
string.IsNullOrWhiteSpace(story.Metadata.StoryUri)
336+
? story.Metadata.TitlePrefix + story.Metadata.Title
337+
: string.Format("<a href='{0}'>{1}{2}</a>", story.Metadata.StoryUri, story.Metadata.TitlePrefix, story.Metadata.Title)));
338+
339+
if (story.Metadata != null && !string.IsNullOrWhiteSpace(story.Metadata.ImageUri))
340+
{
341+
AddLine(string.Format("<img class='storyImg' src='{0}' alt='Image for {1}{2}'/>", story.Metadata.ImageUri, story.Metadata.TitlePrefix, story.Metadata.Title));
342+
}
335343

336344
if (story.Metadata == null || string.IsNullOrEmpty(story.Metadata.Narrative1))
337345
return;
338346

347+
339348
using (OpenTag("<ul class='storyNarrative'>", HtmlTag.ul))
340349
{
341350
AddLine(string.Format("<li>{0}</li>", story.Metadata.Narrative1));

TestStack.BDDfy/Reporters/Html/Scripts/metro.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,3 +894,9 @@ code {
894894
border: 1px solid #d0d0d0;
895895
display: inline-block;
896896
}
897+
898+
.storyImg {
899+
max-width:600px;
900+
max-height:400px;
901+
margin: 10px;
902+
}

TestStack.BDDfy/Scanners/StoryMetadata.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ namespace TestStack.BDDfy
66
public class StoryMetadata
77
{
88
public StoryMetadata(Type storyType, StoryNarrativeAttribute narrative)
9-
: this(storyType, narrative.Narrative1, narrative.Narrative2, narrative.Narrative3, narrative.Title, narrative.TitlePrefix)
9+
: this(storyType, narrative.Narrative1, narrative.Narrative2, narrative.Narrative3, narrative.Title, narrative.TitlePrefix, narrative.ImageUri, narrative.StoryUri)
1010
{
1111
}
1212

13-
public StoryMetadata(Type storyType, string narrative1, string narrative2, string narrative3, string title = null, string titlePrefix = null)
13+
public StoryMetadata(Type storyType, string narrative1, string narrative2, string narrative3, string title = null, string titlePrefix = null, string imageUri = null, string storyUri = null)
1414
{
1515
Title = title ?? Configurator.Scanners.Humanize(storyType.Name);
1616
TitlePrefix = titlePrefix ?? "Story: ";
@@ -19,6 +19,9 @@ public StoryMetadata(Type storyType, string narrative1, string narrative2, strin
1919
Narrative1 = narrative1;
2020
Narrative2 = narrative2;
2121
Narrative3 = narrative3;
22+
23+
ImageUri = imageUri;
24+
StoryUri = storyUri;
2225
}
2326

2427
public Type Type { get; private set; }
@@ -27,5 +30,7 @@ public StoryMetadata(Type storyType, string narrative1, string narrative2, strin
2730
public string Narrative1 { get; private set; }
2831
public string Narrative2 { get; private set; }
2932
public string Narrative3 { get; private set; }
33+
public string ImageUri { get; private set; }
34+
public string StoryUri { get; private set; }
3035
}
3136
}

TestStack.BDDfy/StoryNarrativeAttribute.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ public class StoryNarrativeAttribute : Attribute
1111
public string Narrative1 { get; set; }
1212
public string Narrative2 { get; set; }
1313
public string Narrative3 { get; set; }
14+
public string StoryUri { get; set; } // link to story in task management system
15+
public string ImageUri { get; set; } // image to display for the story
1416

1517
protected string CleanseProperty(string text, string prefix)
1618
{

0 commit comments

Comments
 (0)