Ejemplo n.º 1
0
        public void Serializes_ConnAck_Packet(bool sessionPresent, ConnectionResult result)
        {
            var packet = new ConnAck(result, sessionPresent);

            byte[] expected =
            {
                0b00100000,                           //packet code
                0x02,                                 //length
                (byte)(sessionPresent ? 0x01 : 0x00), //flags
                (byte)result
            };

            MqttSerializer.Serialize(bufferWriter, packet);

            VerifySerialization(expected);
        }
Ejemplo n.º 2
0
        public void Serializes_Connect_With_Username_Flag()
        {
            string username = Guid.NewGuid().ToString();
            var    packet   = new Connect
            {
                ClientId = Guid.NewGuid().ToString(),
                Flags    = ConnectFlags.UserName,
                UserName = username
            };
            var expected = CreateConnectHeader(packet);

            AddString(expected, username);
            SetRemainingLength(expected);

            MqttSerializer.Serialize(bufferWriter, packet);

            VerifySerialization(expected.ToArray());
        }
Ejemplo n.º 3
0
        public void Serializes_Connect_With_Password_Flag()
        {
            byte[] password = Guid.NewGuid().ToByteArray();
            var    packet   = new Connect
            {
                Flags    = ConnectFlags.Password,
                ClientId = Guid.NewGuid().ToString(),
                Password = password
            };
            var expected = CreateConnectHeader(packet);

            AddBinary(expected, password);
            SetRemainingLength(expected);

            MqttSerializer.Serialize(bufferWriter, packet);

            VerifySerialization(expected.ToArray());
        }
Ejemplo n.º 4
0
        public void Serializes_Connect(ConnectFlags flags)
        {
            ushort keepAlive = BitConverter.ToUInt16(Guid.NewGuid().ToByteArray(), 0);
            string clientId  = Guid.NewGuid().ToString();
            var    packet    = new Connect
            {
                Flags     = flags,
                KeepAlive = keepAlive,
                ClientId  = clientId
            };
            var expected = CreateConnectHeader(packet);

            SetRemainingLength(expected);

            MqttSerializer.Serialize(bufferWriter, packet);

            VerifySerialization(expected.ToArray());
        }
Ejemplo n.º 5
0
        public void Serializes_Connect_With_Will_Flag()
        {
            string willTopic = Guid.NewGuid().ToString();

            byte[] willMessage = Guid.NewGuid().ToByteArray();
            var    packet      = new Connect
            {
                ClientId    = Guid.NewGuid().ToString(),
                Flags       = ConnectFlags.Will,
                WillTopic   = willTopic,
                WillMessage = willMessage
            };
            var expected = CreateConnectHeader(packet);

            AddString(expected, willTopic);
            AddBinary(expected, willMessage);
            SetRemainingLength(expected);

            MqttSerializer.Serialize(bufferWriter, packet);

            VerifySerialization(expected.ToArray());
        }