Exemplo n.º 1
0
 public void benNumberDecoding()
 {
     foreach (var result in BEncodedValue.DecodingVariants <BEncodedNumber>(Encoding.UTF8.GetBytes("i12412e")))
     {
         Assert.AreEqual(result.ToString(), "12412");
         Assert.AreEqual(result.Number, 12412);
     }
 }
Exemplo n.º 2
0
 public void benDictionaryLengthInBytes()
 {
     byte[] data = Encoding.UTF8.GetBytes("d4:spaml1:a1:bee");
     foreach (var dict in BEncodedValue.DecodingVariants <BEncodedDictionary> (data))
     {
         Assert.AreEqual(data.Length, dict.LengthInBytes());
     }
 }
Exemplo n.º 3
0
 public void benListLengthInBytes()
 {
     byte[] data = Encoding.UTF8.GetBytes("l4:test5:tests6:testede");
     foreach (var list in BEncodedValue.DecodingVariants <BEncodedList> (data))
     {
         Assert.AreEqual(data.Length, list.LengthInBytes());
     }
 }
Exemplo n.º 4
0
        public void benNumber_MaxMin([Values(long.MinValue, long.MaxValue)] long value)
        {
            var number = new BEncodedNumber(value);

            foreach (var result in BEncodedValue.DecodingVariants <BEncodedNumber> (number.Encode()))
            {
                Assert.AreEqual(result.Number, value);
            }
        }
Exemplo n.º 5
0
        public void benNumberEncoding6()
        {
            BEncodedNumber a = -123;

            foreach (var b in BEncodedValue.DecodingVariants <BEncodedNumber> (a.Encode()))
            {
                Assert.AreEqual(a.Number, b.Number, "#1");
            }
        }
Exemplo n.º 6
0
        public void benListStackedTest()
        {
            string benString = "l6:stringl7:stringsl8:stringedei23456eei12345ee";

            foreach (var list in BEncodedValue.DecodingVariants <BEncodedList> (Encoding.UTF8.GetBytes(benString)))
            {
                string decoded = Encoding.UTF8.GetString(list.Encode());
                Assert.AreEqual(benString, decoded);
            }
        }
Exemplo n.º 7
0
        public void benDictionaryStackedTest()
        {
            string benString = "d4:testd5:testsli12345ei12345ee2:tod3:tomi12345eeee";

            byte[] data = Encoding.UTF8.GetBytes(benString);
            foreach (var dict in BEncodedValue.DecodingVariants <BEncodedDictionary> (data))
            {
                string decoded = Encoding.UTF8.GetString(dict.Encode());
                Assert.AreEqual(benString, decoded);
            }
        }
Exemplo n.º 8
0
 public void benListDecoding()
 {
     byte[] data = Encoding.UTF8.GetBytes("l4:test5:tests6:testede");
     foreach (var list in BEncodedValue.DecodingVariants <BEncodedList> (data))
     {
         Assert.AreEqual(list.Count, 3);
         Assert.AreEqual(list[0] is BEncodedString, true);
         Assert.AreEqual(((BEncodedString)list[0]).Text, "test");
         Assert.AreEqual(((BEncodedString)list[1]).Text, "tests");
         Assert.AreEqual(((BEncodedString)list[2]).Text, "tested");
     }
 }
Exemplo n.º 9
0
 public void benStringDecoding()
 {
     foreach (var str in new[] { "", "a", "this is a test string" })
     {
         var data = Encoding.UTF8.GetBytes($"{str.Length}:{str}");
         foreach (var result in BEncodedValue.DecodingVariants <BEncodedString> (data))
         {
             Assert.AreEqual(result.Text, str);
             Assert.AreEqual(str, result.ToString());
         }
     }
 }
Exemplo n.º 10
0
        public void benDictionaryDecoding()
        {
            byte[] data = Encoding.UTF8.GetBytes("d4:spaml1:a1:bee");
            foreach (var dict in BEncodedValue.DecodingVariants <BEncodedDictionary> (data))
            {
                Assert.AreEqual(dict.Count, 1);
                Assert.IsTrue(dict["spam"] is BEncodedList);

                BEncodedList list = (BEncodedList)dict["spam"];
                Assert.AreEqual(((BEncodedString)list[0]).Text, "a");
                Assert.AreEqual(((BEncodedString)list[1]).Text, "b");
            }
        }