Updated serial implementations
This commit is contained in:
@@ -13,13 +13,15 @@ namespace AMWD.Protocols.Modbus.Tests.Serial
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
string portName = "COM-42";
|
||||
|
||||
_genericConnectionMock = new Mock<IModbusConnection>();
|
||||
_genericConnectionMock.Setup(c => c.IdleTimeout).Returns(TimeSpan.FromSeconds(40));
|
||||
_genericConnectionMock.Setup(c => c.ConnectTimeout).Returns(TimeSpan.FromSeconds(30));
|
||||
_genericConnectionMock.Setup(c => c.ReadTimeout).Returns(TimeSpan.FromSeconds(20));
|
||||
_genericConnectionMock.Setup(c => c.WriteTimeout).Returns(TimeSpan.FromSeconds(10));
|
||||
|
||||
_serialConnectionMock = new Mock<ModbusSerialConnection>();
|
||||
_serialConnectionMock = new Mock<ModbusSerialConnection>(portName);
|
||||
|
||||
_serialConnectionMock.Setup(c => c.IdleTimeout).Returns(TimeSpan.FromSeconds(10));
|
||||
_serialConnectionMock.Setup(c => c.ConnectTimeout).Returns(TimeSpan.FromSeconds(20));
|
||||
@@ -28,7 +30,7 @@ namespace AMWD.Protocols.Modbus.Tests.Serial
|
||||
|
||||
_serialConnectionMock.Setup(c => c.DriverEnabledRS485).Returns(true);
|
||||
_serialConnectionMock.Setup(c => c.InterRequestDelay).Returns(TimeSpan.FromSeconds(50));
|
||||
_serialConnectionMock.Setup(c => c.PortName).Returns("COM-42");
|
||||
_serialConnectionMock.Setup(c => c.PortName).Returns(portName);
|
||||
_serialConnectionMock.Setup(c => c.BaudRate).Returns(BaudRate.Baud2400);
|
||||
_serialConnectionMock.Setup(c => c.DataBits).Returns(7);
|
||||
_serialConnectionMock.Setup(c => c.Handshake).Returns(Handshake.XOnXOff);
|
||||
@@ -231,5 +233,18 @@ namespace AMWD.Protocols.Modbus.Tests.Serial
|
||||
|
||||
_serialConnectionMock.VerifyNoOtherCalls();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ShouldPrintCleanString()
|
||||
{
|
||||
// Arrange
|
||||
using var client = new ModbusSerialClient(_serialConnectionMock.Object);
|
||||
|
||||
// Act
|
||||
string str = client.ToString();
|
||||
|
||||
// Assert
|
||||
SnapshotAssert.AreEqual(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,6 +90,21 @@ namespace AMWD.Protocols.Modbus.Tests.Serial
|
||||
connection.Dispose();
|
||||
}
|
||||
|
||||
[DataTestMethod]
|
||||
[DataRow(null)]
|
||||
[DataRow("")]
|
||||
[DataRow(" ")]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public void ShouldThrowArgumentNullExceptionOnCreate(string portName)
|
||||
{
|
||||
// Arrange
|
||||
|
||||
// Act
|
||||
using var test = new ModbusSerialClient(portName);
|
||||
|
||||
// Assert - ArgumentNullException
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ObjectDisposedException))]
|
||||
public async Task ShouldThrowDisposedExceptionOnInvokeAsync()
|
||||
@@ -467,7 +482,7 @@ namespace AMWD.Protocols.Modbus.Tests.Serial
|
||||
return Task.FromResult(0);
|
||||
});
|
||||
|
||||
var connection = new ModbusSerialConnection();
|
||||
var connection = new ModbusSerialConnection("some-port");
|
||||
|
||||
// Replace real connection with mock
|
||||
var connectionField = connection.GetType().GetField("_serialPort", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
Serial Client COM-42
|
||||
BaudRate: 2400
|
||||
DataBits: 7
|
||||
StopBits: 1.5
|
||||
Parity: space
|
||||
Handshake: xonxoff
|
||||
RtsEnable: true
|
||||
DriverEnabledRS485: true
|
||||
Reference in New Issue
Block a user