public void Encode_Complex() { var bdict = new BDictionary { {"spam", "egg"}, { "A List", new BList { "foo", "bar", 123, new BDictionary { {"more spam", "more eggs"} } } }, { "foobar", new BDictionary { {"numbers", new BList {1, 2, 3}} } } }; // Keys should be sorted in lexical order var expected = "d6:A Listl3:foo3:bari123ed9:more spam9:more eggsee6:foobard7:numbersli1ei2ei3eee4:spam3:egge"; var actual = bdict.Encode(); Assert.AreEqual(expected, actual); }
private void TestBDictionary(Dictionary <BString, BObject> testDictionary) { BDictionary bDictionary = new BDictionary(testDictionary); byte[] encoded = bDictionary.Encode(); Assert.True(BObject.TryParse(encoded, out BDictionary bObject)); Assert.True(bDictionary.Equals(bObject)); using (MemoryStream ms = new MemoryStream()) { bDictionary.Encode(ms); encoded = ms.ToArray(); } Assert.True(BObject.TryParse(encoded, out bObject)); Assert.True(bDictionary.Equals(bObject)); Assert.Equal(encoded.Length, bDictionary.GetEncodedSize()); }
public void BDictionary_TooDeep() { BDictionary dictionary = new BDictionary(); BDictionary child = new BDictionary(); dictionary.Add("key-1", child); for (int i = 0; i < BObject.RecursionLimit; i++) { BDictionary subChild = new BDictionary(); child.Add("key" + i.ToString(), subChild); child = subChild; } Assert.Throws <StackOverflowException>(() => { dictionary.Encode(); }); }
public void Encode_Simple() { var bdict = new BDictionary { {"foobar", "Hello World!"}, {"number", 747}, {"key", "value"} }; // Keys should be sorted in lexical order var expected = "d6:foobar12:Hello World!3:key5:value6:numberi747ee"; var actual = bdict.Encode(); Assert.AreEqual(expected, actual); }
public void Encode_EmptyDictionary() { var bdict = new BDictionary(); Assert.AreEqual("de", bdict.Encode()); }