public void EncodeObject_BDictionary_Positive()
        {
            string expectedOutput = "d3:one9:value_one3:twoi1ee";
            MemoryStream outputBuffer = new MemoryStream(64);

            // Create input test data
            BDictionary data = new BDictionary();
            data.Value.Add(new BByteString("one"), new BByteString("value_one"));
            data.Value.Add(new BByteString("two"), new BInteger(1));

            // Test
            var bot = new BObjectTransform();
            bot.EncodeObject(data, outputBuffer);

            // Get result and check it
            int length = (int) outputBuffer.Position;
            string actualOutput = Encoding.UTF8.GetString(outputBuffer.ToArray(), 0, length);

            Assert.AreEqual<string>(expectedOutput, actualOutput);
        }
Exemple #2
0
        public void SaveTorrentFile()
        {
            if (!TorrentPrepared) { return; }

            BDictionary torrent = new BDictionary();
            torrent.Value.Add(new BByteString("announce"), torrentSaved.GetAnnounce());
            torrent.Value.Add(new BByteString("info"), torrentSaved.GetInfo());
            torrent.Value.Add(new BByteString("creation date"), new BInteger(TimeUnix()));

            using (FileStream outputFileStream = new FileStream(torrentSaved.FileName, FileMode.Create, FileAccess.Write))
            {
                BObjectTransform objTransform = new BObjectTransform();
                objTransform.EncodeObject(torrent, outputFileStream);
            }
            Console.WriteLine("\n{0} [{1}]\n", messages.GetMessage("TorrentCreated"), torrentSaved.FileName);
        }