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

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

            Assert.AreEqual(initialString, encodedString, true);
        }
        public void TestDecodeBInteger()
        {
            IBElement[] list = BencodeDecoder.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 = BencodeDecoder.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 = BencodeDecoder.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 = BencodeDecoder.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);
        }
예제 #7
0
 public void TestDecodeNullString()
 {
     Assert.ThrowsException <ArgumentNullException>(() => BencodeDecoder.Decode(bencodedValue: null));
 }
 public void TestDecodeInvalidBIteger_4()
 {
     BencodeDecoder.Decode("ie");
 }
 public void TestDecodeInvalidBIteger_3()
 {
     BencodeDecoder.Decode("45e");
 }
예제 #10
0
 public void TestDecodeInvalidBIteger_1()
 {
     BencodeDecoder.Decode("i45");
 }
예제 #11
0
 public void TestDecodeInvalidBElement_1()
 {
     Assert.ThrowsException <BencodingException>(() => BencodeDecoder.Decode("k"));
 }
예제 #12
0
 public void TestDecodeInvalidBElement_1()
 {
     BencodeDecoder.Decode("k");
 }
예제 #13
0
 public void TestDecodeInvalidBIteger_4()
 {
     Assert.ThrowsException <BencodingException>(() => BencodeDecoder.Decode("ie"));
 }
예제 #14
0
 public void TestDecodeNullStream()
 {
     BencodeDecoder.Decode(input: null);
 }
예제 #15
0
 public void TestDecodeInvalidBString_1()
 {
     Assert.ThrowsException <BencodingException>(() => BencodeDecoder.Decode(":aze"));
 }
예제 #16
0
 public void TestDecodeNullStream()
 {
     Assert.ThrowsException <ArgumentNullException>(() => BencodeDecoder.Decode(input: null));
 }
예제 #17
0
 public void TestDecodeEmptyString()
 {
     IBElement[] result = BencodeDecoder.Decode("");
     Assert.IsNotNull(result);
     Assert.AreEqual(0, result.Length);
 }
예제 #18
0
 public void TestDecodeNullString()
 {
     BencodeDecoder.Decode(bencodedValue: null);
 }
예제 #19
0
 public void TestDecodeInvalidBString_3()
 {
     BencodeDecoder.Decode("5:");
 }
예제 #20
0
 public void TestDecodeInvalidBString_2()
 {
     BencodeDecoder.Decode("5:aze");
 }