コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
            }
        }
コード例 #9
0
        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);
        }