示例#1
0
        public void TestGetTorrentDetailsReturnsCorrectDetails()
        {
            MetaInfoFile file = new MetaInfoFile(Constants.SingleFileTorrent);

            file.Parse();
            Manager manager = new Manager();
            Mock <IAgentNetwork> networkMock = new Mock <IAgentNetwork>();
            Agent agent = new Agent(new Manager(), new Assembler(), networkMock.Object);

            agent.Startup();
            TorrentContext tc = new TorrentContext(file, new Selector(), new DiskIO(manager), Constants.DestinationDirectory);

            _ = new Tracker(tc);
            agent.AddTorrent(tc);
            TorrentDetails details = agent.GetTorrentDetails(tc);

            Assert.Equal(0, details.deadPeers);
            Assert.Equal(0, (int)details.downloadedBytes);
            Assert.Equal(Constants.SingleFileTorrent, details.fileName);
            Assert.Equal(file.GetInfoHash(), details.infoHash);
            Assert.Equal(22, details.missingPiecesCount);
            Assert.Equal(0, (int)details.peers.Count);
            Assert.Equal(TorrentStatus.Initialised, details.status);
            Assert.Equal(0, details.swarmSize);
            Assert.Equal(TrackerStatus.Stopped, details.trackerStatus);
            Assert.Null(details.trackerStatusMessage);
            Assert.Equal(0, (int)details.uploadedBytes);
        }
        public void TestGetInfoHashOentCheckInfoHash(string file, string expected)
        {
            MetaInfoFile torrentFile = new MetaInfoFile(file);

            torrentFile.Parse();
            byte[]        infoHash = torrentFile.GetInfoHash();
            StringBuilder actual   = new StringBuilder(infoHash.Length);

            foreach (byte b in infoHash)
            {
                actual.AppendFormat("{0:x2}", b);
            }
            Assert.Equal(expected, actual.ToString());
        }
        public void TestGetInfoHashWithNoParseOnMetaInfoFile()
        {
            MetaInfoFile        torrentFile = new MetaInfoFile(Constants.SingleFileTorrent);
            BitTorrentException error       = Assert.Throws <BitTorrentException>(() => { byte[] infoHash = new byte[20]; infoHash = torrentFile.GetInfoHash(); });

            Assert.Equal("BitTorrent Error: File has not been parsed.", error.Message);
        }