public void Initialize()
        {
            _fakeBuilder = new FakeClassBuilder<RateLimitHelper>();
            _tokenRateLimits = A.Fake<ITokenRateLimits>();

            _webHelper = new WebHelper(A.Fake<ITweetinviSettingsAccessor>());
            _attributeHelper = new AttributeHelper();
        }
예제 #2
0
        public void Initialize()
        {
            _fakeBuilder     = new FakeClassBuilder <RateLimitHelper>();
            _tokenRateLimits = A.Fake <ITokenRateLimits>();

            _webHelper       = new WebHelper(A.Fake <ITweetinviSettingsAccessor>());
            _attributeHelper = new AttributeHelper();
        }
        public void Itinialize()
        {
            _fakeBuilder = new FakeClassBuilder<RateLimitCache>();

            _credentials = A.Fake<ITwitterCredentials>();
            _credentials2 = A.Fake<ITwitterCredentials>();
            _tokenRateLimits = A.Fake<ITokenRateLimits>();
            _tokenRateLimits2 = A.Fake<ITokenRateLimits>();
        }
예제 #4
0
        public void Itinialize()
        {
            _fakeBuilder = new FakeClassBuilder <RateLimitCache>();

            _credentials      = A.Fake <ITwitterCredentials>();
            _credentials2     = A.Fake <ITwitterCredentials>();
            _tokenRateLimits  = A.Fake <ITokenRateLimits>();
            _tokenRateLimits2 = A.Fake <ITokenRateLimits>();
        }
예제 #5
0
 public void RefreshEntry(ITwitterCredentials credentials, ITokenRateLimits credentialsRateLimits)
 {
     lock (_lockTokenRateLimitsDictionary)
     {
         if (_tokenRateLimits.ContainsKey(credentials))
         {
             _tokenRateLimits[credentials] = credentialsRateLimits;
         }
         else
         {
             _tokenRateLimits.Add(credentials, credentialsRateLimits);
         }
     }
 }
예제 #6
0
 public void RefreshEntry(IOAuthCredentials credentials, ITokenRateLimits credentialsRateLimits)
 {
     lock (_lockTokenRateLimitsDictionary)
     {
         if (_tokenRateLimits.ContainsKey(credentials))
         {
             _tokenRateLimits[credentials] = credentialsRateLimits;
         }
         else
         {
             _tokenRateLimits.Add(credentials, credentialsRateLimits);
         }
     }
 }
예제 #7
0
        /// <summary>
        /// Get all the rate limits of all the Twitter endpoints
        /// </summary>
        public static ITokenRateLimits GetCurrentCredentialsRateLimits(bool useRateLimitCache = false)
        {
            ITokenRateLimits tokenRateLimits = null;

            if (!useRateLimitCache)
            {
                tokenRateLimits = HelpController.GetCurrentCredentialsRateLimits();
                _rateLimitCacheManager.UpdateTokenRateLimits(Auth.Credentials, tokenRateLimits);
            }
            else
            {
                tokenRateLimits = _rateLimitCacheManager.GetTokenRateLimits(Auth.Credentials);
            }

            return(tokenRateLimits);
        }
        private void InitializeData()
        {
            _credentials      = A.Fake <ITwitterCredentials>();
            _tokenRateLimits  = A.Fake <ITokenRateLimits>();
            _tokenRateLimit   = A.Fake <ITokenRateLimit>();
            _tokenRateLimits2 = A.Fake <ITokenRateLimits>();

            _refreshedTokenRateLimits = A.Fake <ITokenRateLimits>();
            _refreshedTokenRateLimit  = A.Fake <ITokenRateLimit>();

            _tokenRateLimit.CallsTo(x => x.Remaining).Returns(0);
            _tokenRateLimit.CallsTo(x => x.ResetDateTime).Returns(DateTime.Now.AddMinutes(1));

            _twitterQuery = A.Fake <ITwitterQuery>();
            _twitterQuery.CallsTo(x => x.QueryURL).Returns(TEST_QUERY);
            _twitterQuery.CallsTo(x => x.HttpMethod).Returns(HttpMethod.GET);
            _twitterQuery.CallsTo(x => x.QueryParameters).Returns(Enumerable.Empty <IOAuthQueryParameter>());
        }
        public ITokenRateLimit GetTokenRateLimitFromQuery(string query, ITokenRateLimits rateLimits)
        {
            var queryBaseURL = _webHelper.GetBaseURL(query);
            if (rateLimits == null || queryBaseURL == null)
            {
                return null;
            }

            var tokenAttributes = _attributeHelper.GetAllPropertiesAttributes<ITokenRateLimits, TwitterEndpointAttribute>();
            var matchingAttribute = tokenAttributes.Keys.JustOneOrDefault(x => IsEndpointURLMatchingQueryURL(queryBaseURL, x));

            if (matchingAttribute == null)
            {
                return null;
            }

            var matchingProperty = tokenAttributes[matchingAttribute];
            return GetRateLimitFromProperty(matchingProperty, rateLimits);
        }
