Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ public void ShouldPrintErrorInReportIfProcessingFails()

sut.Process(new List<Core.Story>());

_writer.Received().OutputReport("There was an error compiling the markdown report: Error occurred.",
Arg.Any<string>(), Arg.Any<string>());
_writer.Received().OutputReport(
Arg.Is<string>(s => s.StartsWith("Error occurred.")),
Arg.Any<string>(),
Arg.Any<string>());
}

private MarkDownReporter CreateSut()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace TestStack.BDDfy.Tests.Story
public class StoryCanBeSpecifiedInReflectiveMode
{
[Test]
public void Verift()
public void Verify()
{
var story = this.BDDfy<SharedStoryNotion>();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using NUnit.Framework;
using TestStack.BDDfy.Core;

namespace TestStack.BDDfy.Tests.Story
{
[TestFixture]
[Story(
AsA = "programmer",
IWant = "I want the missing 'As a' to be added to story metadata",
SoThat = "So that I don't have to duplicate it on the string")]
public class WhenStoryAttibuteMissesAsATextInAsAProperty
{
[Test]
public void Then_it_is_injected_by_BDDfy()
{
var story = new DummyScenario().BDDfy<WhenStoryAttibuteMissesAsATextInAsAProperty>();

Assert.That(story.MetaData.AsA, Is.EqualTo("As a programmer"));
Assert.That(story.MetaData.IWant, Is.EqualTo("I want the missing 'As a' to be added to story metadata"));
Assert.That(story.MetaData.SoThat, Is.EqualTo("So that I don't have to duplicate it on the string"));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using NUnit.Framework;
using TestStack.BDDfy.Core;

namespace TestStack.BDDfy.Tests.Story
{
[TestFixture]
[Story(
AsA = "programmer",
IWant = "the missing texts to be added to story metadata",
SoThat = "I don't have to duplicate it on the string")]
public class WhenStoryAttibuteMissesDuplicateTextsInProperties
{
[Test]
public void Then_it_is_injected_by_BDDfy()
{
var story = new DummyScenario().BDDfy<WhenStoryAttibuteMissesDuplicateTextsInProperties>();

Assert.That(story.MetaData.AsA, Is.EqualTo("As a programmer"));
Assert.That(story.MetaData.IWant, Is.EqualTo("I want the missing texts to be added to story metadata"));
Assert.That(story.MetaData.SoThat, Is.EqualTo("So that I don't have to duplicate it on the string"));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using NUnit.Framework;
using TestStack.BDDfy.Core;

namespace TestStack.BDDfy.Tests.Story
{
[TestFixture]
[Story(
AsA = "As a programmer",
IWant = "the missing 'I want' to be added to story metadata",
SoThat = "So that I don't have to duplicate it on the string")]
public class WhenStoryAttibuteMissesIWantTextInIWantProperty
{
[Test]
public void Then_it_is_injected_by_BDDfy()
{
var story = new DummyScenario().BDDfy<WhenStoryAttibuteMissesIWantTextInIWantProperty>();

Assert.That(story.MetaData.AsA, Is.EqualTo("As a programmer"));
Assert.That(story.MetaData.IWant, Is.EqualTo("I want the missing 'I want' to be added to story metadata"));
Assert.That(story.MetaData.SoThat, Is.EqualTo("So that I don't have to duplicate it on the string"));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using NUnit.Framework;
using TestStack.BDDfy.Core;

namespace TestStack.BDDfy.Tests.Story
{
[TestFixture]
[Story(
AsA = "As a programmer",
IWant = "I want the missing 'So that' to be added to story metadata",
SoThat = "I don't have to duplicate it on the string")]
public class WhenStoryAttibuteMissesSoThatTextInSoThatProperty
{
[Test]
public void Then_it_is_injected_by_BDDfy()
{
var story = new DummyScenario().BDDfy<WhenStoryAttibuteMissesSoThatTextInSoThatProperty>();

Assert.That(story.MetaData.AsA, Is.EqualTo("As a programmer"));
Assert.That(story.MetaData.IWant, Is.EqualTo("I want the missing 'So that' to be added to story metadata"));
Assert.That(story.MetaData.SoThat, Is.EqualTo("So that I don't have to duplicate it on the string"));
}
}
}
4 changes: 4 additions & 0 deletions TestStack.BDDfy.Tests/TestStack.BDDfy.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@
<Compile Include="Scanner\WhenCombinationOfExecutableAttributeAndMethodNamingConventionIsUsed.cs" />
<Compile Include="Scanner\WhenStepsAreDefinedInABaseClass.cs" />
<Compile Include="Scanner\WhenStepsReturnTheirText.cs" />
<Compile Include="Story\WhenStoryAttibuteMissesDuplicateTextsInProperties.cs" />
<Compile Include="Story\WhenStoryAttibuteMissesSoThatTextInSoThatProperty.cs" />
<Compile Include="Story\WhenStoryAttibuteMissesIWantTextInIWantProperty.cs" />
<Compile Include="Story\WhenStoryAttibuteMissesAsATextInAsAProperty.cs" />
<Compile Include="Story\StoryCanBeSpecifiedInReflectiveMode.cs" />
<Compile Include="Story\DummyScenario.cs" />
<Compile Include="Story\SharedStoryNotion.cs" />
Expand Down
33 changes: 27 additions & 6 deletions TestStack.BDDfy/Core/StoryMetaData.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
using System;
using System.Text;

namespace TestStack.BDDfy.Core
{
public class StoryMetaData
{
// ReSharper disable InconsistentNaming
private const string I_want_prefix = "I want";
private const string So_that_prefix = "So that";
private const string As_a_prefix = "As a";
// ReSharper restore InconsistentNaming

public StoryMetaData(Type storyType, StoryAttribute storyAttribute)
{
var title = storyAttribute.Title;
Expand All @@ -13,19 +20,33 @@ public StoryMetaData(Type storyType, StoryAttribute storyAttribute)
Type = storyType;
Title = title;

AsA = storyAttribute.AsA;
IWant = storyAttribute.IWant;
SoThat = storyAttribute.SoThat;
AsA = CleanseProperty(storyAttribute.AsA, As_a_prefix);
IWant= CleanseProperty(storyAttribute.IWant, I_want_prefix);
SoThat = CleanseProperty(storyAttribute.SoThat, So_that_prefix);
}

public StoryMetaData(Type storyType, string asA, string iWant, string soThat, string storyTitle = null)
{
Title = storyTitle ?? NetToString.Convert(storyType.Name);
Type = storyType;

AsA = asA;
IWant = iWant;
SoThat = soThat;
AsA = CleanseProperty(asA, As_a_prefix);
IWant = CleanseProperty(iWant, I_want_prefix);
SoThat = CleanseProperty(soThat, So_that_prefix);
}

string CleanseProperty(string text, string prefix)
{
var property = new StringBuilder();

if (string.IsNullOrWhiteSpace(text))
return null;

if (!text.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
property.AppendFormat("{0} ", prefix);

property.Append(text);
return property.ToString();
}

public Type Type { get; private set; }
Expand Down