public async void ReadBitAsync_Should_Return_Value_On_Correct_Data(MemoryType memoryType, string address, int length) { //Arrange var connector = new EthernetConnector(new TcpSocket("127.0.0.1", 10621)); using var mockServer = new MockServer(new TcpServer(10621)); 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).ToDualByte()); response.AddRange(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 }); for (var i = 0; i < length; i++) { response.Add(1); } response.AddRange(response.Sum(x => x).ToDualByte()); return(response.ToArray()); }); var(responseCode, data) = await connector.ReadBitAsync(memoryType, address, length); mockServer.Stop(); //Assert Assert.Equal(ResponseCode.Success, responseCode); Assert.Equal(length, data.Length); }
public async void ReadBitAsync_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.ReadBitAsync(memoryType, address, length)); }