Exemple #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));
            }
Exemple #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));
            }
Exemple #3
0
            public void SetterAndGetterInSync()
            {
                var target = new MinimumRequestTimeDistanceAttribute {
                    Message = "ccccccbughknjbvlcldddtvfbkbivrbegdtuccridudr"
                };

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

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

                Assert.AreEqual(42, target.Seconds);
            }
Exemple #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);
            }
Exemple #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);
            }
Exemple #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);
            }
Exemple #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));
            }
Exemple #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);
            }
Exemple #11
0
            public void ImplementsActionFilterAttribute()
            {
                var target = new MinimumRequestTimeDistanceAttribute();

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

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