コード例 #1
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);
        }
コード例 #2
0
        public void Test1ByteMaxValueEncode()
        {
            EncodedRemainingLength erl = new EncodedRemainingLength(127);
            var bytes = erl.Encode().ToArray();

            Assert.IsTrue(bytes.Length == 1);
            Assert.IsTrue(bytes[0] == 0x7F);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }