예제 #1
0
        public void ShouldConvertCommandToJsonCorrectly()
        {
            //Arrange
            var testCommand = new UpdateSteeringInfoCommand(10, 10, true);

            var resultBytes = new byte[0];

            var tcpRawClientMock = new Mock <ITcpRawClient>();

            tcpRawClientMock.Setup(x => x.Send(It.IsAny <byte[]>()))
            .Callback <byte[]>(x => resultBytes = x);

            var tcpRawClientsFactoryMock = new Mock <ITcpRawClientsFactory>();

            tcpRawClientsFactoryMock.Setup(x => x.Create(It.IsAny <IpAddress>()))
            .Returns(tcpRawClientMock.Object);

            var tcpFacade = new TcpFacade(new IpAddress("127.0.0.1", 1234), tcpRawClientsFactoryMock.Object);

            //Act
            tcpFacade.Send(testCommand);

            //Assert
            var jsonTestCommand = JsonConvert.SerializeObject(testCommand, Formatting.None);
            var stringResult    = Encoding.UTF8.GetString(resultBytes);

            Assert.That(stringResult, Is.EqualTo(jsonTestCommand));
        }
        public void SendCommand <T>(T command, IpAddress ipAddress) where T : ICommand
        {
            var tcpFacade = new TcpFacade(ipAddress, this._tcpRawClientsFactory);

            tcpFacade.Send(command);
        }