예제 #1
0
        private void DecodeByteArray_ReturnTrue()
        {
            var testcase      = "5:hello";
            var bytes         = GetBytes(testcase);
            var decodedResult = BEncoding.DecodeNextObject(GetIterator(bytes)) as byte[];
            var decodedStr    = GetString(decodedResult);

            Debug.Assert(decodedStr == "hello");
        }
예제 #2
0
        private void DecodeInt_ReturnTrue()
        {
            var testcase = 2331;
            var bytes    = GetBytes($"i{testcase}e");
            var resObj   = BEncoding.DecodeNextObject(GetIterator(bytes));

            Debug.Assert(resObj is long);
            var intVal = (long)resObj;

            Debug.Assert(intVal == 2331);
        }
예제 #3
0
        private void DecodeDictionary_ReturnTrue()
        {
            var authorInfo = "i'am";
            var infoVal    = 331;
            var testcase   = $"d4:infoi{infoVal}e6:author{authorInfo.Length}:{authorInfo}";
            var bytes      = GetBytes(testcase);
            var result     = BEncoding.DecodeNextObject(GetIterator(bytes));

            Debug.Assert(result is IDictionary <string, object>);

            var dict = result as IDictionary <string, object>;

            Debug.Assert(dict.Keys.Contains("info"));
            Debug.Assert(dict.Keys.Contains("author"));
            Debug.Assert((long)dict["info"] == 331);

            var authorBytes  = GetBytes(authorInfo);
            var resultAuthor = (byte[])dict["author"];

            Debug.Assert(resultAuthor.Length == authorBytes.Length);
            Debug.Assert(authorBytes.SequenceEqual(resultAuthor));
        }