public async Task IpAddress_TooManyRequestForAddress_ReturnsTrue() { const string ipAddress = "1.2.3.4"; _mockRepository .Setup(repo => repo.FindFailedAttemptsForIpAddressAsync(ipAddress, It.IsAny <DateTimeOffset>())) .ReturnsAsync(Enumerable.Range(0, 8).Select(failedAttempts => new FailedAttempt(ipAddress, DateTimeOffset.Now)).ToList()); var result = await _service.HasTooManyRequestsForIpAddressAsync(ipAddress); result.Should().BeTrue(); }
public async Task <IActionResult> Login(string returnUrl) { ViewData["TooManyRequests"] = false; ViewData["ReturnUrl"] = returnUrl; var ipAddress = HttpContext.Connection.RemoteIpAddress; if (ipAddress == null) { throw new IpAddressNotFoundException(); } var tooManyRequestsForIpAddress = await _failedLoginAttemptsService.HasTooManyRequestsForIpAddressAsync(ipAddress.ToString()); ViewData["TooManyRequests"] = tooManyRequestsForIpAddress; return(View()); }