From 207a804e07a8bb1feb4c952d4f3aa3cb3bc63380 Mon Sep 17 00:00:00 2001 From: Gabriel Palma Date: Mon, 8 Apr 2024 16:40:14 +1000 Subject: [PATCH] Added MSUnit test suite --- .../Features/BookingService.feature | 57 +++ .../Features/BookingService.feature.cs | 346 ++++++++++++++++ .../Features/RequestValidator.feature | 47 +++ .../Features/RequestValidator.feature.cs | 385 ++++++++++++++++++ .../My.Test.Library.MsTest.Unit.Tests.csproj | 27 ++ .../Steps/BookingServiceSteps.cs | 167 ++++++++ .../Steps/RequestValidatorSteps.cs | 124 ++++++ .../My.Test.Library.N.Unit.Tests.csproj | 2 +- .../My.Test.Library.X.Unit.Tests.csproj | 5 - src/6.0/SpecFlowToMarkdownSample.sln | 6 + 10 files changed, 1160 insertions(+), 6 deletions(-) create mode 100644 src/6.0/My.Test.Library.MsTest.Unit.Tests/Features/BookingService.feature create mode 100644 src/6.0/My.Test.Library.MsTest.Unit.Tests/Features/BookingService.feature.cs create mode 100644 src/6.0/My.Test.Library.MsTest.Unit.Tests/Features/RequestValidator.feature create mode 100644 src/6.0/My.Test.Library.MsTest.Unit.Tests/Features/RequestValidator.feature.cs create mode 100644 src/6.0/My.Test.Library.MsTest.Unit.Tests/My.Test.Library.MsTest.Unit.Tests.csproj create mode 100644 src/6.0/My.Test.Library.MsTest.Unit.Tests/Steps/BookingServiceSteps.cs create mode 100644 src/6.0/My.Test.Library.MsTest.Unit.Tests/Steps/RequestValidatorSteps.cs diff --git a/src/6.0/My.Test.Library.MsTest.Unit.Tests/Features/BookingService.feature b/src/6.0/My.Test.Library.MsTest.Unit.Tests/Features/BookingService.feature new file mode 100644 index 0000000..14215e9 --- /dev/null +++ b/src/6.0/My.Test.Library.MsTest.Unit.Tests/Features/BookingService.feature @@ -0,0 +1,57 @@ +Feature: BookingService +Basic booking service that takes a booking request, validates it for correctness, and then attempts to secure the number of tickets against the registered event. + + @validation + Scenario: Invalid request + + Background: an invalid response is returned from the (mocked) request validator interface + Given the request has a validation failure of "Something failed validation" + When the booking request is made + Then the booking request should fail + And the response message should be "Error - Something failed validation" + + @tickets + @event + Scenario: Event cancelled + Given the request is valid + And the request asks for 2 tickets + And the requested event is "Cancelled" + When the booking request is made + Then the booking request should fail + And the response message should be "Error - Event is cancelled" + + @tickets + Scenario: No tickets left + Given the request is valid + And the request asks for 2 tickets + And the requested event has 0 tickets left + When the booking request is made + Then the booking request should fail + And the response message should be "Error - Event is fully booked" + + @tickets + Scenario: Some tickets left + Given the request is valid + And the request asks for 20 tickets + And the requested event has 10 tickets left + When the booking request is made + Then the booking request should succeed + And the response should indicate 10 tickets were purchased + And the response message should be "Partial Success - 10 tickets were purchased" + + @tickets + @happyPath + Scenario: Tickets purchased + Given the request is valid + And the request asks for 5 tickets + And the requested event has 10 tickets left + When the booking request is made + Then the booking request should succeed + And the response should indicate 5 tickets were purchased + And the response message should be "Success - 5 tickets were purchased" + + @event + Scenario: An inconclusive test + Given the request is valid + When the booking request is made + Then the booking test should be inconclusive \ No newline at end of file diff --git a/src/6.0/My.Test.Library.MsTest.Unit.Tests/Features/BookingService.feature.cs b/src/6.0/My.Test.Library.MsTest.Unit.Tests/Features/BookingService.feature.cs new file mode 100644 index 0000000..ab1e752 --- /dev/null +++ b/src/6.0/My.Test.Library.MsTest.Unit.Tests/Features/BookingService.feature.cs @@ -0,0 +1,346 @@ +// ------------------------------------------------------------------------------ +// +// This code was generated by SpecFlow (https://www.specflow.org/). +// SpecFlow Version:3.9.0.0 +// SpecFlow Generator Version:3.9.0.0 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// ------------------------------------------------------------------------------ +#region Designer generated code +#pragma warning disable +namespace My.Test.Library.MsTest.Unit.Tests.Features +{ + using TechTalk.SpecFlow; + using System; + using System.Linq; + + + [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "3.9.0.0")] + [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute()] + public partial class BookingServiceFeature + { + + private static TechTalk.SpecFlow.ITestRunner testRunner; + + private Microsoft.VisualStudio.TestTools.UnitTesting.TestContext _testContext; + + private static string[] featureTags = ((string[])(null)); + +#line 1 "BookingService.feature" +#line hidden + + public virtual Microsoft.VisualStudio.TestTools.UnitTesting.TestContext TestContext + { + get + { + return this._testContext; + } + set + { + this._testContext = value; + } + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.ClassInitializeAttribute()] + public static void FeatureSetup(Microsoft.VisualStudio.TestTools.UnitTesting.TestContext testContext) + { + testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(); + TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Features", "BookingService", "Basic booking service that takes a booking request, validates it for correctness," + + " and then attempts to secure the number of tickets against the registered event." + + "", ProgrammingLanguage.CSharp, featureTags); + testRunner.OnFeatureStart(featureInfo); + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupAttribute()] + public static void FeatureTearDown() + { + testRunner.OnFeatureEnd(); + testRunner = null; + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute()] + public void TestInitialize() + { + if (((testRunner.FeatureContext != null) + && (testRunner.FeatureContext.FeatureInfo.Title != "BookingService"))) + { + global::My.Test.Library.MsTest.Unit.Tests.Features.BookingServiceFeature.FeatureSetup(null); + } + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestCleanupAttribute()] + public void TestTearDown() + { + testRunner.OnScenarioEnd(); + } + + public void ScenarioInitialize(TechTalk.SpecFlow.ScenarioInfo scenarioInfo) + { + testRunner.OnScenarioInitialize(scenarioInfo); + testRunner.ScenarioContext.ScenarioContainer.RegisterInstanceAs(_testContext); + } + + public void ScenarioStart() + { + testRunner.OnScenarioStart(); + } + + public void ScenarioCleanup() + { + testRunner.CollectScenarioErrors(); + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Invalid request")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "BookingService")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestCategoryAttribute("validation")] + public void InvalidRequest() + { + string[] tagsOfScenario = new string[] { + "validation"}; + System.Collections.Specialized.OrderedDictionary argumentsOfScenario = new System.Collections.Specialized.OrderedDictionary(); + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Invalid request", " Background: an invalid response is returned from the (mocked) request validat" + + "or interface", tagsOfScenario, argumentsOfScenario, featureTags); +#line 5 + this.ScenarioInitialize(scenarioInfo); +#line hidden + if ((TagHelper.ContainsIgnoreTag(tagsOfScenario) || TagHelper.ContainsIgnoreTag(featureTags))) + { + testRunner.SkipScenario(); + } + else + { + this.ScenarioStart(); +#line 8 + testRunner.Given("the request has a validation failure of \"Something failed validation\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden +#line 9 + testRunner.When("the booking request is made", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line hidden +#line 10 + testRunner.Then("the booking request should fail", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden +#line 11 + testRunner.And("the response message should be \"Error - Something failed validation\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden + } + this.ScenarioCleanup(); + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Event cancelled")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "BookingService")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestCategoryAttribute("tickets")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestCategoryAttribute("event")] + public void EventCancelled() + { + string[] tagsOfScenario = new string[] { + "tickets", + "event"}; + System.Collections.Specialized.OrderedDictionary argumentsOfScenario = new System.Collections.Specialized.OrderedDictionary(); + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Event cancelled", null, tagsOfScenario, argumentsOfScenario, featureTags); +#line 15 + this.ScenarioInitialize(scenarioInfo); +#line hidden + if ((TagHelper.ContainsIgnoreTag(tagsOfScenario) || TagHelper.ContainsIgnoreTag(featureTags))) + { + testRunner.SkipScenario(); + } + else + { + this.ScenarioStart(); +#line 16 + testRunner.Given("the request is valid", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden +#line 17 + testRunner.And("the request asks for 2 tickets", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden +#line 18 + testRunner.And("the requested event is \"Cancelled\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden +#line 19 + testRunner.When("the booking request is made", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line hidden +#line 20 + testRunner.Then("the booking request should fail", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden +#line 21 + testRunner.And("the response message should be \"Error - Event is cancelled\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden + } + this.ScenarioCleanup(); + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("No tickets left")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "BookingService")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestCategoryAttribute("tickets")] + public void NoTicketsLeft() + { + string[] tagsOfScenario = new string[] { + "tickets"}; + System.Collections.Specialized.OrderedDictionary argumentsOfScenario = new System.Collections.Specialized.OrderedDictionary(); + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("No tickets left", null, tagsOfScenario, argumentsOfScenario, featureTags); +#line 24 + this.ScenarioInitialize(scenarioInfo); +#line hidden + if ((TagHelper.ContainsIgnoreTag(tagsOfScenario) || TagHelper.ContainsIgnoreTag(featureTags))) + { + testRunner.SkipScenario(); + } + else + { + this.ScenarioStart(); +#line 25 + testRunner.Given("the request is valid", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden +#line 26 + testRunner.And("the request asks for 2 tickets", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden +#line 27 + testRunner.And("the requested event has 0 tickets left", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden +#line 28 + testRunner.When("the booking request is made", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line hidden +#line 29 + testRunner.Then("the booking request should fail", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden +#line 30 + testRunner.And("the response message should be \"Error - Event is fully booked\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden + } + this.ScenarioCleanup(); + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Some tickets left")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "BookingService")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestCategoryAttribute("tickets")] + public void SomeTicketsLeft() + { + string[] tagsOfScenario = new string[] { + "tickets"}; + System.Collections.Specialized.OrderedDictionary argumentsOfScenario = new System.Collections.Specialized.OrderedDictionary(); + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Some tickets left", null, tagsOfScenario, argumentsOfScenario, featureTags); +#line 33 + this.ScenarioInitialize(scenarioInfo); +#line hidden + if ((TagHelper.ContainsIgnoreTag(tagsOfScenario) || TagHelper.ContainsIgnoreTag(featureTags))) + { + testRunner.SkipScenario(); + } + else + { + this.ScenarioStart(); +#line 34 + testRunner.Given("the request is valid", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden +#line 35 + testRunner.And("the request asks for 20 tickets", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden +#line 36 + testRunner.And("the requested event has 10 tickets left", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden +#line 37 + testRunner.When("the booking request is made", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line hidden +#line 38 + testRunner.Then("the booking request should succeed", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden +#line 39 + testRunner.And("the response should indicate 10 tickets were purchased", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden +#line 40 + testRunner.And("the response message should be \"Partial Success - 10 tickets were purchased\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden + } + this.ScenarioCleanup(); + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Tickets purchased")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "BookingService")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestCategoryAttribute("tickets")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestCategoryAttribute("happyPath")] + public void TicketsPurchased() + { + string[] tagsOfScenario = new string[] { + "tickets", + "happyPath"}; + System.Collections.Specialized.OrderedDictionary argumentsOfScenario = new System.Collections.Specialized.OrderedDictionary(); + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Tickets purchased", null, tagsOfScenario, argumentsOfScenario, featureTags); +#line 44 + this.ScenarioInitialize(scenarioInfo); +#line hidden + if ((TagHelper.ContainsIgnoreTag(tagsOfScenario) || TagHelper.ContainsIgnoreTag(featureTags))) + { + testRunner.SkipScenario(); + } + else + { + this.ScenarioStart(); +#line 45 + testRunner.Given("the request is valid", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden +#line 46 + testRunner.And("the request asks for 5 tickets", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden +#line 47 + testRunner.And("the requested event has 10 tickets left", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden +#line 48 + testRunner.When("the booking request is made", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line hidden +#line 49 + testRunner.Then("the booking request should succeed", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden +#line 50 + testRunner.And("the response should indicate 5 tickets were purchased", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden +#line 51 + testRunner.And("the response message should be \"Success - 5 tickets were purchased\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden + } + this.ScenarioCleanup(); + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("An inconclusive test")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "BookingService")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestCategoryAttribute("event")] + public void AnInconclusiveTest() + { + string[] tagsOfScenario = new string[] { + "event"}; + System.Collections.Specialized.OrderedDictionary argumentsOfScenario = new System.Collections.Specialized.OrderedDictionary(); + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("An inconclusive test", null, tagsOfScenario, argumentsOfScenario, featureTags); +#line 54 + this.ScenarioInitialize(scenarioInfo); +#line hidden + if ((TagHelper.ContainsIgnoreTag(tagsOfScenario) || TagHelper.ContainsIgnoreTag(featureTags))) + { + testRunner.SkipScenario(); + } + else + { + this.ScenarioStart(); +#line 55 + testRunner.Given("the request is valid", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden +#line 56 + testRunner.When("the booking request is made", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line hidden +#line 57 + testRunner.Then("the booking test should be inconclusive", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden + } + this.ScenarioCleanup(); + } + } +} +#pragma warning restore +#endregion diff --git a/src/6.0/My.Test.Library.MsTest.Unit.Tests/Features/RequestValidator.feature b/src/6.0/My.Test.Library.MsTest.Unit.Tests/Features/RequestValidator.feature new file mode 100644 index 0000000..71160c1 --- /dev/null +++ b/src/6.0/My.Test.Library.MsTest.Unit.Tests/Features/RequestValidator.feature @@ -0,0 +1,47 @@ +Feature: RequestValidator +**This is feature text** which supports markdown +You can find some additional SpecFlow markdown documentation [here](https://docs.specflow.org/projects/specflow-livingdoc/en/latest/Generating/Markdown-and-Embedding-Images.html) +![Image](https://cdn.britannica.com/87/189187-050-C6C16A3B/Smithsonian-Institution-building-Castle-1855.jpg?w=400&h=300&c=crop) + + @validation + Scenario: Invalid booking name + Given a request has been created + And the request has an invalid first name + When the validation request is made + Then the validation request should fail + And the error message should be "Please supply a valid first name" + + @validation + @tickets + Scenario: Invalid tickets requested + Given a request has been created + And the request contains 0 tickets + When the validation request is made + Then the validation request should fail + And the error message should be "Please specify a number of tickets greater than zero" + + Scenario: Various request scenarios + Given a request has been created + And the first name is set to with neither nor being used + And the last name is set to + And the tickets requested are set to + When the validation request is made + Then the validation request should succeed + And there should be no error message + + Examples: + | first_name | last_name | number_of_tickets | unused_variable_1 | unused_variable_2 | + | John | Smith | 10 | 12 | 1 | + | Paul | Jones | 15 | 13 | 1 | + | Mary | Sue | 1 | 14 | 1 | + | Alex | McCain | 1 | 15 | 1 | + | Mary | Jones | 100 | 43 | 1 | + | The | Emperor | 1 | 42 | 1 | + | Cole | Stevens | 42 | 41 | 1 | + | Jack | Smith | 5 | 40 | 1 | + + @tickets + Scenario: An inconclusive test + Given a request has been created + When the validation request is made + Then the validation test should be inconclusive \ No newline at end of file diff --git a/src/6.0/My.Test.Library.MsTest.Unit.Tests/Features/RequestValidator.feature.cs b/src/6.0/My.Test.Library.MsTest.Unit.Tests/Features/RequestValidator.feature.cs new file mode 100644 index 0000000..59ec750 --- /dev/null +++ b/src/6.0/My.Test.Library.MsTest.Unit.Tests/Features/RequestValidator.feature.cs @@ -0,0 +1,385 @@ +// ------------------------------------------------------------------------------ +// +// This code was generated by SpecFlow (https://www.specflow.org/). +// SpecFlow Version:3.9.0.0 +// SpecFlow Generator Version:3.9.0.0 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// ------------------------------------------------------------------------------ +#region Designer generated code +#pragma warning disable +namespace My.Test.Library.MsTest.Unit.Tests.Features +{ + using TechTalk.SpecFlow; + using System; + using System.Linq; + + + [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "3.9.0.0")] + [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute()] + public partial class RequestValidatorFeature + { + + private static TechTalk.SpecFlow.ITestRunner testRunner; + + private Microsoft.VisualStudio.TestTools.UnitTesting.TestContext _testContext; + + private static string[] featureTags = ((string[])(null)); + +#line 1 "RequestValidator.feature" +#line hidden + + public virtual Microsoft.VisualStudio.TestTools.UnitTesting.TestContext TestContext + { + get + { + return this._testContext; + } + set + { + this._testContext = value; + } + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.ClassInitializeAttribute()] + public static void FeatureSetup(Microsoft.VisualStudio.TestTools.UnitTesting.TestContext testContext) + { + testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(); + TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Features", "RequestValidator", @"**This is feature text** which supports markdown +You can find some additional SpecFlow markdown documentation [here](https://docs.specflow.org/projects/specflow-livingdoc/en/latest/Generating/Markdown-and-Embedding-Images.html) +![Image](https://cdn.britannica.com/87/189187-050-C6C16A3B/Smithsonian-Institution-building-Castle-1855.jpg?w=400&h=300&c=crop)", ProgrammingLanguage.CSharp, featureTags); + testRunner.OnFeatureStart(featureInfo); + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupAttribute()] + public static void FeatureTearDown() + { + testRunner.OnFeatureEnd(); + testRunner = null; + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute()] + public void TestInitialize() + { + if (((testRunner.FeatureContext != null) + && (testRunner.FeatureContext.FeatureInfo.Title != "RequestValidator"))) + { + global::My.Test.Library.MsTest.Unit.Tests.Features.RequestValidatorFeature.FeatureSetup(null); + } + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestCleanupAttribute()] + public void TestTearDown() + { + testRunner.OnScenarioEnd(); + } + + public void ScenarioInitialize(TechTalk.SpecFlow.ScenarioInfo scenarioInfo) + { + testRunner.OnScenarioInitialize(scenarioInfo); + testRunner.ScenarioContext.ScenarioContainer.RegisterInstanceAs(_testContext); + } + + public void ScenarioStart() + { + testRunner.OnScenarioStart(); + } + + public void ScenarioCleanup() + { + testRunner.CollectScenarioErrors(); + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Invalid booking name")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "RequestValidator")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestCategoryAttribute("validation")] + public void InvalidBookingName() + { + string[] tagsOfScenario = new string[] { + "validation"}; + System.Collections.Specialized.OrderedDictionary argumentsOfScenario = new System.Collections.Specialized.OrderedDictionary(); + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Invalid booking name", null, tagsOfScenario, argumentsOfScenario, featureTags); +#line 7 + this.ScenarioInitialize(scenarioInfo); +#line hidden + if ((TagHelper.ContainsIgnoreTag(tagsOfScenario) || TagHelper.ContainsIgnoreTag(featureTags))) + { + testRunner.SkipScenario(); + } + else + { + this.ScenarioStart(); +#line 8 + testRunner.Given("a request has been created", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden +#line 9 + testRunner.And("the request has an invalid first name", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden +#line 10 + testRunner.When("the validation request is made", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line hidden +#line 11 + testRunner.Then("the validation request should fail", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden +#line 12 + testRunner.And("the error message should be \"Please supply a valid first name\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden + } + this.ScenarioCleanup(); + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Invalid tickets requested")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "RequestValidator")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestCategoryAttribute("validation")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestCategoryAttribute("tickets")] + public void InvalidTicketsRequested() + { + string[] tagsOfScenario = new string[] { + "validation", + "tickets"}; + System.Collections.Specialized.OrderedDictionary argumentsOfScenario = new System.Collections.Specialized.OrderedDictionary(); + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Invalid tickets requested", null, tagsOfScenario, argumentsOfScenario, featureTags); +#line 16 + this.ScenarioInitialize(scenarioInfo); +#line hidden + if ((TagHelper.ContainsIgnoreTag(tagsOfScenario) || TagHelper.ContainsIgnoreTag(featureTags))) + { + testRunner.SkipScenario(); + } + else + { + this.ScenarioStart(); +#line 17 + testRunner.Given("a request has been created", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden +#line 18 + testRunner.And("the request contains 0 tickets", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden +#line 19 + testRunner.When("the validation request is made", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line hidden +#line 20 + testRunner.Then("the validation request should fail", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden +#line 21 + testRunner.And("the error message should be \"Please specify a number of tickets greater than zero" + + "\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden + } + this.ScenarioCleanup(); + } + + public virtual void VariousRequestScenarios(string first_Name, string last_Name, string number_Of_Tickets, string unused_Variable_1, string unused_Variable_2, string[] exampleTags) + { + string[] tagsOfScenario = exampleTags; + System.Collections.Specialized.OrderedDictionary argumentsOfScenario = new System.Collections.Specialized.OrderedDictionary(); + argumentsOfScenario.Add("first_name", first_Name); + argumentsOfScenario.Add("last_name", last_Name); + argumentsOfScenario.Add("number_of_tickets", number_Of_Tickets); + argumentsOfScenario.Add("unused_variable_1", unused_Variable_1); + argumentsOfScenario.Add("unused_variable_2", unused_Variable_2); + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Various request scenarios", null, tagsOfScenario, argumentsOfScenario, featureTags); +#line 23 + this.ScenarioInitialize(scenarioInfo); +#line hidden + if ((TagHelper.ContainsIgnoreTag(tagsOfScenario) || TagHelper.ContainsIgnoreTag(featureTags))) + { + testRunner.SkipScenario(); + } + else + { + this.ScenarioStart(); +#line 24 + testRunner.Given("a request has been created", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden +#line 25 + testRunner.And(string.Format("the first name is set to {0} with neither {1} nor {2} being used", first_Name, unused_Variable_1, unused_Variable_2), ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden +#line 26 + testRunner.And(string.Format("the last name is set to {0}", last_Name), ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden +#line 27 + testRunner.And(string.Format("the tickets requested are set to {0}", number_Of_Tickets), ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden +#line 28 + testRunner.When("the validation request is made", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line hidden +#line 29 + testRunner.Then("the validation request should succeed", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden +#line 30 + testRunner.And("there should be no error message", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden + } + this.ScenarioCleanup(); + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Various request scenarios: Variant 0")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "RequestValidator")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("VariantName", "Variant 0")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:first_name", "John")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:last_name", "Smith")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:number_of_tickets", "10")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:unused_variable_1", "12")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:unused_variable_2", "1")] + public void VariousRequestScenarios_Variant0() + { +#line 23 + this.VariousRequestScenarios("John", "Smith", "10", "12", "1", ((string[])(null))); +#line hidden + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Various request scenarios: Variant 1")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "RequestValidator")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("VariantName", "Variant 1")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:first_name", "Paul")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:last_name", "Jones")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:number_of_tickets", "15")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:unused_variable_1", "13")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:unused_variable_2", "1")] + public void VariousRequestScenarios_Variant1() + { +#line 23 + this.VariousRequestScenarios("Paul", "Jones", "15", "13", "1", ((string[])(null))); +#line hidden + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Various request scenarios: Variant 2")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "RequestValidator")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("VariantName", "Variant 2")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:first_name", "Mary")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:last_name", "Sue")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:number_of_tickets", "1")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:unused_variable_1", "14")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:unused_variable_2", "1")] + public void VariousRequestScenarios_Variant2() + { +#line 23 + this.VariousRequestScenarios("Mary", "Sue", "1", "14", "1", ((string[])(null))); +#line hidden + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Various request scenarios: Variant 3")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "RequestValidator")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("VariantName", "Variant 3")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:first_name", "Alex")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:last_name", "McCain")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:number_of_tickets", "1")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:unused_variable_1", "15")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:unused_variable_2", "1")] + public void VariousRequestScenarios_Variant3() + { +#line 23 + this.VariousRequestScenarios("Alex", "McCain", "1", "15", "1", ((string[])(null))); +#line hidden + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Various request scenarios: Variant 4")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "RequestValidator")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("VariantName", "Variant 4")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:first_name", "Mary")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:last_name", "Jones")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:number_of_tickets", "100")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:unused_variable_1", "43")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:unused_variable_2", "1")] + public void VariousRequestScenarios_Variant4() + { +#line 23 + this.VariousRequestScenarios("Mary", "Jones", "100", "43", "1", ((string[])(null))); +#line hidden + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Various request scenarios: Variant 5")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "RequestValidator")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("VariantName", "Variant 5")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:first_name", "The")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:last_name", "Emperor")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:number_of_tickets", "1")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:unused_variable_1", "42")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:unused_variable_2", "1")] + public void VariousRequestScenarios_Variant5() + { +#line 23 + this.VariousRequestScenarios("The", "Emperor", "1", "42", "1", ((string[])(null))); +#line hidden + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Various request scenarios: Variant 6")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "RequestValidator")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("VariantName", "Variant 6")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:first_name", "Cole")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:last_name", "Stevens")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:number_of_tickets", "42")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:unused_variable_1", "41")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:unused_variable_2", "1")] + public void VariousRequestScenarios_Variant6() + { +#line 23 + this.VariousRequestScenarios("Cole", "Stevens", "42", "41", "1", ((string[])(null))); +#line hidden + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Various request scenarios: Variant 7")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "RequestValidator")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("VariantName", "Variant 7")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:first_name", "Jack")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:last_name", "Smith")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:number_of_tickets", "5")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:unused_variable_1", "40")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:unused_variable_2", "1")] + public void VariousRequestScenarios_Variant7() + { +#line 23 + this.VariousRequestScenarios("Jack", "Smith", "5", "40", "1", ((string[])(null))); +#line hidden + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("An inconclusive test")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "RequestValidator")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestCategoryAttribute("tickets")] + public void AnInconclusiveTest() + { + string[] tagsOfScenario = new string[] { + "tickets"}; + System.Collections.Specialized.OrderedDictionary argumentsOfScenario = new System.Collections.Specialized.OrderedDictionary(); + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("An inconclusive test", null, tagsOfScenario, argumentsOfScenario, featureTags); +#line 44 + this.ScenarioInitialize(scenarioInfo); +#line hidden + if ((TagHelper.ContainsIgnoreTag(tagsOfScenario) || TagHelper.ContainsIgnoreTag(featureTags))) + { + testRunner.SkipScenario(); + } + else + { + this.ScenarioStart(); +#line 45 + testRunner.Given("a request has been created", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden +#line 46 + testRunner.When("the validation request is made", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line hidden +#line 47 + testRunner.Then("the validation test should be inconclusive", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden + } + this.ScenarioCleanup(); + } + } +} +#pragma warning restore +#endregion diff --git a/src/6.0/My.Test.Library.MsTest.Unit.Tests/My.Test.Library.MsTest.Unit.Tests.csproj b/src/6.0/My.Test.Library.MsTest.Unit.Tests/My.Test.Library.MsTest.Unit.Tests.csproj new file mode 100644 index 0000000..ed1260b --- /dev/null +++ b/src/6.0/My.Test.Library.MsTest.Unit.Tests/My.Test.Library.MsTest.Unit.Tests.csproj @@ -0,0 +1,27 @@ + + + + net6.0 + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/6.0/My.Test.Library.MsTest.Unit.Tests/Steps/BookingServiceSteps.cs b/src/6.0/My.Test.Library.MsTest.Unit.Tests/Steps/BookingServiceSteps.cs new file mode 100644 index 0000000..08e245d --- /dev/null +++ b/src/6.0/My.Test.Library.MsTest.Unit.Tests/Steps/BookingServiceSteps.cs @@ -0,0 +1,167 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using AutoFixture; +using AutoFixture.AutoMoq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using My.Test.Library.Domain.Definition; +using My.Test.Library.Domain.Services; + +namespace My.Test.Library.MsTest.Unit.Tests.Steps +{ + [Binding] + public class BookingServiceSteps + { + private readonly Mock _eventService; + private readonly IFixture _fixture; + private readonly Mock _requestValidator; + private readonly MyBookingService _sut; + private readonly Event _returnedEvent; + private BookingRequest _request; + private BookingResponse _response; + + public BookingServiceSteps() + { + _fixture = new Fixture() + .Customize(new AutoMoqCustomization()); + + _fixture + .Behaviors + .OfType() + .ToList() + .ForEach(b => _fixture.Behaviors.Remove(b)); + + _fixture + .Behaviors + .Add(new OmitOnRecursionBehavior()); + + _eventService = new Mock(); + _requestValidator = new Mock(); + + _returnedEvent = new Event + { + EventCode = Guid.NewGuid(), + StartTime = DateTime.Now.AddHours(10), + EndTime = DateTime.Now.AddHours(11), + Status = EventStatusEnum.Upcoming, + TicketsRemaining = 100 + }; + + _sut = + new MyBookingService( + _eventService.Object, + _requestValidator.Object + ); + } + + [Given(@"the request is valid")] + public void GivenTheRequestIsValid() + { + _request = + _fixture + .Create(); + + _requestValidator + .Setup(o => o.Validate(It.IsAny())) + .Returns( + new ValidationResponse + { + IsValid = true, + Message = null + } + ); + } + + [Given(@"the request has a validation failure of ""(.*)""")] + public void GivenTheRequestHasAValidationFailureOf(string errorMessage) + { + _request = + _fixture + .Create(); + + _requestValidator + .Setup(o => o.Validate(It.IsAny())) + .Returns( + new ValidationResponse + { + IsValid = false, + Message = errorMessage + } + ); + } + + [Given(@"the request asks for (.*) tickets")] + public void GivenTheRequestAsksForTickets(int tickets) + { + _request.NumberOfTickets = tickets; + } + + [Given(@"the requested event has (.*) tickets left")] + public void GivenTheRequestedEventHasTicketsLeft(int tickets) + { + _returnedEvent.TicketsRemaining = tickets; + } + + [When(@"the booking request is made")] + public async Task WhenTheBookingRequestIsMade() + { + _eventService + .Setup(o => o.GetAsync(It.IsAny())) + .ReturnsAsync(_returnedEvent); + + _response = + await + _sut + .ProcessAsync(_request); + } + + [Then(@"the booking request should succeed")] + public void ThenTheBookingRequestShouldSucceed() + { + Assert.IsTrue(_response.IsSuccess); + } + + [Then(@"the booking request should fail")] + public void ThenTheBookingRequestShouldFail() + { + Assert.IsFalse(_response.IsSuccess); + } + + [Then(@"the response message should be ""(.*)""")] + public void ThenTheResponseMessageShouldBe(string expectedErrorMessage) + { + Assert.AreEqual( + expectedErrorMessage, + _response.ResponseMessage + ); + } + + [Then(@"the response should indicate (.*) tickets were purchased")] + public void ThenTheResponseShouldIndicateTicketsWerePurchased(int tickets) + { + Assert.AreEqual( + tickets, + _response.TicketsPurchased + ); + } + + [Given(@"the requested event is ""(.*)""")] + public void GivenTheRequestedEventIs(string eventStatus) + { + var statusValue = + Enum + .Parse( + eventStatus + ); + + _returnedEvent.Status = statusValue; + } + + [Then(@"the booking test should be inconclusive")] + public void ThenTheBookingTestShouldBeInconclusive() + { + ScenarioContext.StepIsPending(); + } + } +} \ No newline at end of file diff --git a/src/6.0/My.Test.Library.MsTest.Unit.Tests/Steps/RequestValidatorSteps.cs b/src/6.0/My.Test.Library.MsTest.Unit.Tests/Steps/RequestValidatorSteps.cs new file mode 100644 index 0000000..b1bdfe4 --- /dev/null +++ b/src/6.0/My.Test.Library.MsTest.Unit.Tests/Steps/RequestValidatorSteps.cs @@ -0,0 +1,124 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using My.Test.Library.Domain.Definition; +using My.Test.Library.Domain.Services; +using TechTalk.SpecFlow.Assist; + +namespace My.Test.Library.MsTest.Unit.Tests.Steps +{ + [Binding] + public class RequestValidatorSteps + { + private const string SkipForTheEmperor = "Emperor"; + + private readonly MyRequestValidator _sut; + private BookingRequest _request; + private ValidationResponse _response; + + public RequestValidatorSteps() + { + _sut = new MyRequestValidator(); + _request = new BookingRequest(); + } + + [Given(@"a request has been created")] + public void GivenARequestHasBeenCreated() + { + _request = + new BookingRequest + { + FirstName = "John", + LastName = "Smith", + EventCode = Guid.NewGuid(), + NumberOfTickets = 2 + }; + } + + [When(@"the validation request is made")] + public void WhenTheValidationRequestIsMade() + { + _response = + _sut + .Validate(_request); + } + + [Then(@"the validation request should fail")] + public void ThenTheValidationRequestShouldFail() + { + Assert.IsFalse(_response.IsValid); + } + + [Then(@"the validation request should succeed")] + public void ThenTheValidationRequestShouldSucceed() + { + Assert.IsTrue(_response.IsValid); + } + + [Then(@"the error message should be ""(.*)""")] + public void ThenTheErrorMessageShouldBe(string expectedErrorMessage) + { + Assert + .AreEqual( + expectedErrorMessage, + _response.Message + ); + } + + [Given(@"the request has an invalid first name")] + public void GivenTheRequestHasAnInvalidFirstName() + { + _request.FirstName = null; + } + + [Given(@"the request contains (.*) tickets")] + public void GivenTheRequestContainsTickets(int tickets) + { + _request.NumberOfTickets = tickets; + } + + [Given(@"a request has been created as follows:")] + public void GivenARequestHasBeenCreatedAsFollows(TableRow table) + { + var request = + table + .CreateInstance(); + + _request = + new BookingRequest + { + FirstName = request.FirstName, + LastName = request.LastName, + EventCode = Guid.NewGuid(), + NumberOfTickets = request.NumberOfTickets + }; + } + + [Then(@"there should be no error message")] + public void ThenThereShouldBeNoErrorMessage() + { + Assert + .IsNull(_response.Message); + } + + [Given(@"the first name is set to (.*) with neither (.*) nor (.*) being used")] + public void GivenTheFirstNameIsSetTo(string value, string unused_1, string unused_2) => _request.FirstName = value; + + [Given(@"the last name is set to (.*)")] + public void GivenTheLastNameIsSetTo(string value) + { + if (value == SkipForTheEmperor) + ScenarioContext.StepIsPending(); + + _request.LastName = value; + } + + [Given(@"the tickets requested are set to (.*)")] + public void GivenTheTicketsRequestedAreSetTo(int value) => _request.NumberOfTickets = value; + + [Then(@"the validation test should be inconclusive")] + public void ThenTheValidationTestShouldBeInconclusive() + { + ScenarioContext.StepIsPending(); + } + } +} \ No newline at end of file diff --git a/src/6.0/My.Test.Library.N.Unit.Tests/My.Test.Library.N.Unit.Tests.csproj b/src/6.0/My.Test.Library.N.Unit.Tests/My.Test.Library.N.Unit.Tests.csproj index 3cede15..0349efe 100644 --- a/src/6.0/My.Test.Library.N.Unit.Tests/My.Test.Library.N.Unit.Tests.csproj +++ b/src/6.0/My.Test.Library.N.Unit.Tests/My.Test.Library.N.Unit.Tests.csproj @@ -9,7 +9,7 @@ - + diff --git a/src/6.0/My.Test.Library.X.Unit.Tests/My.Test.Library.X.Unit.Tests.csproj b/src/6.0/My.Test.Library.X.Unit.Tests/My.Test.Library.X.Unit.Tests.csproj index 071bf89..d2d1a84 100644 --- a/src/6.0/My.Test.Library.X.Unit.Tests/My.Test.Library.X.Unit.Tests.csproj +++ b/src/6.0/My.Test.Library.X.Unit.Tests/My.Test.Library.X.Unit.Tests.csproj @@ -18,11 +18,6 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - diff --git a/src/6.0/SpecFlowToMarkdownSample.sln b/src/6.0/SpecFlowToMarkdownSample.sln index 2c5e62e..3854af9 100644 --- a/src/6.0/SpecFlowToMarkdownSample.sln +++ b/src/6.0/SpecFlowToMarkdownSample.sln @@ -6,6 +6,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "My.Test.Library.N.Unit.Test EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "My.Test.Library.X.Unit.Tests", "My.Test.Library.X.Unit.Tests\My.Test.Library.X.Unit.Tests.csproj", "{1E871503-BBE5-4029-877F-4EC31E2AAF17}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "My.Test.Library.MsTest.Unit.Tests", "My.Test.Library.MsTest.Unit.Tests\My.Test.Library.MsTest.Unit.Tests.csproj", "{FDE2AB8B-FAA9-45A5-A9CB-968B925434E7}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -24,5 +26,9 @@ Global {1E871503-BBE5-4029-877F-4EC31E2AAF17}.Debug|Any CPU.Build.0 = Debug|Any CPU {1E871503-BBE5-4029-877F-4EC31E2AAF17}.Release|Any CPU.ActiveCfg = Release|Any CPU {1E871503-BBE5-4029-877F-4EC31E2AAF17}.Release|Any CPU.Build.0 = Release|Any CPU + {FDE2AB8B-FAA9-45A5-A9CB-968B925434E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FDE2AB8B-FAA9-45A5-A9CB-968B925434E7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FDE2AB8B-FAA9-45A5-A9CB-968B925434E7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FDE2AB8B-FAA9-45A5-A9CB-968B925434E7}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal