public void TestDecodeStream()
 {
     using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
     {
         BinaryBencoding.Decode(ms);
     }
 }
        public void TestBEncodeComplexString()
        {
            const string initialString = "d5:itemsli45e28:aBCdefghijklmnopqrstuvwxyz12ee";

            IBElement[] result = BinaryBencoding.Decode(initialString);
            Assert.IsNotNull(result);
            string encodedString = string.Join("", result.Select(e => e.ToBencodedString()));

            Assert.AreEqual(initialString, encodedString, true);
        }
        public void TestDecodeBInteger()
        {
            IBElement[] list = BinaryBencoding.Decode("i45e");
            Assert.IsNotNull(list);
            Assert.AreEqual(1, list.Length);
            Assert.IsNotNull(list[0]);
            Assert.IsInstanceOfType(list[0], typeof(BInteger));
            BInteger integer = (BInteger)list[0];

            Assert.AreEqual(45L, integer.Value);
        }
        public void TestDecodeBString()
        {
            IBElement[] list = BinaryBencoding.Decode("28:aBCdefghijklmnopqrstuvwxyz12");
            Assert.IsNotNull(list);
            Assert.AreEqual(1, list.Length);
            Assert.IsNotNull(list[0]);
            Assert.IsInstanceOfType(list[0], typeof(BString));
            BString str = (BString)list[0];

            Assert.AreEqual("aBCdefghijklmnopqrstuvwxyz12", str.Value);
        }
        public void TestDecodeBDictionary()
        {
            IBElement[] result = BinaryBencoding.Decode("d5:itemsli45e28:aBCdefghijklmnopqrstuvwxyz12ee");
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Length);
            Assert.IsNotNull(result[0]);
            Assert.IsInstanceOfType(result[0], typeof(BDictionary));
            BDictionary dict = (BDictionary)result[0];

            Assert.AreEqual(1, dict.Count);

            var item = dict.First();

            Assert.IsNotNull(item);

            BString key = item.Key;

            Assert.IsNotNull(key);
            Assert.AreEqual("items", key.Value);

            Assert.IsNotNull(item.Value);
            Assert.IsInstanceOfType(item.Value, typeof(BList));
            BList list = (BList)item.Value;

            Assert.AreEqual(2, list.Count);

            Assert.IsNotNull(list[0]);
            Assert.IsInstanceOfType(list[0], typeof(BInteger));
            BInteger integer = (BInteger)list[0];

            Assert.AreEqual(45L, integer.Value);

            Assert.IsNotNull(list[1]);
            Assert.IsInstanceOfType(list[1], typeof(BString));
            BString str = (BString)list[1];

            Assert.AreEqual("aBCdefghijklmnopqrstuvwxyz12", str.Value);
        }
        public void TestDecodeBList()
        {
            IBElement[] result = BinaryBencoding.Decode("li45e28:aBCdefghijklmnopqrstuvwxyz12e");
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Length);
            Assert.IsNotNull(result[0]);
            Assert.IsInstanceOfType(result[0], typeof(BList));
            BList list = (BList)result[0];

            Assert.AreEqual(2, list.Count);

            Assert.IsNotNull(list[0]);
            Assert.IsInstanceOfType(list[0], typeof(BInteger));
            BInteger integer = (BInteger)list[0];

            Assert.AreEqual(45L, integer.Value);

            Assert.IsNotNull(list[1]);
            Assert.IsInstanceOfType(list[1], typeof(BString));
            BString str = (BString)list[1];

            Assert.AreEqual("aBCdefghijklmnopqrstuvwxyz12", str.Value);
        }
        public void TestBEncodeComplexString2()
        {
            const string initialString = "i456e2:bei67e";

            IBElement[] result = BinaryBencoding.Decode(initialString);
            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.Length);

            BInteger integer = result[0] as BInteger;

            Assert.IsNotNull(integer);
            Assert.AreEqual(456, integer.Value);

            BString str = result[1] as BString;

            Assert.IsNotNull(str);
            Assert.AreEqual("be", str.Value);

            BInteger integer2 = result[2] as BInteger;

            Assert.IsNotNull(integer2);
            Assert.AreEqual(67, integer2.Value);
        }
Exemplo n.º 8
0
 public void TestDecodeNullString()
 {
     Assert.ThrowsException <ArgumentNullException>(() => BinaryBencoding.Decode(bencodedValue: null));
 }
 public void TestDecodeInvalidBIteger_4()
 {
     BinaryBencoding.Decode("ie");
 }
 public void TestDecodeInvalidBIteger_2()
 {
     BinaryBencoding.Decode("45");
 }
Exemplo n.º 11
0
 public void TestDecodeInvalidBElement_1()
 {
     Assert.ThrowsException <BencodingException>(() => BinaryBencoding.Decode("k"));
 }
 public void TestDecodeInvalidBElement_1()
 {
     BinaryBencoding.Decode("k");
 }
Exemplo n.º 13
0
 public void TestDecodeInvalidBIteger_4()
 {
     Assert.ThrowsException <BencodingException>(() => BinaryBencoding.Decode("ie"));
 }
 public void TestDecodeNullStream()
 {
     BinaryBencoding.Decode(input: null);
 }
Exemplo n.º 15
0
 public void TestDecodeInvalidBString_1()
 {
     Assert.ThrowsException <BencodingException>(() => BinaryBencoding.Decode(":aze"));
 }
Exemplo n.º 16
0
 public void TestDecodeNullStream()
 {
     Assert.ThrowsException <ArgumentNullException>(() => BinaryBencoding.Decode(input: null));
 }
 public void TestDecodeEmptyString()
 {
     IBElement[] result = BinaryBencoding.Decode("");
     Assert.IsNotNull(result);
     Assert.AreEqual(0, result.Length);
 }
 public void TestDecodeNullString()
 {
     BinaryBencoding.Decode(bencodedValue: null);
 }
 public void TestDecodeInvalidBString_3()
 {
     BinaryBencoding.Decode("5:");
 }
 public void TestDecodeInvalidBString_1()
 {
     BinaryBencoding.Decode(":aze");
 }