Exemplo n.º 1
0
            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);
            }
Exemplo n.º 2
0
            [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);
            }
Exemplo n.º 3
0
            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));
            }
Exemplo n.º 4
0
            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);
            }
Exemplo n.º 5
0
            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);
            }