public void ShouldSendAPacket() { // arrange const int expectedPacketSize = 7; var packetFragments = new List <IPacketFragment>() { new CommandPacketFragment(MessageType.DeviceCommand), new PinNumberPacketFragment(0), new SignalPacketFragment(true) }; var packet = new ActuationPacket(packetFragments); var endpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8080); var mockSocketProxy = new Mock <ISocketProxy>(); mockSocketProxy.Setup(socketProxy => socketProxy.Send(It.IsAny <byte[]>())) .Returns(expectedPacketSize); var sut = new ClientSocket(endpoint, mockSocketProxy.Object); // act sut.Send(packet); // assert mockSocketProxy.Verify(socketProxy => socketProxy.Send(It.IsAny <byte[]>()), Times.Once); }
public void ShouldSerializeAPacket() { // arrange var expectedRawPacket = "0 01 1\0"; var expectedPacket = Encoding.ASCII.GetBytes(expectedRawPacket); var packetFragments = new List <IPacketFragment>() { new CommandPacketFragment(MessageType.DeviceCommand), new PinNumberPacketFragment(1), new SignalPacketFragment(true) }; var sut = new ActuationPacket(packetFragments); Assert.NotNull(sut); // act var actualPacket = sut.Serialize(); // assert Assert.NotNull(actualPacket); Assert.AreEqual(expectedPacket, actualPacket, "Packet"); }
public void SendCommand(MessageType messageType, int pinNumber, bool signal) { // Note: potentially abstract this later var packetFragments = new List <IPacketFragment>() { new CommandPacketFragment(messageType), new PinNumberPacketFragment(pinNumber), new SignalPacketFragment(signal) }; var packet = new ActuationPacket(packetFragments); _clientSocket.Send(packet); }