Added more tests

This commit is contained in:
Federico Barresi
2021-02-04 22:10:49 +01:00
parent 9a890ef26f
commit 733ce3529f
2 changed files with 68 additions and 1 deletions

View File

@@ -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");
}
}
}