public void GetQueryRateLimit_QueryReturnedOutOfDateTokenRateLimit_RefreshNotPerformed()
        {
            // Arrange
            var cacheManager = CreateRateLimitCacheManager();

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

            // Act
            cacheManager.GetQueryRateLimit(TEST_QUERY, _credentials);

            // Assert
            _fakeRateLimitCache.CallsTo(x => x.RefreshEntry(It.IsAny <ITwitterCredentials>(), It.IsAny <ITokenRateLimits>())).MustNotHaveHappened();
        }
        public void WaitForRateLimit_QueriesCanBePerformedRightAway_DoNotWait()
        {
            // Arrange
            var rateLimitAwaiter = CreateRateLimitAwaiter();

            _tokenRateLimit.CallsTo(x => x.Remaining).Returns(15);

            // Act
            rateLimitAwaiter.WaitForCredentialsRateLimit(TEST_QUERY, _credentials);

            // Assert
            _fakeThreadHelper.CallsTo(x => x.Sleep(It.IsAny <int>())).MustNotHaveHappened();
        }
        public void QueryExecutedWithCredentials_QueryFoundAndRemainingIs2_NumberOfRequestIs3_Substract2()
        {
            // Arrange
            var cacheUpdater = CreateRateLimitUpdater();

            _tokenRateLimit.CallsTo(x => x.Remaining).Returns(2);

            // Act
            cacheUpdater.QueryExecuted(TEST_QUERY, _credentials, 3);

            // Assert
            Assert.AreEqual(_tokenRateLimit.Remaining, 0);
        }
        public void TestInitialize()
        {
            _fakeBuilder = new FakeClassBuilder<RateLimitAwaiter>();
            _fakeRateLimitCacheManager = _fakeBuilder.GetFake<IRateLimitCacheManager>();
            _fakeCredentialsAccessor = _fakeBuilder.GetFake<ICredentialsAccessor>();
            _fakeThreadHelper = _fakeBuilder.GetFake<IThreadHelper>();

            _credentials = A.Fake<IOAuthCredentials>();
            _tokenRateLimit = A.Fake<ITokenRateLimit>();
            _tokenRateLimit.CallsTo(x => x.Remaining).Returns(0);
            _tokenRateLimit.CallsTo(x => x.ResetDateTimeInMilliseconds).Returns(TIME_TO_WAIT);

            _fakeRateLimitCacheManager.CallsTo(x => x.GetQueryRateLimit(TEST_QUERY, _credentials)).Returns(_tokenRateLimit);
            _fakeCredentialsAccessor.CallsTo(x => x.CurrentThreadCredentials).Returns(_credentials);
        }
        public void TestInitialize()
        {
            _fakeBuilder = new FakeClassBuilder <RateLimitAwaiter>();
            _fakeRateLimitCacheManager = _fakeBuilder.GetFake <IRateLimitCacheManager>();
            _fakeCredentialsAccessor   = _fakeBuilder.GetFake <ICredentialsAccessor>();
            _fakeThreadHelper          = _fakeBuilder.GetFake <IThreadHelper>();

            _credentials    = A.Fake <ITwitterCredentials>();
            _tokenRateLimit = A.Fake <ITokenRateLimit>();
            _tokenRateLimit.CallsTo(x => x.Remaining).Returns(0);
            _tokenRateLimit.CallsTo(x => x.ResetDateTimeInMilliseconds).Returns(TIME_TO_WAIT);

            _fakeRateLimitCacheManager.CallsTo(x => x.GetQueryRateLimit(TEST_QUERY, _credentials)).Returns(_tokenRateLimit);
            _fakeCredentialsAccessor.CallsTo(x => x.CurrentThreadCredentials).Returns(_credentials);
        }
        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>());
        }
 private void InitializeData()
 {
     _credentials = A.Fake<ITwitterCredentials>();
     _tokenRateLimit = A.Fake<ITokenRateLimit>();
     _tokenRateLimit.CallsTo(x => x.Remaining).Returns(5);
 }
 private void InitializeData()
 {
     _credentials    = A.Fake <IOAuthCredentials>();
     _tokenRateLimit = A.Fake <ITokenRateLimit>();
     _tokenRateLimit.CallsTo(x => x.Remaining).Returns(5);
 }
        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>());
        }