public ImgurService(IOptions <BotConfiguration> config) { _config = config.Value; _ImgurClient = new ImgurClient(_config.ImgurClientId, _config.ImgurApiKey); ImageEndpoint = new ImageEndpoint(_ImgurClient); RateLimitEndpoint = new RateLimitEndpoint(_ImgurClient); VidToGIFEndpoint = new VidToGIFEndpoint(new VidToGIFClient(_config.ImgurClientId, _config.ImgurApiKey)); }
public async Task RateLimit_GetRateLimitWithMashapeClient_IsValidRateLimit() { var authentication = new MashapeClient(ClientId, ClientSecret, MashapeKey); var endpoint = new RateLimitEndpoint(authentication); var limit = await endpoint.GetRateLimitAsync(); Assert.IsNotNull(limit); Assert.IsTrue(limit.ClientLimit > 0); Assert.IsTrue(limit.ClientRemaining > 0); Assert.IsTrue(limit.UserLimit > 0); Assert.IsTrue(limit.UserRemaining > 0); Assert.IsNotNull(limit.UserReset); Assert.IsNull(limit.MashapeUploadsLimit); Assert.IsNull(limit.MashapeUploadsRemaining); }
public async Task GetRateLimitAsync_Equal() { var mockUrl = "https://api.imgur.com/3/credits"; var mockResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(MockRateLimitEndpointResponses.GetRateLimit) }; var httpClient = new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)); var client = new ImgurClient("123", "1234"); var endpoint = new RateLimitEndpoint(client, httpClient); var rateLimit = await endpoint.GetRateLimitAsync().ConfigureAwait(false); Assert.NotNull(rateLimit); Assert.Equal(10500, rateLimit.ClientLimit); Assert.Equal(9500, rateLimit.ClientRemaining); }
public async Task GetRateLimitAsync_AreEqual() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(RateLimitEndpointResponses.RateLimitResponse) }; fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/3/credits"), fakeResponse); var httpClient = new HttpClient(fakeHttpMessageHandler); var client = new ImgurClient("123", "1234"); var endpoint = new RateLimitEndpoint(client, httpClient); var rateLimit = await endpoint.GetRateLimitAsync(); Assert.IsNotNull(rateLimit); Assert.AreEqual(412, rateLimit.UserLimit); Assert.AreEqual(382, rateLimit.UserRemaining); Assert.AreEqual(10500, rateLimit.ClientLimit); Assert.AreEqual(9500, rateLimit.ClientRemaining); }