Esempio n. 1
0
        public async Task GetEpisodesAsync_FailedResponse_ReturnsNone()
        {
            _jsonConnection.GetAsync(Arg.Any <GetEpisodesRequest>(), Arg.Any <Option <string> >())
            .Returns(new FailedRequest(HttpStatusCode.BadRequest, "Failed"));

            var tvDbClient = new TvDbClient(_jsonConnection, _fileCache, _applicationPaths, _logManager,
                                            new JsonSerialiser(), new PluginConfiguration());

            var episodes = await tvDbClient.GetEpisodesAsync(4);

            episodes.IsSome.Should().BeFalse();
        }
Esempio n. 2
0
        public async Task GetEpisodesAsync_LocalEpisodeData_ReturnsLocalEpisodeData()
        {
            var episode = new TvDbEpisodeData(1, "Test", 1L, 2, 3, 4, new DateTime(2017, 1, 2, 3, 4, 5), "Overview", 3.77f, 12);

            _fileCache.GetFileContent(Arg.Any <TvDbSeriesEpisodesFileSpec>())
            .Returns(new TvDbEpisodeCollection(new[] { episode }));

            var tvDbClient = new TvDbClient(_jsonConnection, _fileCache, _applicationPaths, _logManager,
                                            new JsonSerialiser(), new PluginConfiguration());

            var episodes = await tvDbClient.GetEpisodesAsync(4);

            episodes.IsSome.Should().BeTrue();
            episodes.ValueUnsafe().Should().BeEquivalentTo(episode);
        }
Esempio n. 3
0
        public async Task GetEpisodesAsync_LocalEpisodeData_DoesNotRequestEpisodeData()
        {
            var episode = new TvDbEpisodeData(1, "Test", 1L, 2, 3, 4, new DateTime(2017, 1, 2, 3, 4, 5), "Overview", 3.77f, 12);

            _fileCache.GetFileContent(Arg.Any <TvDbSeriesEpisodesFileSpec>())
            .Returns(new TvDbEpisodeCollection(new[] { episode }));

            var tvDbClient = new TvDbClient(_jsonConnection, _fileCache, _applicationPaths, _logManager,
                                            new JsonSerialiser(), new PluginConfiguration());

            await tvDbClient.GetEpisodesAsync(4);

            _jsonConnection.DidNotReceiveWithAnyArgs()
            .GetAsync <GetEpisodesRequest.Response>(null, Option <string> .None);
        }
Esempio n. 4
0
        public async Task GetEpisodesAsync_MultiPageResponse_RequestsAllPages()
        {
            var page1Episode       = new TvDbEpisodeSummaryData(1, "Test1", 1L, 2, 3, 4, new DateTime(2017, 1, 2, 3, 4, 5), "Overview");
            var page1EpisodeDetail = new TvDbEpisodeData(1, "Test", 1L, 2, 3, 4, new DateTime(2017, 1, 2, 3, 4, 5), "Overview", 33.4f, 12);

            var page2Episode       = new TvDbEpisodeSummaryData(2, "Test2", 5L, 6, 7, 8, new DateTime(2017, 1, 2, 3, 4, 5), "Overview");
            var page2EpisodeDetail = new TvDbEpisodeData(2, "Test2", 5L, 6, 7, 8, new DateTime(2017, 1, 2, 3, 4, 5), "Overview", 33.4f, 12);

            _jsonConnection
            .GetAsync(Arg.Is <GetEpisodesRequest>(r => r.Url == "https://api.thetvdb.com/series/4/episodes?page=1"),
                      Arg.Any <Option <string> >())
            .Returns(new Response <GetEpisodesRequest.Response>(new GetEpisodesRequest.Response(
                                                                    new[] { page1Episode },
                                                                    new GetEpisodesRequest.PageLinks(1, 2, 2, Option <int> .None))));
            _jsonConnection.GetAsync(Arg.Is <GetEpisodeDetailsRequest>(r => r.Url.EndsWith("1")), Arg.Any <Option <string> >())
            .Returns(new Response <GetEpisodeDetailsRequest.Response>(
                         new GetEpisodeDetailsRequest.Response(page1EpisodeDetail)));

            _jsonConnection
            .GetAsync(Arg.Is <GetEpisodesRequest>(r => r.Url == "https://api.thetvdb.com/series/4/episodes?page=2"),
                      Arg.Any <Option <string> >())
            .Returns(new Response <GetEpisodesRequest.Response>(new GetEpisodesRequest.Response(
                                                                    new[] { page2Episode },
                                                                    new GetEpisodesRequest.PageLinks(2, 2, Option <int> .None, 1))));
            _jsonConnection.GetAsync(Arg.Is <GetEpisodeDetailsRequest>(r => r.Url.EndsWith("2")), Arg.Any <Option <string> >())
            .Returns(new Response <GetEpisodeDetailsRequest.Response>(
                         new GetEpisodeDetailsRequest.Response(page2EpisodeDetail)));

            var tvDbClient = new TvDbClient(_jsonConnection, _fileCache, _applicationPaths, _logManager,
                                            new JsonSerialiser(), new PluginConfiguration());

            await tvDbClient.GetEpisodesAsync(4);

            _jsonConnection.Received(1)
            .GetAsync(Arg.Is <GetEpisodesRequest>(r => r.Url == "https://api.thetvdb.com/series/4/episodes?page=1"),
                      Arg.Any <Option <string> >());
            _jsonConnection.Received(1)
            .GetAsync(Arg.Is <GetEpisodesRequest>(r => r.Url == "https://api.thetvdb.com/series/4/episodes?page=2"),
                      Arg.Any <Option <string> >());
            _jsonConnection.ReceivedWithAnyArgs(2)
            .GetAsync <GetEpisodeDetailsRequest.Response>(null, Option <string> .None);
        }
