Esempio n. 1
0
        public TvMazeClient(HttpClient httpClient, IRateLimitingStrategy rateLimitingStrategy)
        {
            if (rateLimitingStrategy == null)
            {
                rateLimitingStrategy = new ThrowExceptionRateLimitingStrategy();
            }

            var flurlClient = new FlurlClient(httpClient);

            // Caller didn't provide the base address.
            if (flurlClient.BaseUrl == null)
            {
                flurlClient.BaseUrl = BaseApiUrl;
            }

            flurlClient.AllowAnyHttpStatus();

            var tvMazeHttpClient = new TvMazeHttpClient(flurlClient, rateLimitingStrategy);

            Search   = new SearchEndpoint(tvMazeHttpClient);
            Shows    = new ShowsEndpoint(tvMazeHttpClient);
            Episodes = new EpisodesEndpoint(tvMazeHttpClient);
            Updates  = new UpdatesEndpoint(tvMazeHttpClient);
            Lookup   = new LookupEndpoint(tvMazeHttpClient);
        }
Esempio n. 2
0
        public async void ThrowExceptionRateLimitingStrategy()
        {
            // arrange
            var strategy     = new ThrowExceptionRateLimitingStrategy();
            var tvMazeClient = new TvMazeClient(new HttpClient(), strategy);
            var beforeCount  = _httpTest.CallLog.Count;

            // act
            Func <Task> action = async() =>
            {
                await tvMazeClient.Shows.GetShowMainInformationAsync(1);
            };

            // assert
            await action.Should().ThrowAsync <UnexpectedResponseStatusException>();

            _httpTest.CallLog.Count.Should().Be(beforeCount + 1);
        }