Esempio n. 1
0
 public Task <Option <TvDbSeriesData> > FindSeriesAsync(string seriesName)
 {
     return(_token.GetTokenAsync()
            .Bind(t => _jsonConnection.GetAsync(new FindSeriesRequest(seriesName), t)
                  .Bind(response =>
     {
         return response.Match(
             r => r.Data.MatchingSeries.Aggregate(Task.FromResult(Option <TvDbSeriesData> .None),
                                                  (existing, current) => existing.Bind(e => e.Match(s =>
         {
             _log.Debug(
                 $"More than one matching series found for series name '{seriesName}'");
             return Task.FromResult(Option <TvDbSeriesData> .None);
         },
                                                                                                    () => GetSeriesAsync(current.Id)))),
             fr => Task.FromResult(Option <TvDbSeriesData> .None));
     })));
 }
Esempio n. 2
0
        public async Task GetEpisodeAsync_NoLocalEpisodeData_RequestsEpisodeData()
        {
            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);

            _jsonConnection.ReceivedWithAnyArgs(1)
            .GetAsync <GetEpisodesRequest.Response>(null, Option <string> .None);
            _jsonConnection.ReceivedWithAnyArgs(1)
            .GetAsync <GetEpisodeDetailsRequest.Response>(null, Option <string> .None);
        }