mirror of
https://github.com/evopro-ag/Sharp7Reactive.git
synced 2025-12-16 11:42:52 +00:00
import tests
This commit is contained in:
50
Sharp7.Rx.Tests/ParsingS7VariableName.cs
Normal file
50
Sharp7.Rx.Tests/ParsingS7VariableName.cs
Normal file
@@ -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<Vars>();
|
||||||
|
|
||||||
|
ScenarioContext.Current.Set(names);
|
||||||
|
}
|
||||||
|
|
||||||
|
[When(@"I parse the var name")]
|
||||||
|
public void WhenIParseTheVarName()
|
||||||
|
{
|
||||||
|
var names = ScenarioContext.Current.Get<IEnumerable<Vars>>();
|
||||||
|
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<S7VariableAddress[]>();
|
||||||
|
table.CompareToSet(addresses);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Vars
|
||||||
|
{
|
||||||
|
public string VarName { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
40
Sharp7.Rx.Tests/ParsingS7VariableName.feature
Normal file
40
Sharp7.Rx.Tests/ParsingS7VariableName.feature
Normal file
@@ -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 |
|
||||||
242
Sharp7.Rx.Tests/ParsingS7VariableName.feature.cs
generated
Normal file
242
Sharp7.Rx.Tests/ParsingS7VariableName.feature.cs
generated
Normal file
@@ -0,0 +1,242 @@
|
|||||||
|
// ------------------------------------------------------------------------------
|
||||||
|
// <auto-generated>
|
||||||
|
// 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.
|
||||||
|
// </auto-generated>
|
||||||
|
// ------------------------------------------------------------------------------
|
||||||
|
#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>(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
|
||||||
31
Sharp7.Rx.Tests/Sharp7.Rx.Tests.csproj
Normal file
31
Sharp7.Rx.Tests/Sharp7.Rx.Tests.csproj
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net461</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="NUnit" Version="3.11.0" />
|
||||||
|
<PackageReference Include="SpecFlow" Version="2.4.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Sharp7.Rx\Sharp7.Rx.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Update="ParsingS7VariableName.feature.cs">
|
||||||
|
<DesignTime>True</DesignTime>
|
||||||
|
<AutoGen>True</AutoGen>
|
||||||
|
<DependentUpon>ParsingS7VariableName.feature</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="ParsingS7VariableName.feature">
|
||||||
|
<Generator>SpecFlowSingleFileGenerator</Generator>
|
||||||
|
<LastGenOutput>ParsingS7VariableName.feature.cs</LastGenOutput>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -5,6 +5,8 @@ VisualStudioVersion = 15.0.28010.2041
|
|||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sharp7.Rx", "Sharp7.Rx\Sharp7.Rx.csproj", "{690A7E0E-BE95-49AC-AF2F-7FEA2F63204A}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sharp7.Rx", "Sharp7.Rx\Sharp7.Rx.csproj", "{690A7E0E-BE95-49AC-AF2F-7FEA2F63204A}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sharp7.Rx.Tests", "Sharp7.Rx.Tests\Sharp7.Rx.Tests.csproj", "{1BDD07D2-6540-4ACF-81E7-98300421073B}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
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}.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.ActiveCfg = Release|Any CPU
|
||||||
{690A7E0E-BE95-49AC-AF2F-7FEA2F63204A}.Release|Any CPU.Build.0 = 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
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
4
Sharp7.Rx/AssemblyInfo.cs
Normal file
4
Sharp7.Rx/AssemblyInfo.cs
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
[assembly: InternalsVisibleTo("Sharp7.Rx.Tests")]
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@ using Sharp7.Rx.Enums;
|
|||||||
|
|
||||||
namespace Sharp7.Rx
|
namespace Sharp7.Rx
|
||||||
{
|
{
|
||||||
internal class S7VaraibleNameParser
|
internal class S7VariableNameParser
|
||||||
{
|
{
|
||||||
private readonly Regex regex = new Regex(@"^(?<operand>db{1})(?<dbNr>\d{1,4})\.?(?<type>dbx|x|s|string|b|dbb|d|int|dbw|w|dint|dul|dulint|dulong|){1}(?<start>\d+)(\.(?<bitOrLength>\d+))?$", RegexOptions.IgnoreCase);
|
private readonly Regex regex = new Regex(@"^(?<operand>db{1})(?<dbNr>\d{1,4})\.?(?<type>dbx|x|s|string|b|dbb|d|int|dbw|w|dint|dul|dulint|dulong|){1}(?<start>\d+)(\.(?<bitOrLength>\d+))?$", RegexOptions.IgnoreCase);
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ namespace Sharp7.Rx
|
|||||||
private readonly string ipAddress;
|
private readonly string ipAddress;
|
||||||
private readonly int rackNumber;
|
private readonly int rackNumber;
|
||||||
private readonly int cpuMpiAddress;
|
private readonly int cpuMpiAddress;
|
||||||
private readonly S7VaraibleNameParser varaibleNameParser;
|
private readonly S7VariableNameParser varaibleNameParser;
|
||||||
private bool disposed;
|
private bool disposed;
|
||||||
private ISubject<Unit> disposingSubject = new Subject<Unit>();
|
private ISubject<Unit> disposingSubject = new Subject<Unit>();
|
||||||
private IS7Connector s7Connector;
|
private IS7Connector s7Connector;
|
||||||
@@ -27,7 +27,7 @@ namespace Sharp7.Rx
|
|||||||
this.rackNumber = rackNumber;
|
this.rackNumber = rackNumber;
|
||||||
this.cpuMpiAddress = cpuMpiAddress;
|
this.cpuMpiAddress = cpuMpiAddress;
|
||||||
|
|
||||||
varaibleNameParser = new S7VaraibleNameParser();
|
varaibleNameParser = new S7VariableNameParser();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IObservable<ConnectionState> ConnectionState { get; private set; }
|
public IObservable<ConnectionState> ConnectionState { get; private set; }
|
||||||
|
|||||||
Reference in New Issue
Block a user