diff --git a/TestStack.BDDfy.Tests/Stories/CanUseACustomStoryAttribute.cs b/TestStack.BDDfy.Tests/Stories/CanUseACustomStoryAttribute.cs new file mode 100644 index 00000000..b5540ec0 --- /dev/null +++ b/TestStack.BDDfy.Tests/Stories/CanUseACustomStoryAttribute.cs @@ -0,0 +1,49 @@ +using NUnit.Framework; + +namespace TestStack.BDDfy.Tests.Stories +{ + class InOrderToStoryAttribute : StoryNarrativeAttribute + { + // ReSharper disable InconsistentNaming + private const string As_a_prefix = "As a"; + private const string In_order_to_prefix = "In order to"; + private const string I_want_prefix = "I want"; + // ReSharper restore InconsistentNaming + + public string InOrderTo + { + get { return Narrative1; } + set { Narrative1 = CleanseProperty(value, In_order_to_prefix); } + } + + public string AsA + { + get { return Narrative2; } + set { Narrative2 = CleanseProperty(value, As_a_prefix); } + } + + public string IWant + { + get { return Narrative3; } + set { Narrative3 = CleanseProperty(value, I_want_prefix); } + } + } + + [TestFixture] + [InOrderToStory( + InOrderTo = "do something", + AsA = "programmer", + IWant = "this to work")] + public class CanUseACustomStoryAttribute + { + [Test] + public void When_InOrderTo_is_specified_the_InOrderTo_syntax_is_used() + { + var story = new DummyScenario().BDDfy(); + + Assert.That(story.Metadata.Narrative1, Is.EqualTo("In order to do something")); + Assert.That(story.Metadata.Narrative2, Is.EqualTo("As a programmer")); + Assert.That(story.Metadata.Narrative3, Is.EqualTo("I want this to work")); + } + } +} diff --git a/TestStack.BDDfy.Tests/Stories/StoryClassAndScenarioClassAreTheSame.cs b/TestStack.BDDfy.Tests/Stories/StoryClassAndScenarioClassAreTheSame.cs index 6f9b42d2..de95a933 100644 --- a/TestStack.BDDfy.Tests/Stories/StoryClassAndScenarioClassAreTheSame.cs +++ b/TestStack.BDDfy.Tests/Stories/StoryClassAndScenarioClassAreTheSame.cs @@ -42,9 +42,9 @@ void andTheNarrativeIsReturnedAsExpected() { var expectedNarrative = (StoryAttribute)typeof(StoryAsScenario).GetCustomAttributes(typeof(StoryAttribute), false).First(); Assert.That(_story.Metadata, Is.Not.Null); - Assert.That(_story.Metadata.AsA, Is.EqualTo(expectedNarrative.AsA)); - Assert.That(_story.Metadata.IWant, Is.EqualTo(expectedNarrative.IWant)); - Assert.That(_story.Metadata.SoThat, Is.EqualTo(expectedNarrative.SoThat)); + Assert.That(_story.Metadata.Narrative1, Is.EqualTo(expectedNarrative.AsA)); + Assert.That(_story.Metadata.Narrative2, Is.EqualTo(expectedNarrative.IWant)); + Assert.That(_story.Metadata.Narrative3, Is.EqualTo(expectedNarrative.SoThat)); } [Test] diff --git a/TestStack.BDDfy.Tests/Stories/WhenStoryAttibuteMissesAsATextInAsAProperty.cs b/TestStack.BDDfy.Tests/Stories/WhenStoryAttibuteMissesAsATextInAsAProperty.cs index 953b4312..dcc58921 100644 --- a/TestStack.BDDfy.Tests/Stories/WhenStoryAttibuteMissesAsATextInAsAProperty.cs +++ b/TestStack.BDDfy.Tests/Stories/WhenStoryAttibuteMissesAsATextInAsAProperty.cs @@ -14,9 +14,9 @@ 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")); + Assert.That(story.Metadata.Narrative1, Is.EqualTo("As a programmer")); + Assert.That(story.Metadata.Narrative2, Is.EqualTo("I want the missing 'As a' to be added to story metadata")); + Assert.That(story.Metadata.Narrative3, 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/Stories/WhenStoryAttibuteMissesDuplicateTextsInProperties.cs b/TestStack.BDDfy.Tests/Stories/WhenStoryAttibuteMissesDuplicateTextsInProperties.cs index ec698cf4..b6e84a08 100644 --- a/TestStack.BDDfy.Tests/Stories/WhenStoryAttibuteMissesDuplicateTextsInProperties.cs +++ b/TestStack.BDDfy.Tests/Stories/WhenStoryAttibuteMissesDuplicateTextsInProperties.cs @@ -14,9 +14,9 @@ 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")); + Assert.That(story.Metadata.Narrative1, Is.EqualTo("As a programmer")); + Assert.That(story.Metadata.Narrative2, Is.EqualTo("I want the missing texts to be added to story metadata")); + Assert.That(story.Metadata.Narrative3, 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/Stories/WhenStoryAttibuteMissesIWantTextInIWantProperty.cs b/TestStack.BDDfy.Tests/Stories/WhenStoryAttibuteMissesIWantTextInIWantProperty.cs index 55d9900a..cfc88b34 100644 --- a/TestStack.BDDfy.Tests/Stories/WhenStoryAttibuteMissesIWantTextInIWantProperty.cs +++ b/TestStack.BDDfy.Tests/Stories/WhenStoryAttibuteMissesIWantTextInIWantProperty.cs @@ -14,9 +14,9 @@ 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")); + Assert.That(story.Metadata.Narrative1, Is.EqualTo("As a programmer")); + Assert.That(story.Metadata.Narrative2, Is.EqualTo("I want the missing 'I want' to be added to story metadata")); + Assert.That(story.Metadata.Narrative3, 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/Stories/WhenStoryAttibuteMissesSoThatTextInSoThatProperty.cs b/TestStack.BDDfy.Tests/Stories/WhenStoryAttibuteMissesSoThatTextInSoThatProperty.cs index 0fd04b70..2ed00999 100644 --- a/TestStack.BDDfy.Tests/Stories/WhenStoryAttibuteMissesSoThatTextInSoThatProperty.cs +++ b/TestStack.BDDfy.Tests/Stories/WhenStoryAttibuteMissesSoThatTextInSoThatProperty.cs @@ -14,9 +14,9 @@ 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")); + Assert.That(story.Metadata.Narrative1, Is.EqualTo("As a programmer")); + Assert.That(story.Metadata.Narrative2, Is.EqualTo("I want the missing 'So that' to be added to story metadata")); + Assert.That(story.Metadata.Narrative3, 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 d27090bf..cb27129d 100644 --- a/TestStack.BDDfy.Tests/TestStack.BDDfy.Tests.csproj +++ b/TestStack.BDDfy.Tests/TestStack.BDDfy.Tests.csproj @@ -99,6 +99,7 @@ + diff --git a/TestStack.BDDfy/Reporters/ConsoleReporter.cs b/TestStack.BDDfy/Reporters/ConsoleReporter.cs index aad89f1e..2713be34 100644 --- a/TestStack.BDDfy/Reporters/ConsoleReporter.cs +++ b/TestStack.BDDfy/Reporters/ConsoleReporter.cs @@ -38,9 +38,9 @@ private static void ReportStoryHeader(Story story) return; Console.WriteLine("Story: " + story.Metadata.Title); - Console.WriteLine("\t" + story.Metadata.AsA); - Console.WriteLine("\t" + story.Metadata.IWant); - Console.WriteLine("\t" + story.Metadata.SoThat); + Console.WriteLine("\t" + story.Metadata.Narrative1); + Console.WriteLine("\t" + story.Metadata.Narrative2); + Console.WriteLine("\t" + story.Metadata.Narrative3); } static string PrefixWithSpaceIfRequired(Step step) diff --git a/TestStack.BDDfy/Reporters/Html/HtmlReportBuilder.cs b/TestStack.BDDfy/Reporters/Html/HtmlReportBuilder.cs index 8638677f..85730da4 100644 --- a/TestStack.BDDfy/Reporters/Html/HtmlReportBuilder.cs +++ b/TestStack.BDDfy/Reporters/Html/HtmlReportBuilder.cs @@ -224,13 +224,13 @@ private void AddStoryMetadataAndNarrative(Story story) AddLine(string.Format("
{0}
", story.Metadata.Title)); } - if (story.Metadata != null && !string.IsNullOrEmpty(story.Metadata.AsA)) + if (story.Metadata != null && !string.IsNullOrEmpty(story.Metadata.Narrative1)) { using (OpenTag("
    ", HtmlTag.ul)) { - AddLine(string.Format("
  • {0}
  • ", story.Metadata.AsA)); - AddLine(string.Format("
  • {0}
  • ", story.Metadata.IWant)); - AddLine(string.Format("
  • {0}
  • ", story.Metadata.SoThat)); + AddLine(string.Format("
  • {0}
  • ", story.Metadata.Narrative1)); + AddLine(string.Format("
  • {0}
  • ", story.Metadata.Narrative2)); + AddLine(string.Format("
  • {0}
  • ", story.Metadata.Narrative3)); } } } diff --git a/TestStack.BDDfy/Reporters/MarkDown/MarkDownReportBuilder.cs b/TestStack.BDDfy/Reporters/MarkDown/MarkDownReportBuilder.cs index 63da78ee..b1fd1b75 100644 --- a/TestStack.BDDfy/Reporters/MarkDown/MarkDownReportBuilder.cs +++ b/TestStack.BDDfy/Reporters/MarkDown/MarkDownReportBuilder.cs @@ -13,9 +13,9 @@ public string CreateReport(FileReportModel model) if (story.Metadata != null) { report.AppendLine(string.Format("## Story: {0}", story.Metadata.Title)); - report.AppendLine(string.Format(" **{0}** ", story.Metadata.AsA)); - report.AppendLine(string.Format(" **{0}** ", story.Metadata.IWant)); - report.AppendLine(string.Format(" **{0}** ", story.Metadata.SoThat)); + report.AppendLine(string.Format(" **{0}** ", story.Metadata.Narrative1)); + report.AppendLine(string.Format(" **{0}** ", story.Metadata.Narrative2)); + report.AppendLine(string.Format(" **{0}** ", story.Metadata.Narrative3)); } report.AppendLine(); // separator diff --git a/TestStack.BDDfy/Scanners/StoryAttributeMetaDataScanner.cs b/TestStack.BDDfy/Scanners/StoryAttributeMetaDataScanner.cs index 2d02b615..d89ea4fb 100644 --- a/TestStack.BDDfy/Scanners/StoryAttributeMetaDataScanner.cs +++ b/TestStack.BDDfy/Scanners/StoryAttributeMetaDataScanner.cs @@ -53,9 +53,9 @@ protected virtual Type GetCandidateStory(object testObject, Type explicitStoryTy return firstFrame.GetMethod().DeclaringType; } - static StoryAttribute GetStoryAttribute(Type candidateStoryType) + static StoryNarrativeAttribute GetStoryAttribute(Type candidateStoryType) { - return (StoryAttribute)candidateStoryType.GetCustomAttributes(typeof(StoryAttribute), true).FirstOrDefault(); + return (StoryNarrativeAttribute)candidateStoryType.GetCustomAttributes(typeof(StoryNarrativeAttribute), true).FirstOrDefault(); } } } \ No newline at end of file diff --git a/TestStack.BDDfy/Scanners/StoryMetadata.cs b/TestStack.BDDfy/Scanners/StoryMetadata.cs index 1df8ae0c..a611193f 100644 --- a/TestStack.BDDfy/Scanners/StoryMetadata.cs +++ b/TestStack.BDDfy/Scanners/StoryMetadata.cs @@ -1,58 +1,28 @@ using System; -using System.Text; namespace TestStack.BDDfy { 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) + public StoryMetadata(Type storyType, StoryNarrativeAttribute narrative) + : this(storyType, narrative.Narrative1, narrative.Narrative2, narrative.Narrative3, narrative.Title) { - var title = storyAttribute.Title; - if (string.IsNullOrEmpty(title)) - title = NetToString.Convert(storyType.Name); - - Type = storyType; - Title = title; - - 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) + public StoryMetadata(Type storyType, string narrative1, string narrative2, string narrative3, string storyTitle = null) { Title = storyTitle ?? NetToString.Convert(storyType.Name); Type = storyType; - 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(); + Narrative1 = narrative1; + Narrative2 = narrative2; + Narrative3 = narrative3; } public Type Type { get; private set; } public string Title { get; private set; } - public string AsA { get; private set; } - public string IWant { get; private set; } - public string SoThat { get; private set; } + public string Narrative1 { get; private set; } + public string Narrative2 { get; private set; } + public string Narrative3 { get; private set; } } } \ No newline at end of file diff --git a/TestStack.BDDfy/StoryAttribute.cs b/TestStack.BDDfy/StoryAttribute.cs index 3341ef90..cc449d2a 100644 --- a/TestStack.BDDfy/StoryAttribute.cs +++ b/TestStack.BDDfy/StoryAttribute.cs @@ -3,11 +3,30 @@ namespace TestStack.BDDfy { [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] - public class StoryAttribute : Attribute + public class StoryAttribute : StoryNarrativeAttribute { - public string Title { get; set; } - public string AsA { get; set; } - public string IWant { get; set; } - public string SoThat { get; set; } + // 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 string AsA + { + get { return Narrative1; } + set { Narrative1 = CleanseProperty(value, As_a_prefix); } + } + + public string IWant + { + get { return Narrative2; } + set { Narrative2 = CleanseProperty(value, I_want_prefix); } + } + + public string SoThat + { + get { return Narrative3; } + set { Narrative3 = CleanseProperty(value, So_that_prefix); } + } } } \ No newline at end of file diff --git a/TestStack.BDDfy/StoryNarrativeAttribute.cs b/TestStack.BDDfy/StoryNarrativeAttribute.cs new file mode 100644 index 00000000..ae82e0e6 --- /dev/null +++ b/TestStack.BDDfy/StoryNarrativeAttribute.cs @@ -0,0 +1,28 @@ +using System; +using System.Text; + +namespace TestStack.BDDfy +{ + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class StoryNarrativeAttribute : Attribute + { + public string Title { get; set; } + public string Narrative1 { get; set; } + public string Narrative2 { get; set; } + public string Narrative3 { get; set; } + + protected 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(); + } + } +} diff --git a/TestStack.BDDfy/TestStack.BDDfy.csproj b/TestStack.BDDfy/TestStack.BDDfy.csproj index 1b346e0c..d2cdc795 100644 --- a/TestStack.BDDfy/TestStack.BDDfy.csproj +++ b/TestStack.BDDfy/TestStack.BDDfy.csproj @@ -152,6 +152,7 @@ +