Exemplo n.º 1
0
            public void InitializesExplicitExtractors()
            {
                var target = new MinimumRequestTimeDistanceAttribute(new[] { typeof(EmptyExtractor) });

                Assert.AreEqual(1, target.ContextProcessors.Count());
                Assert.IsTrue(target.ContextProcessors.Any(x => x.IdExtractor is EmptyExtractor));
            }
Exemplo n.º 2
0
            public void InitializesDefaultExtractors()
            {
                var target = new MinimumRequestTimeDistanceAttribute();

                Assert.IsTrue(target.ContextProcessors.Any(x => x.IdExtractor is SessionIdExtractor));
                Assert.IsTrue(target.ContextProcessors.Any(x => x.IdExtractor is UserHostExtractor));
            }
Exemplo n.º 3
0
            public void SetterAndGetterInSync()
            {
                var target = new MinimumRequestTimeDistanceAttribute {
                    Message = "ccccccbughknjbvlcldddtvfbkbivrbegdtuccridudr"
                };

                Assert.AreEqual("ccccccbughknjbvlcldddtvfbkbivrbegdtuccridudr", target.Message);
            }
Exemplo n.º 4
0
            public void SetterAndGetterInSync()
            {
                var target = new MinimumRequestTimeDistanceAttribute {
                    Name = "ccccccbughkndndufnhfjfthfnhhucdjleuktvcrgtnl"
                };

                Assert.AreEqual("ccccccbughkndndufnhfjfthfnhhucdjleuktvcrgtnl", target.Name);
            }
Exemplo n.º 5
0
            public void SetterAndGetterInSync()
            {
                var target = new MinimumRequestTimeDistanceAttribute {
                    Seconds = 42
                };

                Assert.AreEqual(42, target.Seconds);
            }
Exemplo n.º 6
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);
            }
Exemplo n.º 7
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.º 8
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.º 9
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.º 10
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.º 11
0
            public void ImplementsActionFilterAttribute()
            {
                var target = new MinimumRequestTimeDistanceAttribute();

                Assert.IsInstanceOfType(target, typeof(ActionFilterAttribute));
            }
Exemplo n.º 12
0
            public void DefaultIsOneSeconds()
            {
                var target = new MinimumRequestTimeDistanceAttribute();

                Assert.AreEqual(1, target.Seconds);
            }