예제 #10
0
        public IEnumerable<ITokenRateLimit> GetTokenRateLimitsFromMethod(Expression<Action> expression, ITokenRateLimits rateLimits)
        {
            if (expression == null)
            {
                return null;
            }

            var body = expression.Body;
             
            var methodCallExpression = body as MethodCallExpression;
            if (methodCallExpression != null)
            {
                var method = methodCallExpression.Method;
                var attributes = _attributeHelper.GetAttributes<CustomTwitterEndpointAttribute>(method);
                var tokenAttributes = _attributeHelper.GetAllPropertiesAttributes<ITokenRateLimits, TwitterEndpointAttribute>();
                var validKeys = tokenAttributes.Keys.Where(x => attributes.Any(a => a.EndpointURL == x.EndpointURL));
                return validKeys.Select(key => GetRateLimitFromProperty(tokenAttributes[key], rateLimits));
            }
            
            return null;
        }
예제 #11
0
        public ITokenRateLimit GetTokenRateLimitFromQuery(string query, ITokenRateLimits rateLimits)
        {
            var queryBaseURL = _webHelper.GetBaseURL(query);

            if (rateLimits == null || queryBaseURL == null)
            {
                return(null);
            }

            var tokenAttributes   = _attributeHelper.GetAllPropertiesAttributes <ITokenRateLimits, TwitterEndpointAttribute>();
            var matchingAttribute = tokenAttributes.Keys.JustOneOrDefault(x => IsEndpointURLMatchingQueryURL(queryBaseURL, x));

            if (matchingAttribute == null)
            {
                return(null);
            }

            var matchingProperty = tokenAttributes[matchingAttribute];

            return(GetRateLimitFromProperty(matchingProperty, rateLimits));
        }
 public void UpdateTokenRateLimits(ITwitterCredentials credentials, ITokenRateLimits tokenRateLimits)
 {
     _rateLimitCache.RefreshEntry(credentials, tokenRateLimits);
 }
예제 #13
0
 private ITokenRateLimit GetRateLimitFromProperty(PropertyInfo propertyInfo, ITokenRateLimits rateLimits)
 {
     var rateLimit = propertyInfo.GetValue(rateLimits, null) as ITokenRateLimit;
     return rateLimit;
 }
예제 #14
0
 public bool IsQueryAssociatedWithTokenRateLimit(string query, ITokenRateLimits rateLimits)
 {
     return GetTokenRateLimitFromQuery(query, rateLimits) != null;
 }
예제 #15
0
 public bool IsQueryAssociatedWithTokenRateLimit(string query, ITokenRateLimits rateLimits)
 {
     return(GetTokenRateLimitFromQuery(query, rateLimits) != null);
 }
예제 #16
0
        public IEnumerable <ITokenRateLimit> GetTokenRateLimitsFromMethod(Expression <Action> expression, ITokenRateLimits rateLimits)
        {
            if (expression == null)
            {
                return(null);
            }

            var body = expression.Body;

            var methodCallExpression = body as MethodCallExpression;

            if (methodCallExpression != null)
            {
                var method          = methodCallExpression.Method;
                var attributes      = _attributeHelper.GetAttributes <CustomTwitterEndpointAttribute>(method);
                var tokenAttributes = _attributeHelper.GetAllPropertiesAttributes <ITokenRateLimits, TwitterEndpointAttribute>();
                var validKeys       = tokenAttributes.Keys.Where(x => attributes.Any(a => a.EndpointURL == x.EndpointURL));
                return(validKeys.Select(key => GetRateLimitFromProperty(tokenAttributes[key], rateLimits)));
            }

            return(null);
        }
 private void ArrangeQueryExecutorGetTokenRateLimits(ITokenRateLimits result)
 {
     _fakeHelpQueryExecutor
         .CallsTo(x => x.GetCurrentCredentialsRateLimits())
         .Returns(result);
 }
        private void InitializeData()
        {
            _credentials = A.Fake<ITwitterCredentials>();
            _credentials.AccessToken = TestHelper.GenerateString();
            _credentials.AccessTokenSecret = TestHelper.GenerateString();

            _tokenRateLimits = A.Fake<ITokenRateLimits>();
            _tokenRateLimit = A.Fake<ITokenRateLimit>();
            _tokenRateLimits2 = A.Fake<ITokenRateLimits>();

            _refreshedTokenRateLimits = A.Fake<ITokenRateLimits>();
            _refreshedTokenRateLimit = A.Fake<ITokenRateLimit>();

            _tokenRateLimit.CallsTo(x => x.Remaining).Returns(0);
            _tokenRateLimit.CallsTo(x => x.ResetDateTime).Returns(DateTime.Now.AddMinutes(1));

            _twitterQuery = A.Fake<ITwitterQuery>();
            _twitterQuery.CallsTo(x => x.QueryURL).Returns(TEST_QUERY);
            _twitterQuery.CallsTo(x => x.HttpMethod).Returns(HttpMethod.GET);
            _twitterQuery.CallsTo(x => x.QueryParameters).Returns(Enumerable.Empty<IOAuthQueryParameter>());
        }
예제 #19
0
 public void UpdateTokenRateLimits(ITwitterCredentials credentials, ITokenRateLimits tokenRateLimits)
 {
     _rateLimitCache.RefreshEntry(credentials, tokenRateLimits);
 }
예제 #20
0
 private void ArrangeQueryExecutorGetTokenRateLimits(ITokenRateLimits result)
 {
     _fakeHelpQueryExecutor
     .CallsTo(x => x.GetCurrentCredentialsRateLimits())
     .Returns(result);
 }
예제 #21
0
        private ITokenRateLimit GetRateLimitFromProperty(PropertyInfo propertyInfo, ITokenRateLimits rateLimits)
        {
            var rateLimit = propertyInfo.GetValue(rateLimits, null) as ITokenRateLimit;

            return(rateLimit);
        }