From 89d6d3328e2908d3c2dcfb9d9248fc56cc40996d Mon Sep 17 00:00:00 2001 From: Thomas Stangl Date: Tue, 6 Nov 2018 13:03:35 +0100 Subject: [PATCH] import tests --- Sharp7.Rx.Tests/ParsingS7VariableName.cs | 50 ++++ Sharp7.Rx.Tests/ParsingS7VariableName.feature | 40 +++ .../ParsingS7VariableName.feature.cs | 242 ++++++++++++++++++ Sharp7.Rx.Tests/Sharp7.Rx.Tests.csproj | 31 +++ Sharp7.Rx.sln | 6 + Sharp7.Rx/AssemblyInfo.cs | 4 + Sharp7.Rx/S7VariableNameParser.cs | 2 +- Sharp7.Rx/Sharp7Plc.cs | 4 +- 8 files changed, 376 insertions(+), 3 deletions(-) create mode 100644 Sharp7.Rx.Tests/ParsingS7VariableName.cs create mode 100644 Sharp7.Rx.Tests/ParsingS7VariableName.feature create mode 100644 Sharp7.Rx.Tests/ParsingS7VariableName.feature.cs create mode 100644 Sharp7.Rx.Tests/Sharp7.Rx.Tests.csproj create mode 100644 Sharp7.Rx/AssemblyInfo.cs diff --git a/Sharp7.Rx.Tests/ParsingS7VariableName.cs b/Sharp7.Rx.Tests/ParsingS7VariableName.cs new file mode 100644 index 0000000..0dc256a --- /dev/null +++ b/Sharp7.Rx.Tests/ParsingS7VariableName.cs @@ -0,0 +1,50 @@ +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 new file mode 100644 index 0000000..e836e9d --- /dev/null +++ b/Sharp7.Rx.Tests/ParsingS7VariableName.feature @@ -0,0 +1,40 @@ +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 | 0 | 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 new file mode 100644 index 0000000..396af89 --- /dev/null +++ b/Sharp7.Rx.Tests/ParsingS7VariableName.feature.cs @@ -0,0 +1,242 @@ +// ------------------------------------------------------------------------------ +// +// 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", + "0", + "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/Sharp7.Rx.Tests.csproj b/Sharp7.Rx.Tests/Sharp7.Rx.Tests.csproj new file mode 100644 index 0000000..186e465 --- /dev/null +++ b/Sharp7.Rx.Tests/Sharp7.Rx.Tests.csproj @@ -0,0 +1,31 @@ + + + + net461 + + + + + + + + + + + + + + True + True + ParsingS7VariableName.feature + + + + + + SpecFlowSingleFileGenerator + ParsingS7VariableName.feature.cs + + + + diff --git a/Sharp7.Rx.sln b/Sharp7.Rx.sln index faec062..033c14e 100644 --- a/Sharp7.Rx.sln +++ b/Sharp7.Rx.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 15.0.28010.2041 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sharp7.Rx", "Sharp7.Rx\Sharp7.Rx.csproj", "{690A7E0E-BE95-49AC-AF2F-7FEA2F63204A}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sharp7.Rx.Tests", "Sharp7.Rx.Tests\Sharp7.Rx.Tests.csproj", "{1BDD07D2-6540-4ACF-81E7-98300421073B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {690A7E0E-BE95-49AC-AF2F-7FEA2F63204A}.Debug|Any CPU.Build.0 = Debug|Any CPU {690A7E0E-BE95-49AC-AF2F-7FEA2F63204A}.Release|Any CPU.ActiveCfg = Release|Any CPU {690A7E0E-BE95-49AC-AF2F-7FEA2F63204A}.Release|Any CPU.Build.0 = Release|Any CPU + {1BDD07D2-6540-4ACF-81E7-98300421073B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1BDD07D2-6540-4ACF-81E7-98300421073B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1BDD07D2-6540-4ACF-81E7-98300421073B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1BDD07D2-6540-4ACF-81E7-98300421073B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Sharp7.Rx/AssemblyInfo.cs b/Sharp7.Rx/AssemblyInfo.cs new file mode 100644 index 0000000..9d8031c --- /dev/null +++ b/Sharp7.Rx/AssemblyInfo.cs @@ -0,0 +1,4 @@ +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Sharp7.Rx.Tests")] + diff --git a/Sharp7.Rx/S7VariableNameParser.cs b/Sharp7.Rx/S7VariableNameParser.cs index f641b0c..bbe5e0e 100644 --- a/Sharp7.Rx/S7VariableNameParser.cs +++ b/Sharp7.Rx/S7VariableNameParser.cs @@ -7,7 +7,7 @@ using Sharp7.Rx.Enums; namespace Sharp7.Rx { - internal class S7VaraibleNameParser + internal class S7VariableNameParser { private readonly Regex regex = new Regex(@"^(?db{1})(?\d{1,4})\.?(?dbx|x|s|string|b|dbb|d|int|dbw|w|dint|dul|dulint|dulong|){1}(?\d+)(\.(?\d+))?$", RegexOptions.IgnoreCase); diff --git a/Sharp7.Rx/Sharp7Plc.cs b/Sharp7.Rx/Sharp7Plc.cs index 7a1d6bb..493e471 100644 --- a/Sharp7.Rx/Sharp7Plc.cs +++ b/Sharp7.Rx/Sharp7Plc.cs @@ -16,7 +16,7 @@ namespace Sharp7.Rx private readonly string ipAddress; private readonly int rackNumber; private readonly int cpuMpiAddress; - private readonly S7VaraibleNameParser varaibleNameParser; + private readonly S7VariableNameParser varaibleNameParser; private bool disposed; private ISubject disposingSubject = new Subject(); private IS7Connector s7Connector; @@ -27,7 +27,7 @@ namespace Sharp7.Rx this.rackNumber = rackNumber; this.cpuMpiAddress = cpuMpiAddress; - varaibleNameParser = new S7VaraibleNameParser(); + varaibleNameParser = new S7VariableNameParser(); } public IObservable ConnectionState { get; private set; }