public void DictionaryDecode_SimpleSample_Positive() { // Prep input var inputBytes = "d4:spami4e3:ham2:oke".GetASCIIBytes(); var inputStream = new MemoryStream(inputBytes, false); inputStream.Position = 0; // Prep expected data KeyValuePair<BByteString, BInteger> expectedKV1 = new KeyValuePair<BByteString,BInteger>(new BByteString("spam"), new BInteger(4)); KeyValuePair<BByteString, BByteString> expectedKV2 = new KeyValuePair<BByteString, BByteString>(new BByteString("ham"), new BByteString("ok")); var transform = new DictionaryTransform(new BObjectTransform()); var outputBDictionary = transform.Decode(inputStream); // Assert output data var outputDict = outputBDictionary.Value; Assert.AreEqual<BObjectType>(BObjectType.Dictionary, outputBDictionary.BType); Assert.AreEqual(2, outputDict.Count); // Ensure key-value pair 1 is in the output: Assert.IsTrue(outputDict.ContainsKey(expectedKV1.Key)); var outputValue1 = (BInteger) outputDict[expectedKV1.Key]; Assert.AreEqual<long>(expectedKV1.Value.Value, outputValue1.Value); // Ensure key-value pair 2 is in the output: Assert.IsTrue(outputDict.ContainsKey(expectedKV2.Key)); var outputValue2 = (BByteString)outputDict[expectedKV2.Key]; Assert.IsTrue(expectedKV2.Value.Value.IsEqualWith(outputValue2.Value), "Byte strings are not equal for key-value pair 2"); }
public void DictionaryDecode_NoKeyValuePairs_Positive() { var inputBytes = "de".GetASCIIBytes(); var inputStream = new MemoryStream(inputBytes, false); inputStream.Position = 0; var transform = new DictionaryTransform(new BObjectTransform()); var outputBDictionary = transform.Decode(inputStream); Assert.AreEqual<int>(0, outputBDictionary.Value.Count); }