public IEndpointRateLimit GetOrCreateQueryRateLimit(string query, ITwitterCredentials credentials) { var rateLimits = _rateLimitCache.GetCredentialsRateLimits(credentials); var queryRateLimit = _rateLimitHelper.GetEndpointRateLimitFromQuery(query, rateLimits, true); if (rateLimits == null || DoesQueryNeedsToRefreshTheCacheInformation(queryRateLimit)) { rateLimits = RefreshCredentialsRateLimits(credentials); queryRateLimit = _rateLimitHelper.GetEndpointRateLimitFromQuery(query, rateLimits, true); } return(queryRateLimit); }
public virtual async Task <IEndpointRateLimit> GetQueryRateLimitAsync(IGetEndpointRateLimitsParameters parameters, IReadOnlyTwitterCredentials credentials) { var credentialsRateLimits = await RateLimitsClient.GetRateLimitsAsync(parameters).ConfigureAwait(false); var endpointRateLimit = _rateLimitHelper.GetEndpointRateLimitFromQuery(parameters.Url, credentialsRateLimits, false); if (parameters.From == RateLimitsSource.CacheOrTwitterApi && ShouldEndpointCacheBeUpdated(endpointRateLimit)) { var updatedCredentialsRateLimits = await RefreshCredentialsRateLimitsAsync(credentials).ConfigureAwait(false); endpointRateLimit = _rateLimitHelper.GetEndpointRateLimitFromQuery(parameters.Url, updatedCredentialsRateLimits, false); } return(endpointRateLimit); }
private void GetTokenRateLimitFromQuery_EndpointAssociatedCorrectly(Expression <Func <ICredentialsRateLimits, IEndpointRateLimit> > rateLimit, string associatedURL, IRateLimitHelper rateLimitHelper) { // Arrange var fakeTokenRateLimit = A.Fake <IEndpointRateLimit>(); _credentialsRateLimits.CallsTo(rateLimit).Returns(fakeTokenRateLimit); // Act var tokenRateLimit = rateLimitHelper.GetEndpointRateLimitFromQuery(associatedURL, _credentialsRateLimits, true); // Assert Assert.AreEqual(tokenRateLimit, fakeTokenRateLimit); }
private void GetTokenRateLimitFromQuery_EndpointAssociatedCorrectly(Expression<Func<ICredentialsRateLimits, IEndpointRateLimit>> rateLimit, string associatedURL, IRateLimitHelper rateLimitHelper) { // Arrange var fakeTokenRateLimit = A.Fake<IEndpointRateLimit>(); _credentialsRateLimits.CallsTo(rateLimit).Returns(fakeTokenRateLimit); // Act var tokenRateLimit = rateLimitHelper.GetEndpointRateLimitFromQuery(associatedURL, _credentialsRateLimits); // Assert Assert.AreEqual(tokenRateLimit, fakeTokenRateLimit); }