From fb2bd8d56d60e6bf539723c914b59bc1d7d6a866 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Felix=20Wei=C3=9F?=
<72068105+Sandoun@users.noreply.github.com>
Date: Mon, 27 Feb 2023 16:01:47 +0100
Subject: [PATCH] Added test structure
---
Examples/Program.cs | 31 +++++++++++------
MewtocolNet.sln | 28 +++++++++++----
MewtocolTests/MewtocolTests.csproj | 28 +++++++++++++++
MewtocolTests/TestComProtocol.cs | 55 ++++++++++++++++++++++++++++++
4 files changed, 124 insertions(+), 18 deletions(-)
create mode 100644 MewtocolTests/MewtocolTests.csproj
create mode 100644 MewtocolTests/TestComProtocol.cs
diff --git a/Examples/Program.cs b/Examples/Program.cs
index 0327436..e7531f7 100644
--- a/Examples/Program.cs
+++ b/Examples/Program.cs
@@ -3,6 +3,7 @@ using System.Threading.Tasks;
using MewtocolNet;
using MewtocolNet.Logging;
using MewtocolNet.Registers;
+using static System.Net.Mime.MediaTypeNames;
namespace Examples;
@@ -10,6 +11,14 @@ class Program {
static void Main(string[] args) {
+ AppDomain.CurrentDomain.UnhandledException += (s,e) => {
+ Console.WriteLine(e.ExceptionObject.ToString());
+ };
+
+ TaskScheduler.UnobservedTaskException += (s,e) => {
+ Console.WriteLine(e.Exception.ToString());
+ };
+
Console.WriteLine("Enter your scenario number:\n" +
"1 = Permanent connection\n" +
"2 = Dispose connection");
@@ -59,21 +68,21 @@ class Program {
}
});
- //await interf.ConnectAsync((plcinf) => AfterConnect(interf, registers));
+ await interf.ConnectAsync();
- bool flip = false;
- while(true) {
+ //bool flip = false;
+ //while(true) {
- if(!flip) {
- await interf.ConnectAsync();
- } else {
- interf.Disconnect();
- }
+ // if(!flip) {
+ // await interf.ConnectAsync();
+ // } else {
+ // interf.Disconnect();
+ // }
- flip = !flip;
- await Task.Delay(5000);
+ // flip = !flip;
+ // await Task.Delay(5000);
- }
+ //}
});
diff --git a/MewtocolNet.sln b/MewtocolNet.sln
index 11f2096..4f0c7eb 100644
--- a/MewtocolNet.sln
+++ b/MewtocolNet.sln
@@ -1,11 +1,13 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio Version 16
-VisualStudioVersion = 16.0.30114.105
+# Visual Studio Version 17
+VisualStudioVersion = 17.5.33103.201
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MewtocolNet", "MewtocolNet\MewtocolNet.csproj", "{8B7863E7-5E82-4990-9138-2C0C24629982}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MewtocolNet", "MewtocolNet\MewtocolNet.csproj", "{8B7863E7-5E82-4990-9138-2C0C24629982}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Examples", "Examples\Examples.csproj", "{D1F2FA26-3752-44BA-9DCB-4BC2436C5957}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Examples", "Examples\Examples.csproj", "{D1F2FA26-3752-44BA-9DCB-4BC2436C5957}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MewtocolTests", "MewtocolTests\MewtocolTests.csproj", "{C1BF3AB0-CDFE-4070-A759-C3B25A20ABE1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -16,9 +18,6 @@ Global
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8B7863E7-5E82-4990-9138-2C0C24629982}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8B7863E7-5E82-4990-9138-2C0C24629982}.Debug|Any CPU.Build.0 = Debug|Any CPU
@@ -44,5 +43,20 @@ Global
{D1F2FA26-3752-44BA-9DCB-4BC2436C5957}.Release|x64.Build.0 = Release|Any CPU
{D1F2FA26-3752-44BA-9DCB-4BC2436C5957}.Release|x86.ActiveCfg = Release|Any CPU
{D1F2FA26-3752-44BA-9DCB-4BC2436C5957}.Release|x86.Build.0 = Release|Any CPU
+ {C1BF3AB0-CDFE-4070-A759-C3B25A20ABE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {C1BF3AB0-CDFE-4070-A759-C3B25A20ABE1}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {C1BF3AB0-CDFE-4070-A759-C3B25A20ABE1}.Debug|x64.ActiveCfg = Debug|Any CPU
+ {C1BF3AB0-CDFE-4070-A759-C3B25A20ABE1}.Debug|x64.Build.0 = Debug|Any CPU
+ {C1BF3AB0-CDFE-4070-A759-C3B25A20ABE1}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {C1BF3AB0-CDFE-4070-A759-C3B25A20ABE1}.Debug|x86.Build.0 = Debug|Any CPU
+ {C1BF3AB0-CDFE-4070-A759-C3B25A20ABE1}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {C1BF3AB0-CDFE-4070-A759-C3B25A20ABE1}.Release|Any CPU.Build.0 = Release|Any CPU
+ {C1BF3AB0-CDFE-4070-A759-C3B25A20ABE1}.Release|x64.ActiveCfg = Release|Any CPU
+ {C1BF3AB0-CDFE-4070-A759-C3B25A20ABE1}.Release|x64.Build.0 = Release|Any CPU
+ {C1BF3AB0-CDFE-4070-A759-C3B25A20ABE1}.Release|x86.ActiveCfg = Release|Any CPU
+ {C1BF3AB0-CDFE-4070-A759-C3B25A20ABE1}.Release|x86.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
diff --git a/MewtocolTests/MewtocolTests.csproj b/MewtocolTests/MewtocolTests.csproj
new file mode 100644
index 0000000..0e1e112
--- /dev/null
+++ b/MewtocolTests/MewtocolTests.csproj
@@ -0,0 +1,28 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+ false
+
+
+
+
+
+
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+ all
+
+
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+ all
+
+
+
+
+
+
+
+
diff --git a/MewtocolTests/TestComProtocol.cs b/MewtocolTests/TestComProtocol.cs
new file mode 100644
index 0000000..d9180f5
--- /dev/null
+++ b/MewtocolTests/TestComProtocol.cs
@@ -0,0 +1,55 @@
+using Xunit;
+
+using MewtocolNet;
+using MewtocolNet.Registers;
+using System.Diagnostics;
+using Xunit.Abstractions;
+using System.Collections;
+
+namespace MewtocolTests {
+
+ public class TestComProtocol {
+
+ private readonly ITestOutputHelper output;
+
+ public TestComProtocol (ITestOutputHelper output) {
+ this.output = output;
+ }
+
+ [Fact(DisplayName = "Numeric register protocol identifiers")]
+ public void NumericRegisterMewtocolIdentifiers () {
+
+ List registers = new List {
+ new NRegister(50),
+ new NRegister(50),
+ new NRegister(50),
+ new NRegister(50),
+ new NRegister(50),
+ new NRegister(50),
+ };
+
+ List expcectedIdents = new List {
+ "D0005000050", //single word register
+ "D0005000050", //single word register
+ "D0005000051", //double word register
+ "D0005000051", //double word register
+ "D0005000051", //double word register
+ "D0005000051", //double word register
+ "D0005000051", //double word register
+ };
+
+ //test mewtocol idents
+ for (int i = 0; i < registers.Count; i++) {
+
+ Register? reg = registers[i];
+ string expect = expcectedIdents[i];
+
+ Assert.Equal(expect, reg.BuildMewtocolIdent());
+
+ }
+
+ }
+
+ }
+
+}
\ No newline at end of file