Esempio n. 5
0
        public async Task GetEpisodeAsync_NoLocalEpisodeData_ReturnsNewEpisodeData()
        {
            var episode       = new TvDbEpisodeSummaryData(1, "Test", 1L, 2, 3, 4, new DateTime(2017, 1, 2, 3, 4, 5), "Overview");
            var episodeDetail = new TvDbEpisodeData(1, "Test", 1L, 2, 3, 4, new DateTime(2017, 1, 2, 3, 4, 5), "Overview", 33.4f, 12);

            _jsonConnection.GetAsync(Arg.Any <GetEpisodesRequest>(), Arg.Any <Option <string> >())
            .Returns(new Response <GetEpisodesRequest.Response>(new GetEpisodesRequest.Response(new[] { episode },
                                                                                                new GetEpisodesRequest.PageLinks(1, 1, Option <int> .None, Option <int> .None))));
            _jsonConnection.GetAsync(Arg.Any <GetEpisodeDetailsRequest>(), Arg.Any <Option <string> >())
            .Returns(new Response <GetEpisodeDetailsRequest.Response>(
                         new GetEpisodeDetailsRequest.Response(episodeDetail)));

            var tvDbClient = new TvDbClient(_jsonConnection, _fileCache, _applicationPaths, _logManager,
                                            new JsonSerialiser(), new PluginConfiguration());

            var episodes = await tvDbClient.GetEpisodesAsync(4);

            episodes.IsSome.Should().BeTrue();
            episodes.ValueUnsafe().Should().BeEquivalentTo(episodeDetail);
        }
Esempio n. 6
0
        public async Task GetEpisodeAsync_NoLocalEpisodeData_SavesNewEpisodeData()
        {
            var episode       = new TvDbEpisodeSummaryData(1, "Test", 1L, 2, 3, 4, new DateTime(2017, 1, 2, 3, 4, 5), "Overview");
            var episodeDetail = new TvDbEpisodeData(1, "Test", 1L, 2, 3, 4, new DateTime(2017, 1, 2, 3, 4, 5), "Overview", 33.4f, 12);

            _jsonConnection.GetAsync(Arg.Any <GetEpisodesRequest>(), Arg.Any <Option <string> >())
            .Returns(new Response <GetEpisodesRequest.Response>(new GetEpisodesRequest.Response(new[] { episode },
                                                                                                new GetEpisodesRequest.PageLinks(1, 1, Option <int> .None, Option <int> .None))));
            _jsonConnection.GetAsync(Arg.Any <GetEpisodeDetailsRequest>(), Arg.Any <Option <string> >())
            .Returns(new Response <GetEpisodeDetailsRequest.Response>(
                         new GetEpisodeDetailsRequest.Response(episodeDetail)));

            var tvDbClient = new TvDbClient(_jsonConnection, _fileCache, _applicationPaths, _logManager,
                                            new JsonSerialiser(), new PluginConfiguration());

            await tvDbClient.GetEpisodesAsync(4);

            _fileCache.Received(1)
            .SaveFile(Arg.Any <TvDbSeriesEpisodesFileSpec>(),
                      Arg.Is <TvDbEpisodeCollection>(d => d.Episodes.Single() == episodeDetail));
        }
        public async Task GetEpisodesAsync_ValidSeriesId_ReturnsEpisodes()
        {
            var client = new TvDbClient(new JsonConnection(new TestHttpClient(), new JsonSerialiser(), _logManager),
                                        _fileCache, _applicationPaths, _logManager, new JsonSerialiser(), new PluginConfiguration
            {
                TvDbApiKey = Secrets.TvDbApiKey
            });

            var episodesResult = await client.GetEpisodesAsync(80675);

            episodesResult.IsSome.Should().BeTrue();
            var episodes = episodesResult.ValueUnsafe().ToList();

            episodes.Should().HaveCount(57);

            episodes[0]
            .Should().BeEquivalentTo(new TvDbEpisodeData(340368, "Celestial Being", 1L, 1, 1, 1496255818,
                                                         new DateTime(2007, 10, 6),
                                                         "Celestial Being, a private army dedicated to eradicating war, begins demonstrating the powers of their new \"MS-GUNDAM\" suits by interrupting the public demonstration of AEU's latest Mobile Suit, the AEU Enact and by protecting the Human Reform League's Space Elevator, \"Tenchu\" from being attacked by terrorists when their mobile suits had attempted to launch rockets on the \"Tenchu\", earning a news appearance from various TV news channels where Celestial Being's goals were publicly stated by Aeoria Schenberg.",
                                                         8.2f, 5));
        }
Esempio n. 8
0
        private async Task <IEnumerable <Episode> > SearchEpisodes(int seriesId, Dto.Series.EpisodeQuery query)
        {
            var records = (await _client.GetEpisodesAsync(seriesId, page: 1, query).ConfigureAwait(false)).Data;

            return(records.Select(Map));
        }