Esempio n. 1
0
        public async void WriteWordAsync_Should_Return_Value_On_Correct_Data(MemoryType memoryType, string address, params int[] data)
        {
            //Arrange
            var connector = new EthernetConnector(new TcpSocket("127.0.0.1", 10622));

            using var mockServer = new MockServer(new TcpServer(10622));
            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(0x41);
                response.Add(0);
                response.AddRange(new byte[] { 0, 2, 0, 0 });
                response.AddRange(response.Sum(x => x).ToDualByte());
                return(response.ToArray());
            });
            var result = await connector.WriteWordAsync(memoryType, address, data);

            mockServer.Stop();

            //Assert
            Assert.Equal(ResponseCode.Success, result);
        }
Esempio n. 2
0
        public async void WriteWordAsync_Should_Return_Error_On_Incorrect_Data(MemoryType memoryType, string address, params int[] data)
        {
            //Arrange
            var connector = new EthernetConnector(new TcpSocket("127.0.0.1", 10620));

            //Assert
            await Assert.ThrowsAnyAsync <ArgumentException>(() => connector.WriteWordAsync(memoryType, address, data));
        }