From 3de9b6d3218cb6179d9cee4c09d6172f79e9eecb Mon Sep 17 00:00:00 2001 From: MehdiK Date: Mon, 10 Mar 2014 20:39:57 +0330 Subject: [PATCH 1/3] Fixed the md report broken test --- .../Processors/Reports/MarkDown/MarkDownReporterSpecs.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/TestStack.BDDfy.Tests/Processors/Reports/MarkDown/MarkDownReporterSpecs.cs b/TestStack.BDDfy.Tests/Processors/Reports/MarkDown/MarkDownReporterSpecs.cs index eb6e771f..e2274518 100644 --- a/TestStack.BDDfy.Tests/Processors/Reports/MarkDown/MarkDownReporterSpecs.cs +++ b/TestStack.BDDfy.Tests/Processors/Reports/MarkDown/MarkDownReporterSpecs.cs @@ -33,8 +33,10 @@ public void ShouldPrintErrorInReportIfProcessingFails() sut.Process(new List()); - _writer.Received().OutputReport("There was an error compiling the markdown report: Error occurred.", - Arg.Any(), Arg.Any()); + _writer.Received().OutputReport( + Arg.Is(s => s.StartsWith("Error occurred.")), + Arg.Any(), + Arg.Any()); } private MarkDownReporter CreateSut() From fd8503660ebab4062d94be7a25321cbf21c593ac Mon Sep 17 00:00:00 2001 From: MehdiK Date: Mon, 10 Mar 2014 20:41:26 +0330 Subject: [PATCH 2/3] injects "As a", "I want" and "So that" into story metadata if missing - fixes #50 --- .../StoryCanBeSpecifiedInReflectiveMode.cs | 2 +- ...StoryAttibuteMissesAsATextInAsAProperty.cs | 23 +++++++++ ...ttibuteMissesDuplicateTextsInProperties.cs | 23 +++++++++ ...yAttibuteMissesIWantTextInIWantProperty.cs | 23 +++++++++ ...ttibuteMissesSoThatTextInSoThatProperty.cs | 23 +++++++++ .../TestStack.BDDfy.Tests.csproj | 4 ++ TestStack.BDDfy/Core/StoryMetaData.cs | 50 ++++++++++++++++--- 7 files changed, 141 insertions(+), 7 deletions(-) create mode 100644 TestStack.BDDfy.Tests/Story/WhenStoryAttibuteMissesAsATextInAsAProperty.cs create mode 100644 TestStack.BDDfy.Tests/Story/WhenStoryAttibuteMissesDuplicateTextsInProperties.cs create mode 100644 TestStack.BDDfy.Tests/Story/WhenStoryAttibuteMissesIWantTextInIWantProperty.cs create mode 100644 TestStack.BDDfy.Tests/Story/WhenStoryAttibuteMissesSoThatTextInSoThatProperty.cs diff --git a/TestStack.BDDfy.Tests/Story/StoryCanBeSpecifiedInReflectiveMode.cs b/TestStack.BDDfy.Tests/Story/StoryCanBeSpecifiedInReflectiveMode.cs index 2dd8bf2c..4fdcd810 100644 --- a/TestStack.BDDfy.Tests/Story/StoryCanBeSpecifiedInReflectiveMode.cs +++ b/TestStack.BDDfy.Tests/Story/StoryCanBeSpecifiedInReflectiveMode.cs @@ -7,7 +7,7 @@ namespace TestStack.BDDfy.Tests.Story public class StoryCanBeSpecifiedInReflectiveMode { [Test] - public void Verift() + public void Verify() { var story = this.BDDfy(); diff --git a/TestStack.BDDfy.Tests/Story/WhenStoryAttibuteMissesAsATextInAsAProperty.cs b/TestStack.BDDfy.Tests/Story/WhenStoryAttibuteMissesAsATextInAsAProperty.cs new file mode 100644 index 00000000..e3e4d16b --- /dev/null +++ b/TestStack.BDDfy.Tests/Story/WhenStoryAttibuteMissesAsATextInAsAProperty.cs @@ -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(); + + 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")); + } + } +} \ No newline at end of file diff --git a/TestStack.BDDfy.Tests/Story/WhenStoryAttibuteMissesDuplicateTextsInProperties.cs b/TestStack.BDDfy.Tests/Story/WhenStoryAttibuteMissesDuplicateTextsInProperties.cs new file mode 100644 index 00000000..0ca56fd6 --- /dev/null +++ b/TestStack.BDDfy.Tests/Story/WhenStoryAttibuteMissesDuplicateTextsInProperties.cs @@ -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(); + + 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")); + } + } +} \ No newline at end of file diff --git a/TestStack.BDDfy.Tests/Story/WhenStoryAttibuteMissesIWantTextInIWantProperty.cs b/TestStack.BDDfy.Tests/Story/WhenStoryAttibuteMissesIWantTextInIWantProperty.cs new file mode 100644 index 00000000..ca6a9161 --- /dev/null +++ b/TestStack.BDDfy.Tests/Story/WhenStoryAttibuteMissesIWantTextInIWantProperty.cs @@ -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(); + + 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")); + } + } +} \ No newline at end of file diff --git a/TestStack.BDDfy.Tests/Story/WhenStoryAttibuteMissesSoThatTextInSoThatProperty.cs b/TestStack.BDDfy.Tests/Story/WhenStoryAttibuteMissesSoThatTextInSoThatProperty.cs new file mode 100644 index 00000000..36095e20 --- /dev/null +++ b/TestStack.BDDfy.Tests/Story/WhenStoryAttibuteMissesSoThatTextInSoThatProperty.cs @@ -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(); + + 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")); + } + } +} \ No newline at end of file diff --git a/TestStack.BDDfy.Tests/TestStack.BDDfy.Tests.csproj b/TestStack.BDDfy.Tests/TestStack.BDDfy.Tests.csproj index 303ad651..3922d4c5 100644 --- a/TestStack.BDDfy.Tests/TestStack.BDDfy.Tests.csproj +++ b/TestStack.BDDfy.Tests/TestStack.BDDfy.Tests.csproj @@ -99,6 +99,10 @@ + + + + diff --git a/TestStack.BDDfy/Core/StoryMetaData.cs b/TestStack.BDDfy/Core/StoryMetaData.cs index 3ceab937..0e4abdef 100644 --- a/TestStack.BDDfy/Core/StoryMetaData.cs +++ b/TestStack.BDDfy/Core/StoryMetaData.cs @@ -4,6 +4,11 @@ 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 "; + // ReSharper restore InconsistentNaming + public StoryMetaData(Type storyType, StoryAttribute storyAttribute) { var title = storyAttribute.Title; @@ -13,9 +18,9 @@ public StoryMetaData(Type storyType, StoryAttribute storyAttribute) Type = storyType; Title = title; - AsA = storyAttribute.AsA; - IWant = storyAttribute.IWant; - SoThat = storyAttribute.SoThat; + SetAsA(storyAttribute.AsA); + SetIWant(storyAttribute.IWant); + SetSoThat(storyAttribute.SoThat); } public StoryMetaData(Type storyType, string asA, string iWant, string soThat, string storyTitle = null) @@ -23,9 +28,42 @@ public StoryMetaData(Type storyType, string asA, string iWant, string soThat, st Title = storyTitle ?? NetToString.Convert(storyType.Name); Type = storyType; - AsA = asA; - IWant = iWant; - SoThat = soThat; + SetAsA(asA); + SetIWant(iWant); + SetSoThat(soThat); + } + + void SetAsA(string asA) + { + if (string.IsNullOrWhiteSpace(asA)) + return; + + if (!asA.StartsWith("As a", StringComparison.OrdinalIgnoreCase)) + AsA = "As a "; + + AsA += asA; + } + + void SetIWant(string iWant) + { + if (string.IsNullOrWhiteSpace(iWant)) + return; + + if (!iWant.StartsWith(I_want_prefix, StringComparison.OrdinalIgnoreCase)) + IWant = I_want_prefix; + + IWant += iWant; + } + + void SetSoThat(string soThat) + { + if(string.IsNullOrWhiteSpace(soThat)) + return; + + if (!soThat.StartsWith(So_that_prefix, StringComparison.OrdinalIgnoreCase)) + SoThat = So_that_prefix; + + SoThat += soThat; } public Type Type { get; private set; } From 93a143c837b3ef7c5241005a4b443d64033068c8 Mon Sep 17 00:00:00 2001 From: MehdiK Date: Mon, 10 Mar 2014 21:04:04 +0330 Subject: [PATCH 3/3] refactoring out the duplicate code --- TestStack.BDDfy/Core/StoryMetaData.cs | 55 +++++++++------------------ 1 file changed, 19 insertions(+), 36 deletions(-) diff --git a/TestStack.BDDfy/Core/StoryMetaData.cs b/TestStack.BDDfy/Core/StoryMetaData.cs index 0e4abdef..561c9e0a 100644 --- a/TestStack.BDDfy/Core/StoryMetaData.cs +++ b/TestStack.BDDfy/Core/StoryMetaData.cs @@ -1,12 +1,14 @@ 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 "; + // 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) @@ -18,9 +20,9 @@ public StoryMetaData(Type storyType, StoryAttribute storyAttribute) Type = storyType; Title = title; - SetAsA(storyAttribute.AsA); - SetIWant(storyAttribute.IWant); - SetSoThat(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) @@ -28,42 +30,23 @@ public StoryMetaData(Type storyType, string asA, string iWant, string soThat, st Title = storyTitle ?? NetToString.Convert(storyType.Name); Type = storyType; - SetAsA(asA); - SetIWant(iWant); - SetSoThat(soThat); + AsA = CleanseProperty(asA, As_a_prefix); + IWant = CleanseProperty(iWant, I_want_prefix); + SoThat = CleanseProperty(soThat, So_that_prefix); } - void SetAsA(string asA) + string CleanseProperty(string text, string prefix) { - if (string.IsNullOrWhiteSpace(asA)) - return; + var property = new StringBuilder(); - if (!asA.StartsWith("As a", StringComparison.OrdinalIgnoreCase)) - AsA = "As a "; + if (string.IsNullOrWhiteSpace(text)) + return null; - AsA += asA; - } - - void SetIWant(string iWant) - { - if (string.IsNullOrWhiteSpace(iWant)) - return; - - if (!iWant.StartsWith(I_want_prefix, StringComparison.OrdinalIgnoreCase)) - IWant = I_want_prefix; - - IWant += iWant; - } - - void SetSoThat(string soThat) - { - if(string.IsNullOrWhiteSpace(soThat)) - return; - - if (!soThat.StartsWith(So_that_prefix, StringComparison.OrdinalIgnoreCase)) - SoThat = So_that_prefix; + if (!text.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)) + property.AppendFormat("{0} ", prefix); - SoThat += soThat; + property.Append(text); + return property.ToString(); } public Type Type { get; private set; }