示例#1
0
        static void Main(string[] args)
        {
            if (args.Length == 1)
            {
                var inFileStream = new FileStream(args[0], FileMode.Open);

                //BEncoding
                var transform = new BObjectTransform();
                IBObject bObject = transform.DecodeNext(inFileStream);

                var textOutput = new TextOutput(4);
                textOutput.WriteObject(0, bObject);
            }
            else
            {
                Console.WriteLine("\nSyntax is:\nOSS.SampleApp.exe <torrent file path>");
            }
        }
        public void DecodeNext_EmptyStringFollowingEmptyString_Positive()
        {
            string str3 = "hello";      // third example string in test data list

            var dataStream = new MemoryStream(Encoding.UTF8.GetBytes("l0:0:5:" + str3 + "e"), false);      // list with two empty string, followed by "hello"

            var bot = new BObjectTransform();
            IBObject decodedList = bot.DecodeNext(dataStream);

            Assert.IsNotNull(decodedList);
            Assert.IsInstanceOfType(decodedList, typeof(BList));

            var castList = (BList)decodedList;

            Assert.AreEqual<int>(3, castList.Value.Length);
            Assert.IsInstanceOfType(castList.Value[0], typeof(BByteString));
            Assert.IsInstanceOfType(castList.Value[1], typeof(BByteString));
            Assert.IsInstanceOfType(castList.Value[2], typeof(BByteString));

            Assert.AreEqual<string>(string.Empty, ((BByteString)castList.Value[0]).ConvertToText(Encoding.UTF8));
            Assert.AreEqual<string>(string.Empty, ((BByteString)castList.Value[1]).ConvertToText(Encoding.UTF8));
            Assert.AreEqual<string>(str3, ((BByteString)castList.Value[2]).ConvertToText(Encoding.UTF8));
        }
        public void DecodeNext_NineLetterString_Positive()
        {
            string testWord = "debugging";
            var dataStream = new MemoryStream(Encoding.UTF8.GetBytes("9:" + testWord), false);

            var bot = new BObjectTransform();
            IBObject decodedString = bot.DecodeNext(dataStream);

            Assert.IsNotNull(decodedString);
            Assert.IsInstanceOfType(decodedString, typeof(BByteString));
            var castDecodedString = (BByteString)decodedString;
            Assert.AreEqual<string>(testWord, castDecodedString.ConvertToText(Encoding.UTF8));
        }
        public void DecodeNext_EmptyString_Positive()
        {
            var dataStream = new MemoryStream(Encoding.UTF8.GetBytes("0:"), false);

            var bot = new BObjectTransform();
            IBObject decodedString = bot.DecodeNext(dataStream);

            Assert.IsNotNull(decodedString);
            Assert.IsInstanceOfType(decodedString, typeof(BByteString));
            var castDecodedString = (BByteString)decodedString;
            Assert.AreEqual<string>(string.Empty, castDecodedString.ConvertToText(Encoding.UTF8));
        }