From 733ce3529f64ae2fe71198cf6aea257c31f5000e Mon Sep 17 00:00:00 2001 From: Federico Barresi Date: Thu, 4 Feb 2021 22:10:49 +0100 Subject: [PATCH] Added more tests --- Sharp7.Tests/PropertiesTests.cs | 67 ++++++++++++++++++++++++++++ Sharp7.Tests/ServerClientTestBase.cs | 2 +- 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 Sharp7.Tests/PropertiesTests.cs diff --git a/Sharp7.Tests/PropertiesTests.cs b/Sharp7.Tests/PropertiesTests.cs new file mode 100644 index 0000000..3afe38e --- /dev/null +++ b/Sharp7.Tests/PropertiesTests.cs @@ -0,0 +1,67 @@ +using Shouldly; +using Xunit; + +namespace Sharp7.Tests +{ + public class PropertiesTests + { + [Fact] + public void PlcHasNoName() + { + var client = new S7Client(); + client.Name.ShouldBeNull(); + string.IsNullOrEmpty(client.Name).ShouldBeTrue(); + } + + [Fact] + public void PlcHasAName() + { + var name = "test"; + var client = new S7Client(name); + client.Name.ShouldNotBeNull(); + string.IsNullOrEmpty(client.Name).ShouldBeFalse(); + client.Name.ShouldBe(name); + } + + [Fact] + public void PlcHasIp() + { + var ip = "10.10.10.10"; + var client = new S7Client(); + client.SetConnectionParams(ip, 0, 0); + client.PLCIpAddress.ShouldNotBeNull(); + string.IsNullOrEmpty(client.PLCIpAddress).ShouldBeFalse(); + client.PLCIpAddress.ShouldBe(ip); + } + + [Fact] + public void PlcHasNoIp() + { + var client = new S7Client(); + client.PLCIpAddress.ShouldBeNull(); + string.IsNullOrEmpty(client.PLCIpAddress).ShouldBeTrue(); + } + + [Fact] + public void PlcToString() + { + var client = new S7Client(); + client.ToString().ShouldBe("PLC @0.0.0.0"); + } + + [Fact] + public void PlcToStringWithName() + { + var client = new S7Client("Test"); + client.ToString().ShouldBe("PLC Test@0.0.0.0"); + } + + [Fact] + public void PlcToStringWithNameAndIp() + { + var client = new S7Client("Test"); + client.SetConnectionParams("1.2.3.4", 0, 0); + client.ToString().ShouldBe("PLC Test@1.2.3.4"); + } + } +} \ No newline at end of file diff --git a/Sharp7.Tests/ServerClientTestBase.cs b/Sharp7.Tests/ServerClientTestBase.cs index 48642c7..5666d5b 100644 --- a/Sharp7.Tests/ServerClientTestBase.cs +++ b/Sharp7.Tests/ServerClientTestBase.cs @@ -12,7 +12,7 @@ namespace Sharp7.Tests public ServerClientTestBase() : base() { - client = new S7Client(); + client = new S7Client("Test Plc"); var rc = client.ConnectTo(Localhost, 0, 2); rc.ShouldBe(0); }