public async Task EnforceRateLimitAsync_WhenCalledWithResetTimeEqualToNull_AssertHandleAsyncWasNotCalledOnExceptionHandler() { int used = _random.Next(30, 60); int remaining = _random.Next(30, 60); DateTime?resetTime = null; DateTime receivedTime = DateTime.Now; IRedditRateLimitLogic sut = CreateSut(); await sut.EnforceRateLimitAsync(used, remaining, resetTime, receivedTime); _exceptionHandlerMock.Verify(m => m.HandleAsync(It.IsAny <AggregateException>()), Times.Never); _exceptionHandlerMock.Verify(m => m.HandleAsync(It.IsAny <Exception>()), Times.Never); }
public async Task EnforceRateLimitAsync_WhenCalledWithResetTimeEqualToNullAndRemainingEqualToExistingRemaining_ExpectRemainingUntouched() { int existingRemaining = _random.Next(30, 60); int remaining = existingRemaining; int used = _random.Next(30, 60); DateTime?resetTime = null; DateTime receivedTime = DateTime.Now; IRedditRateLimitLogic sut = CreateSut(remaining: existingRemaining); await sut.EnforceRateLimitAsync(used, remaining, resetTime, receivedTime); Assert.AreEqual(existingRemaining, sut.Remaining); }
public async Task EnforceRateLimitAsync_WhenCalledWithResetTimeEqualToNullAndUsedGreaterThanAlreadyUsed_ExpectUsedEqualToInputValue() { int alreadyUsed = _random.Next(30, 60); int used = alreadyUsed + _random.Next(1, 10); int remaining = _random.Next(30, 60); DateTime?resetTime = null; DateTime receivedTime = DateTime.Now; IRedditRateLimitLogic sut = CreateSut(used: alreadyUsed); await sut.EnforceRateLimitAsync(used, remaining, resetTime, receivedTime); Assert.AreEqual(used, sut.Used); }
public async Task EnforceRateLimitAsync_WhenCalledWithResetTimeLaterThanExistingResetTime_ExpectResetTimeEqualToInputValue() { DateTime existingResetTime = DateTime.Now.AddSeconds(_random.Next(30, 60)); DateTime?resetTime = existingResetTime.AddSeconds(_random.Next(1, 30)); int used = _random.Next(30, 60); int remaining = _random.Next(30, 60); DateTime receivedTime = DateTime.Now; IRedditRateLimitLogic sut = CreateSut(resetTime: existingResetTime); await sut.EnforceRateLimitAsync(used, remaining, resetTime, receivedTime); Assert.AreEqual(resetTime, sut.ResetTime); }
public async Task EnforceRateLimitAsync_WhenCalledWithResetTimeLaterThanExistingResetTime_AssertHandleAsyncWasNotCalledOnExceptionHandler() { DateTime existingResetTime = DateTime.Now.AddSeconds(_random.Next(30, 60)); DateTime?resetTime = existingResetTime.AddSeconds(_random.Next(1, 30)); int used = _random.Next(30, 60); int remaining = _random.Next(30, 60); DateTime receivedTime = DateTime.Now; IRedditRateLimitLogic sut = CreateSut(resetTime: existingResetTime); await sut.EnforceRateLimitAsync(used, remaining, resetTime, receivedTime); _exceptionHandlerMock.Verify(m => m.HandleAsync(It.IsAny <AggregateException>()), Times.Never); _exceptionHandlerMock.Verify(m => m.HandleAsync(It.IsAny <Exception>()), Times.Never); }
public async Task EnforceRateLimitAsync_WhenCalledWithResetTimeEqualToExistingResetTimeAndUsedEqualToAlreadyUsed_ExpectUsedUntouched() { int alreadyUsed = _random.Next(30, 60); int used = alreadyUsed; DateTime existingResetTime = DateTime.Now.AddSeconds(_random.Next(30, 60)); DateTime?resetTime = existingResetTime; int remaining = _random.Next(30, 60); DateTime receivedTime = DateTime.Now; IRedditRateLimitLogic sut = CreateSut(used: alreadyUsed, resetTime: existingResetTime); await sut.EnforceRateLimitAsync(used, remaining, resetTime, receivedTime); Assert.AreEqual(alreadyUsed, sut.Used); }
public async Task EnforceRateLimitAsync_WhenCalledWithResetTimeBeforeThanExistingResetTimeAndRemainingGreaterThanExistingRemaining_ExpectRemainingUntouched() { int existingRemaining = _random.Next(30, 60); int remaining = existingRemaining + _random.Next(1, 10); DateTime existingResetTime = DateTime.Now.AddSeconds(_random.Next(30, 60)); DateTime?resetTime = existingResetTime.AddSeconds(_random.Next(1, 25) * -1); int used = _random.Next(30, 60); DateTime receivedTime = DateTime.Now; IRedditRateLimitLogic sut = CreateSut(remaining: existingRemaining, resetTime: existingResetTime); await sut.EnforceRateLimitAsync(used, remaining, resetTime, receivedTime); Assert.AreEqual(existingRemaining, sut.Remaining); }
public async Task EnforceRateLimitAsync_WhenCalledWithReceivedTimeLowerThanLatestReceivedTime_ExpectUsedUntouched() { int alreadyUsed = _random.Next(30, 60); int used = alreadyUsed + _random.Next(1, 10); DateTime existingResetTime = DateTime.Now.AddSeconds(_random.Next(10, 60)); DateTime?resetTime = existingResetTime.AddSeconds(_random.Next(10, 60)); int remaining = _random.Next(30, 60); DateTime receivedTime = DateTime.Now; DateTime latestReceivedTime = receivedTime.AddSeconds(_random.Next(10, 30)); IRedditRateLimitLogic sut = CreateSut(used: alreadyUsed, resetTime: existingResetTime, latestReceivedTime: latestReceivedTime); await sut.EnforceRateLimitAsync(used, remaining, resetTime, receivedTime); Assert.AreEqual(alreadyUsed, sut.Used); }