From fb176b5efa8be5b57e8caa256f879c382c45771e Mon Sep 17 00:00:00 2001 From: Nate Adams Date: Wed, 11 Dec 2019 14:58:57 -0600 Subject: [PATCH 01/15] Implement simple addition test code --- GettingStarted/AddTwoNumbersTogetherSteps.cs | 30 ++++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/GettingStarted/AddTwoNumbersTogetherSteps.cs b/GettingStarted/AddTwoNumbersTogetherSteps.cs index a0159a3..3669120 100644 --- a/GettingStarted/AddTwoNumbersTogetherSteps.cs +++ b/GettingStarted/AddTwoNumbersTogetherSteps.cs @@ -1,4 +1,5 @@ -using System; +using FluentAssertions; +using System; using TechTalk.SpecFlow; namespace GettingStarted @@ -6,22 +7,27 @@ namespace GettingStarted [Binding] public class AddTwoNumbersTogetherSteps { - [Given(@"I have entered the numbers (.*) and (.*)")] - public void GivenIHaveEnteredTheNumbersAnd(int p0, int p1) + int firstNumber; + int secondNumber; + int resultOfAddition; + + [Given(@"I have entered the numbers 1 and 2")] + public void GivenIHaveEnteredTheNumbersOneAndTwo() { - ScenarioContext.Current.Pending(); + firstNumber = 1; + secondNumber = 2; } - - [When(@"I add (.*) and (.*) together")] - public void WhenIAddAndTogether(int p0, int p1) + + [When(@"I add 1 and 2 together")] + public void WhenIAddOneAndTwoTogether() { - ScenarioContext.Current.Pending(); + resultOfAddition = firstNumber + secondNumber; } - - [Then(@"the result should be (.*)")] - public void ThenTheResultShouldBe(int p0) + + [Then(@"the result should be 3")] + public void ThenTheResultShouldBeThree() { - ScenarioContext.Current.Pending(); + resultOfAddition.Should().Be(3); } } } From 0e3228c38ad217ddc106987e4c8c139ecdbc2f31 Mon Sep 17 00:00:00 2001 From: Nate Adams Date: Wed, 11 Dec 2019 15:13:38 -0600 Subject: [PATCH 02/15] Add new scenario to add more numbers --- GettingStarted/1_SimpleStarterTests.feature | 7 +++- .../1_SimpleStarterTests.feature.cs | 40 +++++++++++++++++++ GettingStarted/AddTwoNumbersTogetherSteps.cs | 19 +++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/GettingStarted/1_SimpleStarterTests.feature b/GettingStarted/1_SimpleStarterTests.feature index 2ae5f2b..76db88e 100644 --- a/GettingStarted/1_SimpleStarterTests.feature +++ b/GettingStarted/1_SimpleStarterTests.feature @@ -7,4 +7,9 @@ Scenario: Add two numbers - no variables Given I have entered the numbers 1 and 2 When I add 1 and 2 together - Then the result should be 3 \ No newline at end of file + Then the result should be 3 + +Scenario: Add two different numbers - no variables + Given I have entered the numbers 3 and 5 + When I add 3 and 5 together + Then the result should be 8 \ No newline at end of file diff --git a/GettingStarted/1_SimpleStarterTests.feature.cs b/GettingStarted/1_SimpleStarterTests.feature.cs index 3e3054e..52e7c24 100644 --- a/GettingStarted/1_SimpleStarterTests.feature.cs +++ b/GettingStarted/1_SimpleStarterTests.feature.cs @@ -130,6 +130,46 @@ public virtual void AddTwoNumbers_NoVariables() #line hidden #line 10 testRunner.Then("the result should be 3", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden + } + this.ScenarioCleanup(); + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Add two different numbers - no variables")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "Add Two Numbers Together")] + public virtual void AddTwoDifferentNumbers_NoVariables() + { + string[] tagsOfScenario = ((string[])(null)); + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Add two different numbers - no variables", null, ((string[])(null))); +#line 12 +this.ScenarioInitialize(scenarioInfo); +#line hidden + bool isScenarioIgnored = default(bool); + bool isFeatureIgnored = default(bool); + if ((tagsOfScenario != null)) + { + isScenarioIgnored = tagsOfScenario.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((this._featureTags != null)) + { + isFeatureIgnored = this._featureTags.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((isScenarioIgnored || isFeatureIgnored)) + { + testRunner.SkipScenario(); + } + else + { + this.ScenarioStart(); +#line 13 + testRunner.Given("I have entered the numbers 3 and 5", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden +#line 14 + testRunner.When("I add 3 and 5 together", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line hidden +#line 15 + testRunner.Then("the result should be 8", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); #line hidden } this.ScenarioCleanup(); diff --git a/GettingStarted/AddTwoNumbersTogetherSteps.cs b/GettingStarted/AddTwoNumbersTogetherSteps.cs index 3669120..f39743f 100644 --- a/GettingStarted/AddTwoNumbersTogetherSteps.cs +++ b/GettingStarted/AddTwoNumbersTogetherSteps.cs @@ -29,5 +29,24 @@ public void ThenTheResultShouldBeThree() { resultOfAddition.Should().Be(3); } + + [Given(@"I have entered the numbers 3 and 5")] + public void GivenIHaveEnteredTheNumbersThreAndFive() + { + ScenarioContext.Current.Pending(); + } + + [When(@"I add 3 and 5 together")] + public void WhenIAddThreeAndFiveTogether() + { + ScenarioContext.Current.Pending(); + } + + [Then(@"the result should be 8")] + public void ThenTheResultShouldBeEight() + { + ScenarioContext.Current.Pending(); + } + } } From c418cadec7d52dc706a8a019009450014cdd047a Mon Sep 17 00:00:00 2001 From: Nate Adams Date: Wed, 11 Dec 2019 15:16:58 -0600 Subject: [PATCH 03/15] Implement new testing methods --- GettingStarted/AddTwoNumbersTogetherSteps.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/GettingStarted/AddTwoNumbersTogetherSteps.cs b/GettingStarted/AddTwoNumbersTogetherSteps.cs index f39743f..401e35e 100644 --- a/GettingStarted/AddTwoNumbersTogetherSteps.cs +++ b/GettingStarted/AddTwoNumbersTogetherSteps.cs @@ -33,19 +33,20 @@ public void ThenTheResultShouldBeThree() [Given(@"I have entered the numbers 3 and 5")] public void GivenIHaveEnteredTheNumbersThreAndFive() { - ScenarioContext.Current.Pending(); + firstNumber = 3; + secondNumber = 5; } [When(@"I add 3 and 5 together")] public void WhenIAddThreeAndFiveTogether() { - ScenarioContext.Current.Pending(); + resultOfAddition = firstNumber + secondNumber; } [Then(@"the result should be 8")] public void ThenTheResultShouldBeEight() { - ScenarioContext.Current.Pending(); + resultOfAddition.Should().Be(8); } } From 740ee3fec2d6e5462f8b312365e6d83cf7640816 Mon Sep 17 00:00:00 2001 From: Nate Adams Date: Wed, 11 Dec 2019 15:24:11 -0600 Subject: [PATCH 04/15] This time keep the code SpecFlow generated --- .../TestAddingNumbersWithVariables.feature | 9 ++ .../TestAddingNumbersWithVariables.feature.cs | 140 ++++++++++++++++++ .../TestAddingNumbersWithVariablesSteps.cs | 27 ++++ 3 files changed, 176 insertions(+) create mode 100644 GettingStarted/TestAddingNumbersWithVariables.feature create mode 100644 GettingStarted/TestAddingNumbersWithVariables.feature.cs create mode 100644 GettingStarted/TestAddingNumbersWithVariablesSteps.cs diff --git a/GettingStarted/TestAddingNumbersWithVariables.feature b/GettingStarted/TestAddingNumbersWithVariables.feature new file mode 100644 index 0000000..e176f7d --- /dev/null +++ b/GettingStarted/TestAddingNumbersWithVariables.feature @@ -0,0 +1,9 @@ +Feature: TestAddingNumbersWithVariables + In order to avoid writing a lot of extra testing code + I want to be able to use variables in my SpecFlow tests + +@mytag +Scenario: Add 1 and 2 + Given I have the numbers 1 and 2 + When I add them together + Then they should add up to 3 \ No newline at end of file diff --git a/GettingStarted/TestAddingNumbersWithVariables.feature.cs b/GettingStarted/TestAddingNumbersWithVariables.feature.cs new file mode 100644 index 0000000..3fa39db --- /dev/null +++ b/GettingStarted/TestAddingNumbersWithVariables.feature.cs @@ -0,0 +1,140 @@ +// ------------------------------------------------------------------------------ +// +// This code was generated by SpecFlow (http://www.specflow.org/). +// SpecFlow Version:3.1.0.0 +// SpecFlow Generator Version:3.1.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 GettingStarted +{ + using TechTalk.SpecFlow; + using System; + using System.Linq; + + + [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "3.1.0.0")] + [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute()] + public partial class TestAddingNumbersWithVariablesFeature + { + + private static TechTalk.SpecFlow.ITestRunner testRunner; + + private Microsoft.VisualStudio.TestTools.UnitTesting.TestContext _testContext; + + private string[] _featureTags = ((string[])(null)); + +#line 1 "TestAddingNumbersWithVariables.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"), "TestAddingNumbersWithVariables", "\tIn order to avoid writing a lot of extra testing code\r\n\tI want to be able to use" + + " variables in my SpecFlow tests", ProgrammingLanguage.CSharp, ((string[])(null))); + testRunner.OnFeatureStart(featureInfo); + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupAttribute()] + public static void FeatureTearDown() + { + testRunner.OnFeatureEnd(); + testRunner = null; + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute()] + public virtual void TestInitialize() + { + if (((testRunner.FeatureContext != null) + && (testRunner.FeatureContext.FeatureInfo.Title != "TestAddingNumbersWithVariables"))) + { + global::GettingStarted.TestAddingNumbersWithVariablesFeature.FeatureSetup(null); + } + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestCleanupAttribute()] + public virtual void TestTearDown() + { + testRunner.OnScenarioEnd(); + } + + public virtual void ScenarioInitialize(TechTalk.SpecFlow.ScenarioInfo scenarioInfo) + { + testRunner.OnScenarioInitialize(scenarioInfo); + testRunner.ScenarioContext.ScenarioContainer.RegisterInstanceAs(_testContext); + } + + public virtual void ScenarioStart() + { + testRunner.OnScenarioStart(); + } + + public virtual void ScenarioCleanup() + { + testRunner.CollectScenarioErrors(); + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Add 1 and 2")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "TestAddingNumbersWithVariables")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestCategoryAttribute("mytag")] + public virtual void Add1And2() + { + string[] tagsOfScenario = new string[] { + "mytag"}; + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Add 1 and 2", null, new string[] { + "mytag"}); +#line 6 +this.ScenarioInitialize(scenarioInfo); +#line hidden + bool isScenarioIgnored = default(bool); + bool isFeatureIgnored = default(bool); + if ((tagsOfScenario != null)) + { + isScenarioIgnored = tagsOfScenario.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((this._featureTags != null)) + { + isFeatureIgnored = this._featureTags.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((isScenarioIgnored || isFeatureIgnored)) + { + testRunner.SkipScenario(); + } + else + { + this.ScenarioStart(); +#line 7 + testRunner.Given("I have the numbers 1 and 2", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden +#line 8 + testRunner.When("I add them together", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line hidden +#line 9 + testRunner.Then("they should add up to 3", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden + } + this.ScenarioCleanup(); + } + } +} +#pragma warning restore +#endregion diff --git a/GettingStarted/TestAddingNumbersWithVariablesSteps.cs b/GettingStarted/TestAddingNumbersWithVariablesSteps.cs new file mode 100644 index 0000000..6baeffa --- /dev/null +++ b/GettingStarted/TestAddingNumbersWithVariablesSteps.cs @@ -0,0 +1,27 @@ +using System; +using TechTalk.SpecFlow; + +namespace GettingStarted +{ + [Binding] + public class TestAddingNumbersWithVariablesSteps + { + [Given(@"I have the numbers (.*) and (.*)")] + public void GivenIHaveTheNumbersAnd(int p0, int p1) + { + ScenarioContext.Current.Pending(); + } + + [When(@"I add them together")] + public void WhenIAddThemTogether() + { + ScenarioContext.Current.Pending(); + } + + [Then(@"they should add up to (.*)")] + public void ThenTheyShouldAddUpTo(int p0) + { + ScenarioContext.Current.Pending(); + } + } +} From b75a608754bde26a3833bd4189e9b19726cc83c5 Mon Sep 17 00:00:00 2001 From: Nate Adams Date: Wed, 11 Dec 2019 15:25:53 -0600 Subject: [PATCH 05/15] Implement the testing code utilizing the variables --- .../TestAddingNumbersWithVariablesSteps.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/GettingStarted/TestAddingNumbersWithVariablesSteps.cs b/GettingStarted/TestAddingNumbersWithVariablesSteps.cs index 6baeffa..c7849fb 100644 --- a/GettingStarted/TestAddingNumbersWithVariablesSteps.cs +++ b/GettingStarted/TestAddingNumbersWithVariablesSteps.cs @@ -1,4 +1,5 @@ -using System; +using FluentAssertions; +using System; using TechTalk.SpecFlow; namespace GettingStarted @@ -6,22 +7,27 @@ namespace GettingStarted [Binding] public class TestAddingNumbersWithVariablesSteps { + int firstNumber; + int secondNumber; + int resultOfAddition; + [Given(@"I have the numbers (.*) and (.*)")] public void GivenIHaveTheNumbersAnd(int p0, int p1) { - ScenarioContext.Current.Pending(); + firstNumber = p0; + secondNumber = p1; } - + [When(@"I add them together")] public void WhenIAddThemTogether() { - ScenarioContext.Current.Pending(); + resultOfAddition = firstNumber + secondNumber; } - + [Then(@"they should add up to (.*)")] public void ThenTheyShouldAddUpTo(int p0) { - ScenarioContext.Current.Pending(); + resultOfAddition.Should().Be(p0); } } } From e0dcd6fd17c3e0dac51e45630af25cbdcaac0cd3 Mon Sep 17 00:00:00 2001 From: Nate Adams Date: Wed, 11 Dec 2019 15:29:29 -0600 Subject: [PATCH 06/15] Add additional scenarios which use the variables --- .../TestAddingNumbersWithVariables.feature | 12 ++- .../TestAddingNumbersWithVariables.feature.cs | 80 +++++++++++++++++++ 2 files changed, 91 insertions(+), 1 deletion(-) diff --git a/GettingStarted/TestAddingNumbersWithVariables.feature b/GettingStarted/TestAddingNumbersWithVariables.feature index e176f7d..6a8dfe5 100644 --- a/GettingStarted/TestAddingNumbersWithVariables.feature +++ b/GettingStarted/TestAddingNumbersWithVariables.feature @@ -6,4 +6,14 @@ Scenario: Add 1 and 2 Given I have the numbers 1 and 2 When I add them together - Then they should add up to 3 \ No newline at end of file + Then they should add up to 3 + +Scenario: Add 3 and 4 + Given I have the numbers 3 and 4 + When I add them together + Then they should add up to 7 + +Scenario: Add 101 and 1332 + Given I have the numbers 101 and 1332 + When I add them together + Then they should add up to 1433 \ No newline at end of file diff --git a/GettingStarted/TestAddingNumbersWithVariables.feature.cs b/GettingStarted/TestAddingNumbersWithVariables.feature.cs index 3fa39db..1e5dd0c 100644 --- a/GettingStarted/TestAddingNumbersWithVariables.feature.cs +++ b/GettingStarted/TestAddingNumbersWithVariables.feature.cs @@ -130,6 +130,86 @@ public virtual void Add1And2() #line hidden #line 9 testRunner.Then("they should add up to 3", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden + } + this.ScenarioCleanup(); + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Add 3 and 4")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "TestAddingNumbersWithVariables")] + public virtual void Add3And4() + { + string[] tagsOfScenario = ((string[])(null)); + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Add 3 and 4", null, ((string[])(null))); +#line 11 +this.ScenarioInitialize(scenarioInfo); +#line hidden + bool isScenarioIgnored = default(bool); + bool isFeatureIgnored = default(bool); + if ((tagsOfScenario != null)) + { + isScenarioIgnored = tagsOfScenario.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((this._featureTags != null)) + { + isFeatureIgnored = this._featureTags.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((isScenarioIgnored || isFeatureIgnored)) + { + testRunner.SkipScenario(); + } + else + { + this.ScenarioStart(); +#line 12 + testRunner.Given("I have the numbers 3 and 4", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden +#line 13 + testRunner.When("I add them together", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line hidden +#line 14 + testRunner.Then("they should add up to 7", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden + } + this.ScenarioCleanup(); + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Add 101 and 1332")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "TestAddingNumbersWithVariables")] + public virtual void Add101And1332() + { + string[] tagsOfScenario = ((string[])(null)); + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Add 101 and 1332", null, ((string[])(null))); +#line 16 +this.ScenarioInitialize(scenarioInfo); +#line hidden + bool isScenarioIgnored = default(bool); + bool isFeatureIgnored = default(bool); + if ((tagsOfScenario != null)) + { + isScenarioIgnored = tagsOfScenario.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((this._featureTags != null)) + { + isFeatureIgnored = this._featureTags.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((isScenarioIgnored || isFeatureIgnored)) + { + testRunner.SkipScenario(); + } + else + { + this.ScenarioStart(); +#line 17 + testRunner.Given("I have the numbers 101 and 1332", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden +#line 18 + testRunner.When("I add them together", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line hidden +#line 19 + testRunner.Then("they should add up to 1433", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); #line hidden } this.ScenarioCleanup(); From 68d8d10751d7d78666ef75413e312eea66144b8c Mon Sep 17 00:00:00 2001 From: Nate Adams Date: Wed, 11 Dec 2019 15:42:20 -0600 Subject: [PATCH 07/15] fixup! Add additional scenarios which use the variables --- ...riables.feature => 2_TestAddingNumbersWithVariables.feature} | 0 ...s.feature.cs => 2_TestAddingNumbersWithVariables.feature.cs} | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename GettingStarted/{TestAddingNumbersWithVariables.feature => 2_TestAddingNumbersWithVariables.feature} (100%) rename GettingStarted/{TestAddingNumbersWithVariables.feature.cs => 2_TestAddingNumbersWithVariables.feature.cs} (99%) diff --git a/GettingStarted/TestAddingNumbersWithVariables.feature b/GettingStarted/2_TestAddingNumbersWithVariables.feature similarity index 100% rename from GettingStarted/TestAddingNumbersWithVariables.feature rename to GettingStarted/2_TestAddingNumbersWithVariables.feature diff --git a/GettingStarted/TestAddingNumbersWithVariables.feature.cs b/GettingStarted/2_TestAddingNumbersWithVariables.feature.cs similarity index 99% rename from GettingStarted/TestAddingNumbersWithVariables.feature.cs rename to GettingStarted/2_TestAddingNumbersWithVariables.feature.cs index 1e5dd0c..c373b92 100644 --- a/GettingStarted/TestAddingNumbersWithVariables.feature.cs +++ b/GettingStarted/2_TestAddingNumbersWithVariables.feature.cs @@ -29,7 +29,7 @@ public partial class TestAddingNumbersWithVariablesFeature private string[] _featureTags = ((string[])(null)); -#line 1 "TestAddingNumbersWithVariables.feature" +#line 1 "2_TestAddingNumbersWithVariables.feature" #line hidden public virtual Microsoft.VisualStudio.TestTools.UnitTesting.TestContext TestContext From c2c43e6d0df9c8555980e447508297bc5e3f00e9 Mon Sep 17 00:00:00 2001 From: Nate Adams Date: Wed, 11 Dec 2019 15:42:56 -0600 Subject: [PATCH 08/15] Add a new project with a funtion we want to test --- SomeStuffToTest/SomeStuffToTest.csproj | 7 +++++++ SomeStuffToTest/StoreHours.cs | 9 +++++++++ TestingPracticesWithExamples.sln | 6 ++++++ 3 files changed, 22 insertions(+) create mode 100644 SomeStuffToTest/SomeStuffToTest.csproj create mode 100644 SomeStuffToTest/StoreHours.cs diff --git a/SomeStuffToTest/SomeStuffToTest.csproj b/SomeStuffToTest/SomeStuffToTest.csproj new file mode 100644 index 0000000..cb63190 --- /dev/null +++ b/SomeStuffToTest/SomeStuffToTest.csproj @@ -0,0 +1,7 @@ + + + + netcoreapp3.1 + + + diff --git a/SomeStuffToTest/StoreHours.cs b/SomeStuffToTest/StoreHours.cs new file mode 100644 index 0000000..1806124 --- /dev/null +++ b/SomeStuffToTest/StoreHours.cs @@ -0,0 +1,9 @@ +using System; + +namespace SomeStuffToTest +{ + public static class StoreHours + { + + } +} diff --git a/TestingPracticesWithExamples.sln b/TestingPracticesWithExamples.sln index 4dfbcaf..028c857 100644 --- a/TestingPracticesWithExamples.sln +++ b/TestingPracticesWithExamples.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 16.0.29609.76 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GettingStarted", "GettingStarted\GettingStarted.csproj", "{AAB66502-A5F2-40D8-BCB4-F7EDB0923640}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SomeStuffToTest", "SomeStuffToTest\SomeStuffToTest.csproj", "{0A2F95D9-17BE-493A-825D-FF3A87AB109C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {AAB66502-A5F2-40D8-BCB4-F7EDB0923640}.Debug|Any CPU.Build.0 = Debug|Any CPU {AAB66502-A5F2-40D8-BCB4-F7EDB0923640}.Release|Any CPU.ActiveCfg = Release|Any CPU {AAB66502-A5F2-40D8-BCB4-F7EDB0923640}.Release|Any CPU.Build.0 = Release|Any CPU + {0A2F95D9-17BE-493A-825D-FF3A87AB109C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0A2F95D9-17BE-493A-825D-FF3A87AB109C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0A2F95D9-17BE-493A-825D-FF3A87AB109C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0A2F95D9-17BE-493A-825D-FF3A87AB109C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 226556b3134258b86514e97b77b0f3149c551363 Mon Sep 17 00:00:00 2001 From: Nate Adams Date: Wed, 11 Dec 2019 16:08:44 -0600 Subject: [PATCH 09/15] Implement IsStoreOpen function --- SomeStuffToTest/StoreHours.cs | 45 +++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/SomeStuffToTest/StoreHours.cs b/SomeStuffToTest/StoreHours.cs index 1806124..28d565b 100644 --- a/SomeStuffToTest/StoreHours.cs +++ b/SomeStuffToTest/StoreHours.cs @@ -1,9 +1,54 @@ using System; +using System.Linq; namespace SomeStuffToTest { public static class StoreHours { + public static bool IsStoreOpen(DateTime dateAndTime) + { + var storeHours = new[] { + new { + DayOfWeek = DayOfWeek.Monday, + OpenTimeOnDate = new DateTime(dateAndTime.Year, dateAndTime.Month, dateAndTime.Day, 8, 0, 0), + CloseTimeOnDate = new DateTime(dateAndTime.Year, dateAndTime.Month, dateAndTime.Day, 22, 0, 0) + }, + new { + DayOfWeek = DayOfWeek.Tuesday, + OpenTimeOnDate = new DateTime(dateAndTime.Year, dateAndTime.Month, dateAndTime.Day, 8, 0, 0), + CloseTimeOnDate = new DateTime(dateAndTime.Year, dateAndTime.Month, dateAndTime.Day, 22, 0, 0) + }, + new { + DayOfWeek = DayOfWeek.Wednesday, + OpenTimeOnDate = new DateTime(dateAndTime.Year, dateAndTime.Month, dateAndTime.Day, 8, 0, 0), + CloseTimeOnDate = new DateTime(dateAndTime.Year, dateAndTime.Month, dateAndTime.Day, 22, 0, 0) + }, + new { + DayOfWeek = DayOfWeek.Thursday, + OpenTimeOnDate = new DateTime(dateAndTime.Year, dateAndTime.Month, dateAndTime.Day, 8, 0, 0), + CloseTimeOnDate = new DateTime(dateAndTime.Year, dateAndTime.Month, dateAndTime.Day, 22, 0, 0) + }, + new { + DayOfWeek = DayOfWeek.Friday, + OpenTimeOnDate = new DateTime(dateAndTime.Year, dateAndTime.Month, dateAndTime.Day, 8, 0, 0), + CloseTimeOnDate = new DateTime(dateAndTime.Year, dateAndTime.Month, dateAndTime.Day, 23, 0, 0) + }, + new { + DayOfWeek = DayOfWeek.Saturday, + OpenTimeOnDate = new DateTime(dateAndTime.Year, dateAndTime.Month, dateAndTime.Day, 10, 0, 0), + CloseTimeOnDate = new DateTime(dateAndTime.Year, dateAndTime.Month, dateAndTime.Day, 20, 0, 0) + }, + new { + DayOfWeek = DayOfWeek.Sunday, + OpenTimeOnDate = new DateTime(dateAndTime.Year, dateAndTime.Month, dateAndTime.Day, 10, 0, 0), + CloseTimeOnDate = new DateTime(dateAndTime.Year, dateAndTime.Month, dateAndTime.Day, 18, 0, 0) + } + }; + + var dayOptions = storeHours.First(sh => sh.DayOfWeek == dateAndTime.DayOfWeek); + + return dayOptions.OpenTimeOnDate <= dateAndTime && dayOptions.CloseTimeOnDate > dateAndTime; + } } } From 23365a162cb9ea79e1b85d38ab7a4703206858ca Mon Sep 17 00:00:00 2001 From: Nate Adams Date: Wed, 11 Dec 2019 16:17:41 -0600 Subject: [PATCH 10/15] Finish implementation and add test scenarios --- .../CheckToSeeIfTheStoreIsOpenSteps.cs | 32 ++++ GettingStarted/GettingStarted.csproj | 4 + GettingStarted/SpecFlowFeature1.feature | 13 ++ GettingStarted/SpecFlowFeature1.feature.cs | 174 ++++++++++++++++++ SomeStuffToTest/StoreHours.cs | 2 +- 5 files changed, 224 insertions(+), 1 deletion(-) create mode 100644 GettingStarted/CheckToSeeIfTheStoreIsOpenSteps.cs create mode 100644 GettingStarted/SpecFlowFeature1.feature create mode 100644 GettingStarted/SpecFlowFeature1.feature.cs diff --git a/GettingStarted/CheckToSeeIfTheStoreIsOpenSteps.cs b/GettingStarted/CheckToSeeIfTheStoreIsOpenSteps.cs new file mode 100644 index 0000000..4e123e6 --- /dev/null +++ b/GettingStarted/CheckToSeeIfTheStoreIsOpenSteps.cs @@ -0,0 +1,32 @@ +using FluentAssertions; +using SomeStuffToTest; +using System; +using TechTalk.SpecFlow; + +namespace GettingStarted +{ + [Binding] + public class CheckToSeeIfTheStoreIsOpenSteps + { + DateTime currentTime; + + [Given(@"It is currently (.*) at (.*)")] + public void GivenItIsCurrentlyAt(string p0, string p1) + { + currentTime = DateTime.Parse($"{p0} {p1}"); + } + + [Then(@"The store is open")] + public void ThenTheStoreIsOpen() + { + currentTime.IsStoreOpen().Should().BeTrue(); + } + + [Then(@"The store is closed")] + public void ThenTheStoreIsClosed() + { + currentTime.IsStoreOpen().Should().BeFalse(); + } + + } +} diff --git a/GettingStarted/GettingStarted.csproj b/GettingStarted/GettingStarted.csproj index a3a39a4..9012705 100644 --- a/GettingStarted/GettingStarted.csproj +++ b/GettingStarted/GettingStarted.csproj @@ -17,6 +17,10 @@ + + + + True diff --git a/GettingStarted/SpecFlowFeature1.feature b/GettingStarted/SpecFlowFeature1.feature new file mode 100644 index 0000000..993599a --- /dev/null +++ b/GettingStarted/SpecFlowFeature1.feature @@ -0,0 +1,13 @@ +Feature: Check to see if the store is open + As a potential customer + I want to know if your store is open + So I don't waste my time driving there if it isn't + +@mytag +Scenario: Check if store is open at 12/11/2019 5:00PM + Given It is currently 12/11/2019 at 5:00PM + Then The store is open + +Scenario: Check if store is open at 12/15/2019 11:00PM + Given It is currently 12/15/2019 at 11:00PM + Then The store is closed \ No newline at end of file diff --git a/GettingStarted/SpecFlowFeature1.feature.cs b/GettingStarted/SpecFlowFeature1.feature.cs new file mode 100644 index 0000000..e1d4b1d --- /dev/null +++ b/GettingStarted/SpecFlowFeature1.feature.cs @@ -0,0 +1,174 @@ +// ------------------------------------------------------------------------------ +// +// This code was generated by SpecFlow (http://www.specflow.org/). +// SpecFlow Version:3.1.0.0 +// SpecFlow Generator Version:3.1.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 GettingStarted +{ + using TechTalk.SpecFlow; + using System; + using System.Linq; + + + [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "3.1.0.0")] + [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute()] + public partial class CheckToSeeIfTheStoreIsOpenFeature + { + + private static TechTalk.SpecFlow.ITestRunner testRunner; + + private Microsoft.VisualStudio.TestTools.UnitTesting.TestContext _testContext; + + private string[] _featureTags = ((string[])(null)); + +#line 1 "SpecFlowFeature1.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"), "Check to see if the store is open", "\tAs a potential customer\r\n\tI want to know if your store is open\r\n\tSo I don\'t wast" + + "e my time driving there if it isn\'t", ProgrammingLanguage.CSharp, ((string[])(null))); + testRunner.OnFeatureStart(featureInfo); + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupAttribute()] + public static void FeatureTearDown() + { + testRunner.OnFeatureEnd(); + testRunner = null; + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute()] + public virtual void TestInitialize() + { + if (((testRunner.FeatureContext != null) + && (testRunner.FeatureContext.FeatureInfo.Title != "Check to see if the store is open"))) + { + global::GettingStarted.CheckToSeeIfTheStoreIsOpenFeature.FeatureSetup(null); + } + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestCleanupAttribute()] + public virtual void TestTearDown() + { + testRunner.OnScenarioEnd(); + } + + public virtual void ScenarioInitialize(TechTalk.SpecFlow.ScenarioInfo scenarioInfo) + { + testRunner.OnScenarioInitialize(scenarioInfo); + testRunner.ScenarioContext.ScenarioContainer.RegisterInstanceAs(_testContext); + } + + public virtual void ScenarioStart() + { + testRunner.OnScenarioStart(); + } + + public virtual void ScenarioCleanup() + { + testRunner.CollectScenarioErrors(); + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Check if store is open at 12/11/2019 5:00PM")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "Check to see if the store is open")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestCategoryAttribute("mytag")] + public virtual void CheckIfStoreIsOpenAt12112019500PM() + { + string[] tagsOfScenario = new string[] { + "mytag"}; + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Check if store is open at 12/11/2019 5:00PM", null, new string[] { + "mytag"}); +#line 7 +this.ScenarioInitialize(scenarioInfo); +#line hidden + bool isScenarioIgnored = default(bool); + bool isFeatureIgnored = default(bool); + if ((tagsOfScenario != null)) + { + isScenarioIgnored = tagsOfScenario.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((this._featureTags != null)) + { + isFeatureIgnored = this._featureTags.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((isScenarioIgnored || isFeatureIgnored)) + { + testRunner.SkipScenario(); + } + else + { + this.ScenarioStart(); +#line 8 + testRunner.Given("It is currently 12/11/2019 at 5:00PM", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden +#line 9 + testRunner.Then("The store is open", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden + } + this.ScenarioCleanup(); + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Check if store is open at 12/15/2019 11:00PM")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "Check to see if the store is open")] + public virtual void CheckIfStoreIsOpenAt121520191100PM() + { + string[] tagsOfScenario = ((string[])(null)); + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Check if store is open at 12/15/2019 11:00PM", null, ((string[])(null))); +#line 11 +this.ScenarioInitialize(scenarioInfo); +#line hidden + bool isScenarioIgnored = default(bool); + bool isFeatureIgnored = default(bool); + if ((tagsOfScenario != null)) + { + isScenarioIgnored = tagsOfScenario.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((this._featureTags != null)) + { + isFeatureIgnored = this._featureTags.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((isScenarioIgnored || isFeatureIgnored)) + { + testRunner.SkipScenario(); + } + else + { + this.ScenarioStart(); +#line 12 + testRunner.Given("It is currently 12/15/2019 at 11:00PM", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden +#line 13 + testRunner.Then("The store is closed", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden + } + this.ScenarioCleanup(); + } + } +} +#pragma warning restore +#endregion diff --git a/SomeStuffToTest/StoreHours.cs b/SomeStuffToTest/StoreHours.cs index 28d565b..78ac9c9 100644 --- a/SomeStuffToTest/StoreHours.cs +++ b/SomeStuffToTest/StoreHours.cs @@ -5,7 +5,7 @@ namespace SomeStuffToTest { public static class StoreHours { - public static bool IsStoreOpen(DateTime dateAndTime) + public static bool IsStoreOpen(this DateTime dateAndTime) { var storeHours = new[] { new { From b4762be7ae1b2fdd753fa50ee4be1556fce68e93 Mon Sep 17 00:00:00 2001 From: Nate Adams Date: Wed, 11 Dec 2019 16:23:21 -0600 Subject: [PATCH 11/15] Add a couple additional edge cases. Look! Tests pass --- ...re => 3_TestToSeeIfOurStoreIsOpen.feature} | 8 ++ ...=> 3_TestToSeeIfOurStoreIsOpen.feature.cs} | 76 ++++++++++++++++++- 2 files changed, 83 insertions(+), 1 deletion(-) rename GettingStarted/{SpecFlowFeature1.feature => 3_TestToSeeIfOurStoreIsOpen.feature} (62%) rename GettingStarted/{SpecFlowFeature1.feature.cs => 3_TestToSeeIfOurStoreIsOpen.feature.cs} (66%) diff --git a/GettingStarted/SpecFlowFeature1.feature b/GettingStarted/3_TestToSeeIfOurStoreIsOpen.feature similarity index 62% rename from GettingStarted/SpecFlowFeature1.feature rename to GettingStarted/3_TestToSeeIfOurStoreIsOpen.feature index 993599a..b03629a 100644 --- a/GettingStarted/SpecFlowFeature1.feature +++ b/GettingStarted/3_TestToSeeIfOurStoreIsOpen.feature @@ -10,4 +10,12 @@ Scenario: Check if store is open at 12/11/2019 5:00PM Scenario: Check if store is open at 12/15/2019 11:00PM Given It is currently 12/15/2019 at 11:00PM + Then The store is closed + +Scenario: Open time edge case - store opens at 8AM + Given It is currently 12/11/2019 at 8:00AM + Then The store is open + +Scenario: Close time edge case - store closes at 10:00PM + Given It is currently 12/11/2019 at 10:00PM Then The store is closed \ No newline at end of file diff --git a/GettingStarted/SpecFlowFeature1.feature.cs b/GettingStarted/3_TestToSeeIfOurStoreIsOpen.feature.cs similarity index 66% rename from GettingStarted/SpecFlowFeature1.feature.cs rename to GettingStarted/3_TestToSeeIfOurStoreIsOpen.feature.cs index e1d4b1d..1e10465 100644 --- a/GettingStarted/SpecFlowFeature1.feature.cs +++ b/GettingStarted/3_TestToSeeIfOurStoreIsOpen.feature.cs @@ -29,7 +29,7 @@ public partial class CheckToSeeIfTheStoreIsOpenFeature private string[] _featureTags = ((string[])(null)); -#line 1 "SpecFlowFeature1.feature" +#line 1 "3_TestToSeeIfOurStoreIsOpen.feature" #line hidden public virtual Microsoft.VisualStudio.TestTools.UnitTesting.TestContext TestContext @@ -164,6 +164,80 @@ public virtual void CheckIfStoreIsOpenAt121520191100PM() #line hidden #line 13 testRunner.Then("The store is closed", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden + } + this.ScenarioCleanup(); + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Open time edge case - store opens at 8AM")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "Check to see if the store is open")] + public virtual void OpenTimeEdgeCase_StoreOpensAt8AM() + { + string[] tagsOfScenario = ((string[])(null)); + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Open time edge case - store opens at 8AM", null, ((string[])(null))); +#line 15 +this.ScenarioInitialize(scenarioInfo); +#line hidden + bool isScenarioIgnored = default(bool); + bool isFeatureIgnored = default(bool); + if ((tagsOfScenario != null)) + { + isScenarioIgnored = tagsOfScenario.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((this._featureTags != null)) + { + isFeatureIgnored = this._featureTags.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((isScenarioIgnored || isFeatureIgnored)) + { + testRunner.SkipScenario(); + } + else + { + this.ScenarioStart(); +#line 16 + testRunner.Given("It is currently 12/11/2019 at 8:00AM", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden +#line 17 + testRunner.Then("The store is open", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden + } + this.ScenarioCleanup(); + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Close time edge case - store closes at 10:00PM")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "Check to see if the store is open")] + public virtual void CloseTimeEdgeCase_StoreClosesAt1000PM() + { + string[] tagsOfScenario = ((string[])(null)); + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Close time edge case - store closes at 10:00PM", null, ((string[])(null))); +#line 19 +this.ScenarioInitialize(scenarioInfo); +#line hidden + bool isScenarioIgnored = default(bool); + bool isFeatureIgnored = default(bool); + if ((tagsOfScenario != null)) + { + isScenarioIgnored = tagsOfScenario.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((this._featureTags != null)) + { + isFeatureIgnored = this._featureTags.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((isScenarioIgnored || isFeatureIgnored)) + { + testRunner.SkipScenario(); + } + else + { + this.ScenarioStart(); +#line 20 + testRunner.Given("It is currently 12/11/2019 at 10:00PM", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden +#line 21 + testRunner.Then("The store is closed", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); #line hidden } this.ScenarioCleanup(); From 7ac2f7274c63288276059b99c488e715bf7c18af Mon Sep 17 00:00:00 2001 From: Nate Adams Date: Wed, 11 Dec 2019 16:27:16 -0600 Subject: [PATCH 12/15] Add additional documentation to feature --- .../3_TestToSeeIfOurStoreIsOpen.feature | 5 ++++ .../3_TestToSeeIfOurStoreIsOpen.feature.cs | 27 ++++++++++--------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/GettingStarted/3_TestToSeeIfOurStoreIsOpen.feature b/GettingStarted/3_TestToSeeIfOurStoreIsOpen.feature index b03629a..2a08af5 100644 --- a/GettingStarted/3_TestToSeeIfOurStoreIsOpen.feature +++ b/GettingStarted/3_TestToSeeIfOurStoreIsOpen.feature @@ -2,6 +2,11 @@ As a potential customer I want to know if your store is open So I don't waste my time driving there if it isn't + Store Hours: + M-Th 8-10 + Fri 8-11 + Sat 10-8 + Sun 10-6 @mytag Scenario: Check if store is open at 12/11/2019 5:00PM diff --git a/GettingStarted/3_TestToSeeIfOurStoreIsOpen.feature.cs b/GettingStarted/3_TestToSeeIfOurStoreIsOpen.feature.cs index 1e10465..3c5bae6 100644 --- a/GettingStarted/3_TestToSeeIfOurStoreIsOpen.feature.cs +++ b/GettingStarted/3_TestToSeeIfOurStoreIsOpen.feature.cs @@ -49,7 +49,8 @@ public static void FeatureSetup(Microsoft.VisualStudio.TestTools.UnitTesting.Tes { testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(); TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Check to see if the store is open", "\tAs a potential customer\r\n\tI want to know if your store is open\r\n\tSo I don\'t wast" + - "e my time driving there if it isn\'t", ProgrammingLanguage.CSharp, ((string[])(null))); + "e my time driving there if it isn\'t\r\n\tStore Hours:\r\n\tM-Th 8-10\r\n\tFri 8-11\r\n\tSat " + + "10-8\r\n\tSun 10-6", ProgrammingLanguage.CSharp, ((string[])(null))); testRunner.OnFeatureStart(featureInfo); } @@ -102,7 +103,7 @@ public virtual void CheckIfStoreIsOpenAt12112019500PM() "mytag"}; TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Check if store is open at 12/11/2019 5:00PM", null, new string[] { "mytag"}); -#line 7 +#line 12 this.ScenarioInitialize(scenarioInfo); #line hidden bool isScenarioIgnored = default(bool); @@ -122,10 +123,10 @@ public virtual void CheckIfStoreIsOpenAt12112019500PM() else { this.ScenarioStart(); -#line 8 +#line 13 testRunner.Given("It is currently 12/11/2019 at 5:00PM", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); #line hidden -#line 9 +#line 14 testRunner.Then("The store is open", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); #line hidden } @@ -139,7 +140,7 @@ public virtual void CheckIfStoreIsOpenAt121520191100PM() { string[] tagsOfScenario = ((string[])(null)); TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Check if store is open at 12/15/2019 11:00PM", null, ((string[])(null))); -#line 11 +#line 16 this.ScenarioInitialize(scenarioInfo); #line hidden bool isScenarioIgnored = default(bool); @@ -159,10 +160,10 @@ public virtual void CheckIfStoreIsOpenAt121520191100PM() else { this.ScenarioStart(); -#line 12 +#line 17 testRunner.Given("It is currently 12/15/2019 at 11:00PM", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); #line hidden -#line 13 +#line 18 testRunner.Then("The store is closed", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); #line hidden } @@ -176,7 +177,7 @@ public virtual void OpenTimeEdgeCase_StoreOpensAt8AM() { string[] tagsOfScenario = ((string[])(null)); TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Open time edge case - store opens at 8AM", null, ((string[])(null))); -#line 15 +#line 20 this.ScenarioInitialize(scenarioInfo); #line hidden bool isScenarioIgnored = default(bool); @@ -196,10 +197,10 @@ public virtual void OpenTimeEdgeCase_StoreOpensAt8AM() else { this.ScenarioStart(); -#line 16 +#line 21 testRunner.Given("It is currently 12/11/2019 at 8:00AM", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); #line hidden -#line 17 +#line 22 testRunner.Then("The store is open", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); #line hidden } @@ -213,7 +214,7 @@ public virtual void CloseTimeEdgeCase_StoreClosesAt1000PM() { string[] tagsOfScenario = ((string[])(null)); TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Close time edge case - store closes at 10:00PM", null, ((string[])(null))); -#line 19 +#line 24 this.ScenarioInitialize(scenarioInfo); #line hidden bool isScenarioIgnored = default(bool); @@ -233,10 +234,10 @@ public virtual void CloseTimeEdgeCase_StoreClosesAt1000PM() else { this.ScenarioStart(); -#line 20 +#line 25 testRunner.Given("It is currently 12/11/2019 at 10:00PM", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); #line hidden -#line 21 +#line 26 testRunner.Then("The store is closed", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); #line hidden } From 1dbf4e116ca2483bd9ce972eb0e694cce261262d Mon Sep 17 00:00:00 2001 From: Nate Adams Date: Thu, 12 Dec 2019 09:07:38 -0600 Subject: [PATCH 13/15] Simply test scenario file with outline --- ...SeeIfTheStoreIsOpen_OutlineVersionSteps.cs | 32 +++ .../IsStoreOpenScenarioOutlineVersion.feature | 24 ++ ...StoreOpenScenarioOutlineVersion.feature.cs | 244 ++++++++++++++++++ 3 files changed, 300 insertions(+) create mode 100644 GettingStarted/CheckToSeeIfTheStoreIsOpen_OutlineVersionSteps.cs create mode 100644 GettingStarted/IsStoreOpenScenarioOutlineVersion.feature create mode 100644 GettingStarted/IsStoreOpenScenarioOutlineVersion.feature.cs diff --git a/GettingStarted/CheckToSeeIfTheStoreIsOpen_OutlineVersionSteps.cs b/GettingStarted/CheckToSeeIfTheStoreIsOpen_OutlineVersionSteps.cs new file mode 100644 index 0000000..1b315ac --- /dev/null +++ b/GettingStarted/CheckToSeeIfTheStoreIsOpen_OutlineVersionSteps.cs @@ -0,0 +1,32 @@ +using FluentAssertions; +using SomeStuffToTest; +using System; +using TechTalk.SpecFlow; + +namespace GettingStarted +{ + [Binding] + public class CheckToSeeIfTheStoreIsOpen_OutlineVersionSteps + { + DateTime dateToTest; + + [Given(@"it is a certain (.*) and (.*)")] + public void GivenItIsACertainAnd(string p0, string p1) + { + dateToTest = DateTime.Parse($"{p0} {p1}"); + } + + [Then(@"The store (.*) open at that time")] + public void ThenTheStoreOpen(string p0) + { + if (dateToTest.IsStoreOpen()) + { + p0.ToLower().Replace(" ", "").Should().Be("is"); + } + else + { + p0.ToLower().Replace(" ", "").Should().Be("isnot"); + } + } + } +} diff --git a/GettingStarted/IsStoreOpenScenarioOutlineVersion.feature b/GettingStarted/IsStoreOpenScenarioOutlineVersion.feature new file mode 100644 index 0000000..816c6da --- /dev/null +++ b/GettingStarted/IsStoreOpenScenarioOutlineVersion.feature @@ -0,0 +1,24 @@ +Feature: Check to see if the store is open - outline version + As a potential customer + I want to know if your store is open + So I don't waste my time driving there if it isn't + Store Hours: + M-Th 8-10 + Fri 8-11 + Sat 10-8 + Sun 10-6 + +Scenario Outline: Testing multiple dates and times + Given it is a certain and + + + +