From c291f822a7d96c8e22108bbd37b2390453c2074c Mon Sep 17 00:00:00 2001 From: Thomas Wiedebusch Date: Wed, 17 Jul 2024 15:33:13 +0200 Subject: [PATCH] GenesisCore.UnitTests: - template setup --- Common/Common.sln | 67 +++++++++ .../Features/Calculator.feature | 13 ++ .../Features/Calculator.feature.cs | 127 ++++++++++++++++++ .../GenesisCore.UnitTests.csproj | 38 ++++++ .../Steps/CalculatorStepDefinitions.cs | 59 ++++++++ nuget.config | 8 -- 6 files changed, 304 insertions(+), 8 deletions(-) create mode 100644 Common/Hardware/WaterMeter/Genesis/GenesisCore.UnitTests/Features/Calculator.feature create mode 100644 Common/Hardware/WaterMeter/Genesis/GenesisCore.UnitTests/Features/Calculator.feature.cs create mode 100644 Common/Hardware/WaterMeter/Genesis/GenesisCore.UnitTests/GenesisCore.UnitTests.csproj create mode 100644 Common/Hardware/WaterMeter/Genesis/GenesisCore.UnitTests/Steps/CalculatorStepDefinitions.cs diff --git a/Common/Common.sln b/Common/Common.sln index 0fbf7653..9114aaa1 100644 --- a/Common/Common.sln +++ b/Common/Common.sln @@ -227,6 +227,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.Hardware.WaterMeter. EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.Utils.Extensions", "Utils\Common.Utils.Extensions\Common.Utils.Extensions.csproj", "{05F0CCAF-9F2B-45F9-A7F8-12F29AD182F3}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GenesisCore.UnitTests", "Hardware\WaterMeter\Genesis\GenesisCore.UnitTests\GenesisCore.UnitTests.csproj", "{03B30D85-D89D-4E58-B381-49D3C73A9BB6}" +EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution Utils\DateTimeServerShared\DateTimeServerShared.projitems*{4806d89a-fbfb-41bc-aaa7-2242444bf55a}*SharedItemsImports = 4 @@ -5509,6 +5511,70 @@ Global {05F0CCAF-9F2B-45F9-A7F8-12F29AD182F3}.XP32bit|x64.Build.0 = Release|Any CPU {05F0CCAF-9F2B-45F9-A7F8-12F29AD182F3}.XP32bit|x86.ActiveCfg = Release|Any CPU {05F0CCAF-9F2B-45F9-A7F8-12F29AD182F3}.XP32bit|x86.Build.0 = Release|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}._MANUAL_CONTROL|Any CPU.ActiveCfg = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}._MANUAL_CONTROL|Any CPU.Build.0 = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}._MANUAL_CONTROL|Mixed Platforms.ActiveCfg = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}._MANUAL_CONTROL|Mixed Platforms.Build.0 = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}._MANUAL_CONTROL|x64.ActiveCfg = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}._MANUAL_CONTROL|x64.Build.0 = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}._MANUAL_CONTROL|x86.ActiveCfg = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}._MANUAL_CONTROL|x86.Build.0 = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.COM|Any CPU.ActiveCfg = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.COM|Any CPU.Build.0 = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.COM|Mixed Platforms.ActiveCfg = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.COM|Mixed Platforms.Build.0 = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.COM|x64.ActiveCfg = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.COM|x64.Build.0 = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.COM|x86.ActiveCfg = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.COM|x86.Build.0 = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.Debug|x64.ActiveCfg = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.Debug|x64.Build.0 = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.Debug|x86.ActiveCfg = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.Debug|x86.Build.0 = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.GenesisDisplayTool_V01|Any CPU.ActiveCfg = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.GenesisDisplayTool_V01|Any CPU.Build.0 = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.GenesisDisplayTool_V01|Mixed Platforms.ActiveCfg = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.GenesisDisplayTool_V01|Mixed Platforms.Build.0 = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.GenesisDisplayTool_V01|x64.ActiveCfg = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.GenesisDisplayTool_V01|x64.Build.0 = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.GenesisDisplayTool_V01|x86.ActiveCfg = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.GenesisDisplayTool_V01|x86.Build.0 = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.PerformTest|Any CPU.ActiveCfg = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.PerformTest|Any CPU.Build.0 = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.PerformTest|Mixed Platforms.ActiveCfg = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.PerformTest|Mixed Platforms.Build.0 = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.PerformTest|x64.ActiveCfg = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.PerformTest|x64.Build.0 = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.PerformTest|x86.ActiveCfg = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.PerformTest|x86.Build.0 = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.Release|Any CPU.Build.0 = Release|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.Release|x64.ActiveCfg = Release|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.Release|x64.Build.0 = Release|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.Release|x86.ActiveCfg = Release|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.Release|x86.Build.0 = Release|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.ReleaseTest|Any CPU.ActiveCfg = Release|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.ReleaseTest|Any CPU.Build.0 = Release|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.ReleaseTest|Mixed Platforms.ActiveCfg = Release|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.ReleaseTest|Mixed Platforms.Build.0 = Release|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.ReleaseTest|x64.ActiveCfg = Release|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.ReleaseTest|x64.Build.0 = Release|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.ReleaseTest|x86.ActiveCfg = Release|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.ReleaseTest|x86.Build.0 = Release|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.XP32bit|Any CPU.ActiveCfg = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.XP32bit|Any CPU.Build.0 = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.XP32bit|Mixed Platforms.ActiveCfg = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.XP32bit|Mixed Platforms.Build.0 = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.XP32bit|x64.ActiveCfg = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.XP32bit|x64.Build.0 = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.XP32bit|x86.ActiveCfg = Debug|Any CPU + {03B30D85-D89D-4E58-B381-49D3C73A9BB6}.XP32bit|x86.Build.0 = Debug|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -5612,6 +5678,7 @@ Global {28FD69D1-B2DA-485D-9571-711BF3917350} = {696A94BE-7237-4AE2-9E36-6059DE519971} {4E8BB839-D40A-488C-88CE-F21811F1F476} = {43B54F41-6F09-4BCB-9F82-77621275831B} {05F0CCAF-9F2B-45F9-A7F8-12F29AD182F3} = {7A0EE7B8-6B7E-41E9-B679-319C8CA48CF1} + {03B30D85-D89D-4E58-B381-49D3C73A9BB6} = {B5F43F61-4448-4992-85B5-7EDFB82FD643} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {4BCB7B69-696C-436A-86F7-C91EA5588164} diff --git a/Common/Hardware/WaterMeter/Genesis/GenesisCore.UnitTests/Features/Calculator.feature b/Common/Hardware/WaterMeter/Genesis/GenesisCore.UnitTests/Features/Calculator.feature new file mode 100644 index 00000000..a4d685c5 --- /dev/null +++ b/Common/Hardware/WaterMeter/Genesis/GenesisCore.UnitTests/Features/Calculator.feature @@ -0,0 +1,13 @@ +Feature: Calculator +![Calculator](https://specflow.org/wp-content/uploads/2020/09/calculator.png) +Simple calculator for adding **two** numbers + +Link to a feature: [Calculator](Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore.UnitTests/Features/Calculator.feature) +***Further read***: **[Learn more about how to generate Living Documentation](https://docs.specflow.org/projects/specflow-livingdoc/en/latest/LivingDocGenerator/Generating-Documentation.html)** + +@mytag +Scenario: Add two numbers + Given the first number is 50 + And the second number is 70 + When the two numbers are added + Then the result should be 120 \ No newline at end of file diff --git a/Common/Hardware/WaterMeter/Genesis/GenesisCore.UnitTests/Features/Calculator.feature.cs b/Common/Hardware/WaterMeter/Genesis/GenesisCore.UnitTests/Features/Calculator.feature.cs new file mode 100644 index 00000000..d9090f6d --- /dev/null +++ b/Common/Hardware/WaterMeter/Genesis/GenesisCore.UnitTests/Features/Calculator.feature.cs @@ -0,0 +1,127 @@ +// ------------------------------------------------------------------------------ +// +// 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 Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore.UnitTests.Features +{ + using TechTalk.SpecFlow; + using System; + using System.Linq; + + + [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "3.9.0.0")] + [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [NUnit.Framework.TestFixtureAttribute()] + [NUnit.Framework.DescriptionAttribute("Calculator")] + public partial class CalculatorFeature + { + + private TechTalk.SpecFlow.ITestRunner testRunner; + + private string[] _featureTags = ((string[])(null)); + +#line 1 "Calculator.feature" +#line hidden + + [NUnit.Framework.OneTimeSetUpAttribute()] + public virtual void FeatureSetup() + { + testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(); + TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Features", "Calculator", @"![Calculator](https://specflow.org/wp-content/uploads/2020/09/calculator.png) +Simple calculator for adding **two** numbers + +Link to a feature: [Calculator](Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore.UnitTests/Features/Calculator.feature) +***Further read***: **[Learn more about how to generate Living Documentation](https://docs.specflow.org/projects/specflow-livingdoc/en/latest/LivingDocGenerator/Generating-Documentation.html)**", ProgrammingLanguage.CSharp, ((string[])(null))); + testRunner.OnFeatureStart(featureInfo); + } + + [NUnit.Framework.OneTimeTearDownAttribute()] + public virtual void FeatureTearDown() + { + testRunner.OnFeatureEnd(); + testRunner = null; + } + + [NUnit.Framework.SetUpAttribute()] + public virtual void TestInitialize() + { + } + + [NUnit.Framework.TearDownAttribute()] + public virtual void TestTearDown() + { + testRunner.OnScenarioEnd(); + } + + public virtual void ScenarioInitialize(TechTalk.SpecFlow.ScenarioInfo scenarioInfo) + { + testRunner.OnScenarioInitialize(scenarioInfo); + testRunner.ScenarioContext.ScenarioContainer.RegisterInstanceAs(NUnit.Framework.TestContext.CurrentContext); + } + + public virtual void ScenarioStart() + { + testRunner.OnScenarioStart(); + } + + public virtual void ScenarioCleanup() + { + testRunner.CollectScenarioErrors(); + } + + [NUnit.Framework.TestAttribute()] + [NUnit.Framework.DescriptionAttribute("Add two numbers")] + [NUnit.Framework.CategoryAttribute("mytag")] + public virtual void AddTwoNumbers() + { + string[] tagsOfScenario = new string[] { + "mytag"}; + System.Collections.Specialized.OrderedDictionary argumentsOfScenario = new System.Collections.Specialized.OrderedDictionary(); + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Add two numbers", null, tagsOfScenario, argumentsOfScenario, this._featureTags); +#line 9 +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 10 + testRunner.Given("the first number is 50", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden +#line 11 + testRunner.And("the second number is 70", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden +#line 12 + testRunner.When("the two numbers are added", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line hidden +#line 13 + testRunner.Then("the result should be 120", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden + } + this.ScenarioCleanup(); + } + } +} +#pragma warning restore +#endregion diff --git a/Common/Hardware/WaterMeter/Genesis/GenesisCore.UnitTests/GenesisCore.UnitTests.csproj b/Common/Hardware/WaterMeter/Genesis/GenesisCore.UnitTests/GenesisCore.UnitTests.csproj new file mode 100644 index 00000000..13e3ff92 --- /dev/null +++ b/Common/Hardware/WaterMeter/Genesis/GenesisCore.UnitTests/GenesisCore.UnitTests.csproj @@ -0,0 +1,38 @@ + + + + net48 + enable + Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore.UnitTests + true + Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore.UnitTests + + + + + + + + + + + + + + + + + True + True + Calculator.feature + + + + + + SpecFlowSingleFileGenerator + Calculator.feature.cs + + + + \ No newline at end of file diff --git a/Common/Hardware/WaterMeter/Genesis/GenesisCore.UnitTests/Steps/CalculatorStepDefinitions.cs b/Common/Hardware/WaterMeter/Genesis/GenesisCore.UnitTests/Steps/CalculatorStepDefinitions.cs new file mode 100644 index 00000000..5edcd9c5 --- /dev/null +++ b/Common/Hardware/WaterMeter/Genesis/GenesisCore.UnitTests/Steps/CalculatorStepDefinitions.cs @@ -0,0 +1,59 @@ +using System; +using NUnit.Framework; +using TechTalk.SpecFlow; + +namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore.UnitTests.Steps +{ + [Binding] + public sealed class CalculatorStepDefinitions + { + + // For additional details on SpecFlow step definitions see https://go.specflow.org/doc-stepdef + + private readonly ScenarioContext _scenarioContext; + private Int32 _firstNumber; + private Int32 _secondNumber; + private Int32 _result; + + public CalculatorStepDefinitions(ScenarioContext scenarioContext) + { + _scenarioContext = scenarioContext; + } + + [Given("the first number is (.*)")] + public void GivenTheFirstNumberIs(Int32 number) + { + //TODO: implement arrange (precondition) logic + // For storing and retrieving scenario-specific data see https://go.specflow.org/doc-sharingdata + // To use the multiline text or the table argument of the scenario, + // additional string/Table parameters can be defined on the step definition + // method. + _firstNumber = number; + } + + [Given("the second number is (.*)")] + public void GivenTheSecondNumberIs(Int32 number) + { + //TODO: implement arrange (precondition) logic + // For storing and retrieving scenario-specific data see https://go.specflow.org/doc-sharingdata + // To use the multiline text or the table argument of the scenario, + // additional string/Table parameters can be defined on the step definition + // method. + _secondNumber = number; + } + + [When("the two numbers are added")] + public void WhenTheTwoNumbersAreAdded() + { + //TODO: implement act (action) logic + _result = _firstNumber + _secondNumber; + } + + [Then("the result should be (.*)")] + public void ThenTheResultShouldBe(Int32 result) + { + //TODO: implement assert (verification) logic + Assert.AreEqual(_result, result, "Failed addition"); + } + } +} diff --git a/nuget.config b/nuget.config index a9759313..94b85f6c 100644 --- a/nuget.config +++ b/nuget.config @@ -2,14 +2,6 @@ - - - - - - - -