Beispiel #1
0
        public async Task GetToken_MultipleSimultaneousCalls_MakesOneRequest()
        {
            _jsonConnection.PostAsync <GetTokenRequest.TokenData>(null, null)
            .ReturnsForAnyArgs(x => Task.Delay(1000)
                               .ContinueWith(t => Right <FailedRequest, Response <GetTokenRequest.TokenData> >(
                                                 new Response <GetTokenRequest.TokenData>(
                                                     new GetTokenRequest.TokenData("AccessToken", 3, "RefreshToken")))));

            await Task.WhenAll(
                _token.GetToken(_jsonConnection, _aniListConfiguration, _resultContext),
                _token.GetToken(_jsonConnection, _aniListConfiguration, _resultContext),
                _token.GetToken(_jsonConnection, _aniListConfiguration, _resultContext),
                _token.GetToken(_jsonConnection, _aniListConfiguration, _resultContext),
                _token.GetToken(_jsonConnection, _aniListConfiguration, _resultContext),
                _token.GetToken(_jsonConnection, _aniListConfiguration, _resultContext));

            _jsonConnection.Received(1)
            .PostAsync(Arg.Any <GetTokenRequest>(), Arg.Is(Option <string> .None));
        }
Beispiel #2
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);
        }