public void Test1ByteMaxValueDecode()
        {
            byte[] bytes = new byte[] { 0x7F };
            EncodedRemainingLength erl = new EncodedRemainingLength(bytes);

            Assert.AreEqual((UInt32)127, erl.Length);
        }
        public void Test2ByteMinValueDecode()
        {
            byte[] bytes = new byte[] { 0x80, 0x01 };
            EncodedRemainingLength erl = new EncodedRemainingLength(bytes);

            Assert.AreEqual((UInt32)128, erl.Length);
        }
Пример #3
0
        public void TestUsernameAndPwordEncode()
        {
            string                 username = "******";
            string                 password = "******";
            UTF8Encoding           utf8     = new UTF8Encoding();
            Authentication         auth     = new Authentication(username, password);
            EncodedRemainingLength erl      = new EncodedRemainingLength((uint)password.Length);

            List <byte> expectedBytes = new List <byte>();

            expectedBytes.AddRange(utf8.GetBytes(username));
            expectedBytes.AddRange(erl.Encode());
            expectedBytes.AddRange(utf8.GetBytes(password));

            Assert.AreEqual(expectedBytes.Count, auth.Encode().Count());

            for (int i = 0; i < expectedBytes.Count; i++)
            {
                Assert.AreEqual(expectedBytes[i], auth.Encode().ToArray()[i]);
            }

            byte[] passwordBytes   = auth.Encode().Skip(username.Length).Skip(erl.Encode().Count()).ToArray();
            string decodedPassword = utf8.GetString(passwordBytes);

            Assert.AreEqual(password, decodedPassword);
        }
        public void Test1ByteMaxValueEncode()
        {
            EncodedRemainingLength erl = new EncodedRemainingLength(127);
            var bytes = erl.Encode().ToArray();

            Assert.IsTrue(bytes.Length == 1);
            Assert.IsTrue(bytes[0] == 0x7F);
        }
        public void Test2ByteMinValueEncode()
        {
            EncodedRemainingLength erl = new EncodedRemainingLength(128);
            var bytes = erl.Encode().ToArray();

            Assert.IsTrue(bytes.Length == 2);
            Assert.IsTrue(bytes[0] == 0x80);
            Assert.IsTrue(bytes[1] == 0x01);
        }
        public void Test3ByteMaxValueEncode()
        {
            EncodedRemainingLength erl = new EncodedRemainingLength(2097151);
            var bytes = erl.Encode().ToArray();

            Assert.IsTrue(bytes.Length == 3);
            Assert.IsTrue(bytes[0] == 0xFF);
            Assert.IsTrue(bytes[1] == 0xFF);
            Assert.IsTrue(bytes[2] == 0x7F);
        }
        public void Test4ByteMaxValueEncode()
        {
            EncodedRemainingLength erl = new EncodedRemainingLength(268435455);
            var bytes = erl.Encode().ToArray();

            Assert.IsTrue(bytes.Length == 4);
            Assert.IsTrue(bytes[0] == 0xFF);
            Assert.IsTrue(bytes[1] == 0xFF);
            Assert.IsTrue(bytes[2] == 0xFF);
            Assert.IsTrue(bytes[3] == 0x7F);
        }
Пример #8
0
 protected FixedHeader(ControlPacketType type, ControlPacketFlags flags, UInt32 remainingLength = 0)
 {
     Type            = type;
     Flags           = flags;
     RemainingLength = new EncodedRemainingLength(remainingLength);
 }