public void NotBlocksConfiguredFastCallsWithoutClientId() { // we setup a request context that returns always the same session id var context = MvcTestBase.CreateRequestContext(new Uri("http://localhost"), string.Empty, string.Empty); // we want to allow max 1 requests in one second var target = new MinimumRequestTimeDistanceAttribute(); // calling 2 times should not throw an exception target.OnActionExecuting(context); target.OnActionExecuting(context); Assert.IsNotNull(target); }
[ExcludeFromCodeCoverage] // since we expect an exception, we cannot get 100% code coverage public void BlocksConfiguredFastCalls() { // we setup a request context that returns always the same session id var context = MvcTestBase.CreateRequestContext(); // we want to allow max 1 requests in one second var target = new MinimumRequestTimeDistanceAttribute(); // calling 2 times should block execution target.OnActionExecuting(context); target.OnActionExecuting(context); var contentResult = context.Result as ContentResult; Assert.IsNotNull(contentResult); Assert.AreEqual("client has been blocked...", contentResult.Content); }
public void RedirectsConfiguredFastCalls() { // we setup a request context that returns always the same session id var context = MvcTestBase.CreateRequestContext(); // we want to allow max 1 requests in one second var target = new MinimumRequestTimeDistanceAttribute { FaultAction = "Fault" }; // calling 3 times should throw an exception target.OnActionExecuting(context); Assert.IsNotInstanceOfType(context.Result, typeof(RedirectResult)); target.OnActionExecuting(context); target.OnActionExecuting(context); Assert.IsInstanceOfType(context.Result, typeof(RedirectResult)); }
public async Task NotBlocksMultipleLessThanConfiguredFastCalls() { // we setup a request context that returns always the same session id var context = MvcTestBase.CreateRequestContext(); // we want to allow max 1 requests in one second var target = new MinimumRequestTimeDistanceAttribute(); // calling 1 times should NOT throw an exception target.OnActionExecuting(context); var contentResult1 = context.Result as ContentResult; Assert.IsNull(contentResult1); await Task.Delay(1001); // calling 2 times should NOT throw an exception target.OnActionExecuting(context); var contentResult2 = context.Result as ContentResult; Assert.IsNull(contentResult2); }
public void NotBlocksLessThanConfiguredFastCalls() { var context = MvcTestBase.CreateRequestContext(); // we want to allow max 1 requests in one second var target = new MinimumRequestTimeDistanceAttribute(); // calling 1 times should NOT throw an exception target.OnActionExecuting(context); var contentResult = context.Result as ContentResult; Assert.IsNull(contentResult); }