public void TestEncodeDictionary1() { //Test1 DictNode dict1 = new DictNode(); string source1 = BEncode.StringEncode(dict1); Assert.AreEqual(source1, "[]"); //Test2 DictNode dict2 = new DictNode(); dict2.Add("age", 25); dict2.Add("eyes", "blue"); string source2 = BEncode.StringEncode(dict2); Assert.AreEqual(source2, "[3:agei25e4:eyes4:blue]"); //Test3 DictNode dh31 = new DictNode(); dh31.Add(Encoding.Default.GetBytes("author"), "Alice"); dh31.Add("length", 1048576); DictNode dict3 = new DictNode(); dict3.Add("spam.mp3", dh31); string source3 = BEncode.StringEncode(dict3); Assert.AreEqual(source3, "[8:spam.mp3[6:author5:Alice6:lengthi1048576e]]"); Assert.AreEqual(dict3.ToString(), "[8:spam.mp3[6:author5:Alice6:lengthi1048576e]]"); }
public void TestEncodeDictionary1() { //Test1 DictNode dict1 = new DictNode(); string source1 = BEncodingFactory.StringEncode(dict1); Assert.AreEqual(source1, "de"); //Test2 DictNode dict2 = new DictNode(); dict2.Add("age", 25); dict2.Add("eyes", "blue"); string source2 = BEncodingFactory.StringEncode(dict2); Assert.AreEqual(source2, "d3:agei25e4:eyes4:bluee"); //Test3 DictNode dh31 = new DictNode(); dh31.Add("author", "Alice"); dh31.Add("length", 1048576); DictNode dict3 = new DictNode(); dict3.Add("spam.mp3", dh31); string source3 = BEncodingFactory.StringEncode(dict3); Assert.AreEqual(source3, "d8:spam.mp3d6:author5:Alice6:lengthi1048576eee"); Assert.AreEqual(dict3.ToString(), "d8:spam.mp3d6:author5:Alice6:lengthi1048576eee"); }