mirror of
https://github.com/fbarresi/Sharp7.git
synced 2026-02-04 08:42:51 +00:00
added more tests
This commit is contained in:
70
Sharp7.Tests/ClientTest.cs
Normal file
70
Sharp7.Tests/ClientTest.cs
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
using System;
|
||||||
|
using Shouldly;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Sharp7.Tests
|
||||||
|
{
|
||||||
|
public class ClientTest : ServerClientTestBase
|
||||||
|
{
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ClientIsNotNull()
|
||||||
|
{
|
||||||
|
Client.ShouldNotBeNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ServerIsNotNull()
|
||||||
|
{
|
||||||
|
Server.ShouldNotBeNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TestTimeout()
|
||||||
|
{
|
||||||
|
Client.ConnTimeout.ShouldBe(2000);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TestConnected()
|
||||||
|
{
|
||||||
|
Client.Connected.ShouldBe(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TestPort()
|
||||||
|
{
|
||||||
|
Client.PLCPort.ShouldBe(102);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TestReadDb()
|
||||||
|
{
|
||||||
|
var bytes = new byte[] { 1, 2, 3 };
|
||||||
|
var index = 3;
|
||||||
|
Server.RegisterArea(S7Server.SrvAreaDB, index, ref bytes, bytes.Length);
|
||||||
|
|
||||||
|
var buffer = new byte[bytes.Length];
|
||||||
|
var rc = Client.DBRead(index, 0, bytes.Length, buffer);
|
||||||
|
|
||||||
|
//test
|
||||||
|
rc.ShouldBe(0);
|
||||||
|
buffer.ShouldBe(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TestWriteDb()
|
||||||
|
{
|
||||||
|
var bytes = new byte[3];
|
||||||
|
var index = 3;
|
||||||
|
Server.RegisterArea(S7Server.SrvAreaDB, index, ref bytes, bytes.Length);
|
||||||
|
|
||||||
|
var buffer = new byte[] { 1, 2, 3 };
|
||||||
|
var rc = Client.DBWrite(index, 0, bytes.Length, buffer);
|
||||||
|
|
||||||
|
//test
|
||||||
|
rc.ShouldBe(0);
|
||||||
|
buffer.ShouldBe(bytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Shouldly;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Sharp7.Tests
|
|
||||||
{
|
|
||||||
public class ConnectionTest : ServerClientTestBase
|
|
||||||
{
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void ClientIsNotNull()
|
|
||||||
{
|
|
||||||
Client.ShouldNotBeNull();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void ServerIsNotNull()
|
|
||||||
{
|
|
||||||
Server.ShouldNotBeNull();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -18,6 +18,11 @@ namespace Sharp7.Tests
|
|||||||
private const int MkLog = 1;
|
private const int MkLog = 1;
|
||||||
|
|
||||||
// Server Area ID (use with Register/unregister - Lock/unlock Area)
|
// Server Area ID (use with Register/unregister - Lock/unlock Area)
|
||||||
|
public static readonly int SrvAreaPe = 0;
|
||||||
|
public static readonly int SrvAreaPa = 1;
|
||||||
|
public static readonly int SrvAreaMk = 2;
|
||||||
|
public static readonly int SrvAreaCt = 3;
|
||||||
|
public static readonly int SrvAreaTm = 4;
|
||||||
public static readonly int SrvAreaDB = 5;
|
public static readonly int SrvAreaDB = 5;
|
||||||
|
|
||||||
// S7 Server Event Code
|
// S7 Server Event Code
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Shouldly;
|
using Shouldly;
|
||||||
|
|
||||||
namespace Sharp7.Tests
|
namespace Sharp7.Tests
|
||||||
@@ -13,6 +14,7 @@ namespace Sharp7.Tests
|
|||||||
{
|
{
|
||||||
client = new S7Client();
|
client = new S7Client();
|
||||||
var rc = client.ConnectTo(Localhost, 0, 2);
|
var rc = client.ConnectTo(Localhost, 0, 2);
|
||||||
|
Task.Delay(100).Wait();
|
||||||
rc.ShouldBe(0);
|
rc.ShouldBe(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Shouldly;
|
using Shouldly;
|
||||||
|
|
||||||
namespace Sharp7.Tests
|
namespace Sharp7.Tests
|
||||||
@@ -12,6 +13,7 @@ namespace Sharp7.Tests
|
|||||||
{
|
{
|
||||||
server = new S7Server();
|
server = new S7Server();
|
||||||
var rc = server.StartTo(Localhost);
|
var rc = server.StartTo(Localhost);
|
||||||
|
Task.Delay(100).Wait();
|
||||||
rc.ShouldBe(0);
|
rc.ShouldBe(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user