예제 #1
0
        private Torrent BuildTorrent(XmlNode node)
        {
            var name = node["title"]?.InnerText;

            if (_ignoreWords.Any(name.Contains)) return null;

            var downloadUrl = node["enclosure"].Attributes["url"].InnerText;

            var torrent = new Torrent
            {
                Name = name,
                PublicationDate = Convert.ToDateTime(node["pubDate"].InnerText),
                PageUrl = node["guid"].InnerText,
                MagnetUrl = node["torrent:magnetURI"].InnerText,
                DownloadUrl = downloadUrl
            };

            return torrent;
        }
예제 #2
0
        public void DownloadWantedEpisodes()
        {
            var service = new Mock<ITvService>();
            service.Setup(c => c.GetWantedEpisodes()).Returns(new List<TvEpisode> { new TvEpisode() { SeriesName = "SomeSeries", Season = 1, EpisodeNumber = 1 } });

            var torrent = new Torrent()
            {
                DownloadUrl = "DownloadUrl",
                Name = "Torrent"
            };

            var searchProvider = new Mock<ISearchProvider>();
            searchProvider.Setup(sp => sp.GetTorrent(It.IsAny<string>())).Returns(torrent);

            var webRequester = new Mock<IWebClient>();
            var analyticsService = new Mock<IAnalyticsService>();

            var downloader = new EpisodeDownloader(service.Object, searchProvider.Object, webRequester.Object, new TorrentSearchSettings() { TorrentWatchFolder = "WatchFolder\\" }, analyticsService.Object);
            downloader.DownloadWantedEpisodes().Wait();

            webRequester.Verify(wr => wr.DownloadFileAsync(torrent.DownloadUrl, "WatchFolder\\Torrent.torrent", null), Times.Once);
            service.Verify(s => s.AddOrUpdate(It.IsAny<TvEpisode>()), Times.AtLeastOnce);
            service.Verify(s => s.SaveChanges(), Times.Once);
        }