Skip to content

Commit ba760c3

Browse files
committed
Add StoryUri and ImageUri to Story metadata so that the report can include a link and image for a story.
1 parent 2da3f61 commit ba760c3

File tree

5 files changed

+28
-4
lines changed

5 files changed

+28
-4
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}";

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)