public async void ReadWordAsync_Should_Return_Value_On_Correct_Data(MemoryType memoryType, string address, int length) { //Arrange var connector = new EthernetConnector(new TcpSocket("127.0.0.1", 10620)); using var mockServer = new MockServer(new TcpServer(10620)); mockServer.Start(); //Act mockServer.Mock.Send("").Receive(x => { var response = new List <byte>(); response.AddRange(Encoding.ASCII.GetBytes("KDT_PLC_S")); response.Add((byte)(x[9] + 128)); response.Add(x[10]); response.Add(0); response.AddRange((9 + length * 2).ToDualByte()); response.AddRange(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 }); for (var i = 0; i < length; i++) { response.AddRange(new byte[] { 1, 1 }); } response.AddRange(response.Sum(x => x).ToDualByte()); return(response.ToArray()); }); var(responseCode, data) = await connector.ReadWordAsync(memoryType, address, length); mockServer.Stop(); //Assert Assert.Equal(ResponseCode.Success, responseCode); Assert.Equal(length, data.Length); }
public async void ReadWordAsync_Should_Return_Error_On_Incorrect_Data(MemoryType memoryType, string address, int length) { //Arrange var connector = new EthernetConnector(new TcpSocket("127.0.0.1", 10620)); //Assert await Assert.ThrowsAnyAsync <ArgumentException>(() => connector.ReadWordAsync(memoryType, address, length)); }