public void DeserializesMessageCorrectly_Action(ProtocolMessage.MessageAction action) { // Arrange string message = $"{{ \"action\": {(int)action} }}"; // Act ProtocolMessage target = JsonHelper.Deserialize <ProtocolMessage>(message); // Assert target.Should().NotBeNull(); Assert.Equal(action, target.Action); }
public void DeserializesMessageCorrectly_Count(int count) { // Arrange byte[] expectedMessage = MsgPackHelper.Serialise(new ProtocolMessage() { Count = count }) as byte[]; // Act ProtocolMessage target = MsgPackHelper.Deserialise <ProtocolMessage>(expectedMessage); // Assert target.Should().NotBeNull(); Assert.Equal(count, target.Count.Value); }
public void DeserializesMessageCorrectly_MsgSerial(long serial) { // Arrange List <byte> expectedMessage = new List <byte>(); expectedMessage.Add(0x81); expectedMessage.AddRange(SerializeString("msgSerial")); expectedMessage.Add(BitConverter.GetBytes(serial).First()); // Act ProtocolMessage target = MsgPackHelper.Deserialise <ProtocolMessage>(expectedMessage.ToArray()); // Assert target.Should().NotBeNull(); Assert.Equal <long>(serial, target.MsgSerial); }
public void DeserializesMessageCorrectly_Id(string id) { // Arrange List <byte> expectedMessage = new List <byte>(); expectedMessage.Add(0x81); expectedMessage.AddRange(SerializeString("id")); expectedMessage.AddRange(SerializeString(id)); // Act ProtocolMessage target = MsgPackHelper.Deserialise <ProtocolMessage>(expectedMessage.ToArray()); // Assert target.Should().NotBeNull(); Assert.Equal(id, target.Id); }
public void DeserializesMessageCorrectly_ConnectionKey(string connectionKey) { // Arrange List <byte> expectedMessage = new List <byte>(); expectedMessage.Add(0x81); expectedMessage.AddRange(SerializeString("connectionKey")); expectedMessage.AddRange(SerializeString(connectionKey)); // Act ProtocolMessage target = MsgPackHelper.Deserialise <ProtocolMessage>(expectedMessage.ToArray()); // Assert target.Should().NotBeNull(); Assert.Equal(connectionKey, target.ConnectionKey); }
public void DeserializesMessageCorrectly_Action(ProtocolMessage.MessageAction action) { // Arrange List <byte> expectedMessage = new List <byte>(); expectedMessage.Add(0x81); expectedMessage.AddRange(SerializeString("action")); expectedMessage.Add((byte)action); // Act ProtocolMessage target = MsgPackHelper.Deserialise <ProtocolMessage>(expectedMessage.ToArray()); // Assert target.Should().NotBeNull(); Assert.Equal(action, target.Action); }
public void DeserializesMessageCorrectly_Flags(int flags) { // Arrange List <byte> expectedMessage = new List <byte>(); expectedMessage.Add(0x81); expectedMessage.AddRange(SerializeString("flags")); expectedMessage.Add((byte)flags); // Act ProtocolMessage target = MsgPackHelper.Deserialise <ProtocolMessage>(expectedMessage.ToArray()); // Assert target.Should().NotBeNull(); Assert.Equal <byte>((byte)flags, (byte)target.Flags); }
public void DeserializesMessageCorrectly_Messages(byte[] messageBin, params Message[] expectedMessages) { // Arrange List <byte> expectedMessage = new List <byte>(); expectedMessage.Add(0x81); expectedMessage.AddRange(SerializeString("messages")); expectedMessage.AddRange(messageBin); // Act ProtocolMessage target = MsgPackHelper.Deserialise <ProtocolMessage>(expectedMessage.ToArray()); // Assert target.Should().NotBeNull(); target.Messages.Should().NotBeNull(); Assert.Equal <int>(expectedMessages.Length, target.Messages.Length); for (int i = 0; i < expectedMessages.Length; i++) { Assert.Equal(expectedMessages[i].Name, target.Messages[i].Name); Assert.Equal(expectedMessages[i].Data, target.Messages[i].Data); } }
public void DeserializesMessageCorrectly_ChannelSerial(string serial) { // Arrange List <byte> expectedMessage = new List <byte>(); expectedMessage.Add(0x81); expectedMessage.AddRange(SerializeString("channelSerial")); if (serial != null) { expectedMessage.AddRange(SerializeString(serial)); } else { expectedMessage.Add(0xc0); } // Act ProtocolMessage target = MsgPackHelper.Deserialise <ProtocolMessage>(expectedMessage.ToArray()); // Assert target.Should().NotBeNull(); Assert.Equal(serial, target.ChannelSerial); }