diff --git a/Sharp7.Rx.Tests/ParsingS7VariableName.cs b/Sharp7.Rx.Tests/ParsingS7VariableName.cs deleted file mode 100644 index 0dc256a..0000000 --- a/Sharp7.Rx.Tests/ParsingS7VariableName.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Windows.Forms; -using TechTalk.SpecFlow; -using TechTalk.SpecFlow.Assist; - -namespace Sharp7.Rx.Tests -{ - [Binding] - public class ParsingS7VariableName - { - private S7VariableNameParser parser; - - [Given(@"I have an Parser")] - public void GivenIHaveAnParser() - { - parser = new S7VariableNameParser(); - } - - [Given(@"I have the following variables")] - public void GivenIHaveTheFollowingVariables(Table table) - { - var names = table.CreateSet(); - - ScenarioContext.Current.Set(names); - } - - [When(@"I parse the var name")] - public void WhenIParseTheVarName() - { - var names = ScenarioContext.Current.Get>(); - var addresses = names.Select(v => parser.Parse(v.VarName)).ToArray(); - - ScenarioContext.Current.Set(addresses); - } - - [Then(@"the result should be")] - public void ThenTheResultShouldBe(Table table) - { - var addresses = ScenarioContext.Current.Get(); - table.CompareToSet(addresses); - } - } - - class Vars - { - public string VarName { get; set; } - } -} diff --git a/Sharp7.Rx.Tests/ParsingS7VariableName.feature b/Sharp7.Rx.Tests/ParsingS7VariableName.feature deleted file mode 100644 index 82d3be1..0000000 --- a/Sharp7.Rx.Tests/ParsingS7VariableName.feature +++ /dev/null @@ -1,40 +0,0 @@ -Feature: ParsingS7VariableName - -@mytag -Scenario: Parsing variable name for bool - Given I have an Parser - And I have the following variables - | VarName | - | DB13.DBX3.1 | - | Db403.X5.2 | - | DB55DBX23.6 | - | DB1.S255 | - | DB1.S255.20 | - | DB5.String887.20 | - | DB506.B216 | - | DB506.DBB216.5 | - | DB506.D216 | - | DB506.DINT216 | - | DB506.INT216 | - | DB506.DBW216 | - | DB506.DUL216 | - | DB506.DULINT216 | - | DB506.DULONG216 | - When I parse the var name - Then the result should be - | Operand | DbNr | Start | Length | Bit | Type | - | Db | 13 | 3 | 1 | 1 | Bit | - | Db | 403 | 5 | 1 | 2 | Bit | - | Db | 55 | 23 | 1 | 6 | Bit | - | Db | 1 | 255 | 0 | 0 | String | - | Db | 1 | 255 | 20 | 0 | String | - | Db | 5 | 887 | 20 | 0 | String | - | Db | 506 | 216 | 1 | 0 | Byte | - | Db | 506 | 216 | 5 | 0 | Byte | - | Db | 506 | 216 | 4 | 0 | Double | - | Db | 506 | 216 | 4 | 0 | DInteger | - | Db | 506 | 216 | 2 | 0 | Integer | - | Db | 506 | 216 | 2 | 0 | Integer | - | Db | 506 | 216 | 8 | 0 | ULong | - | Db | 506 | 216 | 8 | 0 | ULong | - | Db | 506 | 216 | 8 | 0 | ULong | diff --git a/Sharp7.Rx.Tests/ParsingS7VariableName.feature.cs b/Sharp7.Rx.Tests/ParsingS7VariableName.feature.cs deleted file mode 100644 index 18959ea..0000000 --- a/Sharp7.Rx.Tests/ParsingS7VariableName.feature.cs +++ /dev/null @@ -1,242 +0,0 @@ -// ------------------------------------------------------------------------------ -// -// This code was generated by SpecFlow (http://www.specflow.org/). -// SpecFlow Version:2.4.0.0 -// SpecFlow Generator Version:2.4.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 Sharp7.Rx.Tests -{ - using TechTalk.SpecFlow; - - - [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "2.4.0.0")] - [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [NUnit.Framework.TestFixtureAttribute()] - [NUnit.Framework.DescriptionAttribute("ParsingS7VariableName")] - public partial class ParsingS7VariableNameFeature - { - - private TechTalk.SpecFlow.ITestRunner testRunner; - -#line 1 "ParsingS7VariableName.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"), "ParsingS7VariableName", null, 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 ScenarioTearDown() - { - 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("Parsing variable name for bool")] - [NUnit.Framework.CategoryAttribute("mytag")] - public virtual void ParsingVariableNameForBool() - { - TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Parsing variable name for bool", null, new string[] { - "mytag"}); -#line 4 -this.ScenarioInitialize(scenarioInfo); - this.ScenarioStart(); -#line 5 - testRunner.Given("I have an Parser", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); -#line hidden - TechTalk.SpecFlow.Table table1 = new TechTalk.SpecFlow.Table(new string[] { - "VarName"}); - table1.AddRow(new string[] { - "DB13.DBX3.1"}); - table1.AddRow(new string[] { - "Db403.X5.2"}); - table1.AddRow(new string[] { - "DB55DBX23.6"}); - table1.AddRow(new string[] { - "DB1.S255"}); - table1.AddRow(new string[] { - "DB1.S255.20"}); - table1.AddRow(new string[] { - "DB5.String887.20"}); - table1.AddRow(new string[] { - "DB506.B216"}); - table1.AddRow(new string[] { - "DB506.DBB216.5"}); - table1.AddRow(new string[] { - "DB506.D216"}); - table1.AddRow(new string[] { - "DB506.DINT216"}); - table1.AddRow(new string[] { - "DB506.INT216"}); - table1.AddRow(new string[] { - "DB506.DBW216"}); - table1.AddRow(new string[] { - "DB506.DUL216"}); - table1.AddRow(new string[] { - "DB506.DULINT216"}); - table1.AddRow(new string[] { - "DB506.DULONG216"}); -#line 6 - testRunner.And("I have the following variables", ((string)(null)), table1, "And "); -#line 23 - testRunner.When("I parse the var name", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); -#line hidden - TechTalk.SpecFlow.Table table2 = new TechTalk.SpecFlow.Table(new string[] { - "Operand", - "DbNr", - "Start", - "Length", - "Bit", - "Type"}); - table2.AddRow(new string[] { - "Db", - "13", - "3", - "1", - "1", - "Bit"}); - table2.AddRow(new string[] { - "Db", - "403", - "5", - "1", - "2", - "Bit"}); - table2.AddRow(new string[] { - "Db", - "55", - "23", - "1", - "6", - "Bit"}); - table2.AddRow(new string[] { - "Db", - "1", - "255", - "0", - "0", - "String"}); - table2.AddRow(new string[] { - "Db", - "1", - "255", - "20", - "0", - "String"}); - table2.AddRow(new string[] { - "Db", - "5", - "887", - "20", - "0", - "String"}); - table2.AddRow(new string[] { - "Db", - "506", - "216", - "1", - "0", - "Byte"}); - table2.AddRow(new string[] { - "Db", - "506", - "216", - "5", - "0", - "Byte"}); - table2.AddRow(new string[] { - "Db", - "506", - "216", - "4", - "0", - "Double"}); - table2.AddRow(new string[] { - "Db", - "506", - "216", - "4", - "0", - "DInteger"}); - table2.AddRow(new string[] { - "Db", - "506", - "216", - "2", - "0", - "Integer"}); - table2.AddRow(new string[] { - "Db", - "506", - "216", - "2", - "0", - "Integer"}); - table2.AddRow(new string[] { - "Db", - "506", - "216", - "8", - "0", - "ULong"}); - table2.AddRow(new string[] { - "Db", - "506", - "216", - "8", - "0", - "ULong"}); - table2.AddRow(new string[] { - "Db", - "506", - "216", - "8", - "0", - "ULong"}); -#line 24 - testRunner.Then("the result should be", ((string)(null)), table2, "Then "); -#line hidden - this.ScenarioCleanup(); - } - } -} -#pragma warning restore -#endregion diff --git a/Sharp7.Rx.Tests/S7VariableNameParserTests.cs b/Sharp7.Rx.Tests/S7VariableNameParserTests.cs new file mode 100644 index 0000000..b97641f --- /dev/null +++ b/Sharp7.Rx.Tests/S7VariableNameParserTests.cs @@ -0,0 +1,42 @@ +using System.Collections.Generic; +using DeepEqual.Syntax; +using NUnit.Framework; +using Sharp7.Rx.Enums; + +namespace Sharp7.Rx.Tests; + +[TestFixture] +internal class S7VariableNameParserTests +{ + [TestCaseSource(nameof(GetTestCases))] + public void Run(TestCase tc) + { + var parser = new S7VariableNameParser(); + var resp = parser.Parse(tc.Input); + resp.ShouldDeepEqual(tc.Expected); + } + + public static IEnumerable GetTestCases() + { + yield return new TestCase("DB13.DBX3.1", new S7VariableAddress {Operand = Operand.Db, DbNr = 13, Start = 3, Length = 1, Bit = 1, Type = DbType.Bit}); + yield return new TestCase("Db403.X5.2", new S7VariableAddress {Operand = Operand.Db, DbNr = 403, Start = 5, Length = 1, Bit = 2, Type = DbType.Bit}); + yield return new TestCase("DB55DBX23.6", new S7VariableAddress {Operand = Operand.Db, DbNr = 55, Start = 23, Length = 1, Bit = 6, Type = DbType.Bit}); + yield return new TestCase("DB1.S255", new S7VariableAddress {Operand = Operand.Db, DbNr = 1, Start = 255, Length = 0, Bit = 0, Type = DbType.String}); + yield return new TestCase("DB1.S255.20", new S7VariableAddress {Operand = Operand.Db, DbNr = 1, Start = 255, Length = 20, Bit = 0, Type = DbType.String}); + yield return new TestCase("DB5.String887.20", new S7VariableAddress {Operand = Operand.Db, DbNr = 5, Start = 887, Length = 20, Bit = 0, Type = DbType.String}); + yield return new TestCase("DB506.B216", new S7VariableAddress {Operand = Operand.Db, DbNr = 506, Start = 216, Length = 1, Bit = 0, Type = DbType.Byte}); + yield return new TestCase("DB506.DBB216.5", new S7VariableAddress {Operand = Operand.Db, DbNr = 506, Start = 216, Length = 5, Bit = 0, Type = DbType.Byte}); + yield return new TestCase("DB506.D216", new S7VariableAddress {Operand = Operand.Db, DbNr = 506, Start = 216, Length = 4, Bit = 0, Type = DbType.Double}); + yield return new TestCase("DB506.DINT216", new S7VariableAddress {Operand = Operand.Db, DbNr = 506, Start = 216, Length = 4, Bit = 0, Type = DbType.DInteger}); + yield return new TestCase("DB506.INT216", new S7VariableAddress {Operand = Operand.Db, DbNr = 506, Start = 216, Length = 2, Bit = 0, Type = DbType.Integer}); + yield return new TestCase("DB506.DBW216", new S7VariableAddress {Operand = Operand.Db, DbNr = 506, Start = 216, Length = 2, Bit = 0, Type = DbType.Integer}); + yield return new TestCase("DB506.DUL216", new S7VariableAddress {Operand = Operand.Db, DbNr = 506, Start = 216, Length = 8, Bit = 0, Type = DbType.ULong}); + yield return new TestCase("DB506.DULINT216", new S7VariableAddress {Operand = Operand.Db, DbNr = 506, Start = 216, Length = 8, Bit = 0, Type = DbType.ULong}); + yield return new TestCase("DB506.DULONG216", new S7VariableAddress {Operand = Operand.Db, DbNr = 506, Start = 216, Length = 8, Bit = 0, Type = DbType.ULong}); + } + + public record TestCase(string Input, S7VariableAddress Expected) + { + public override string ToString() => Input; + } +} \ No newline at end of file diff --git a/Sharp7.Rx.Tests/Sharp7.Rx.Tests.csproj b/Sharp7.Rx.Tests/Sharp7.Rx.Tests.csproj index 39dae7a..58c7e5b 100644 --- a/Sharp7.Rx.Tests/Sharp7.Rx.Tests.csproj +++ b/Sharp7.Rx.Tests/Sharp7.Rx.Tests.csproj @@ -1,32 +1,18 @@  - - net461 - + + net8.0 + - - - - - + + + + + + - - - + + + - - - True - True - ParsingS7VariableName.feature - - - - - - SpecFlowSingleFileGenerator - ParsingS7VariableName.feature.cs - - - - + \ No newline at end of file