mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 09:15:27 +08:00 
			
		
		
		
	refactor code
This commit is contained in:
		@@ -20,6 +20,7 @@ using Xunit;
 | 
			
		||||
using TestStack.BDDfy;
 | 
			
		||||
using Ocelot.Configuration.Builder;
 | 
			
		||||
using Shouldly;
 | 
			
		||||
using Ocelot.Configuration;
 | 
			
		||||
 | 
			
		||||
namespace Ocelot.UnitTests.RateLimit
 | 
			
		||||
{
 | 
			
		||||
@@ -70,11 +71,13 @@ namespace Ocelot.UnitTests.RateLimit
 | 
			
		||||
        {
 | 
			
		||||
            var downstreamRoute = new DownstreamRoute(new List<Ocelot.DownstreamRouteFinder.UrlMatcher.UrlPathPlaceholderNameAndValue>(),
 | 
			
		||||
                 new ReRouteBuilder().WithEnableRateLimiting(true).WithRateLimitOptions(
 | 
			
		||||
                     new Ocelot.Configuration.RateLimitOptions(true, "ClientId", new List<string>(), false, "", "", new Ocelot.Configuration.RateLimitRule() { Limit = 3, Period = "1s", PeriodTimespan = TimeSpan.FromSeconds(100) },429))
 | 
			
		||||
                     new Ocelot.Configuration.RateLimitOptions(true, "ClientId", new List<string>(), false, "", "", new Ocelot.Configuration.RateLimitRule("1s", TimeSpan.FromSeconds(100), 3), 429))
 | 
			
		||||
                     .Build());
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenTheDownStreamRouteIs(downstreamRoute))
 | 
			
		||||
                .When(x => x.WhenICallTheMiddleware())
 | 
			
		||||
                .When(x => x.WhenICallTheMiddlewareMultipleTime(2))
 | 
			
		||||
                .Then(x => x.ThenresponseStatusCodeIs200())
 | 
			
		||||
                .When(x => x.WhenICallTheMiddlewareMultipleTime(2))
 | 
			
		||||
                .Then(x => x.ThenresponseStatusCodeIs429())
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
@@ -84,7 +87,7 @@ namespace Ocelot.UnitTests.RateLimit
 | 
			
		||||
        {
 | 
			
		||||
            var downstreamRoute = new DownstreamRoute(new List<Ocelot.DownstreamRouteFinder.UrlMatcher.UrlPathPlaceholderNameAndValue>(),
 | 
			
		||||
                 new ReRouteBuilder().WithEnableRateLimiting(true).WithRateLimitOptions(
 | 
			
		||||
                     new Ocelot.Configuration.RateLimitOptions(true, "ClientId", new List<string>() { "ocelotclient2" }, false, "", "", new Ocelot.Configuration.RateLimitRule() { Limit = 3, Period = "1s", PeriodTimespan = TimeSpan.FromSeconds(100) },429))
 | 
			
		||||
                     new Ocelot.Configuration.RateLimitOptions(true, "ClientId", new List<string>() { "ocelotclient2" }, false, "", "", new  RateLimitRule( "1s", TimeSpan.FromSeconds(100),3),429))
 | 
			
		||||
                     .Build());
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenTheDownStreamRouteIs(downstreamRoute))
 | 
			
		||||
@@ -102,11 +105,11 @@ namespace Ocelot.UnitTests.RateLimit
 | 
			
		||||
                .Returns(_downstreamRoute);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void WhenICallTheMiddleware()
 | 
			
		||||
        private void WhenICallTheMiddlewareMultipleTime(int times)
 | 
			
		||||
        {
 | 
			
		||||
            var clientId = "ocelotclient1";
 | 
			
		||||
            // Act    
 | 
			
		||||
            for (int i = 0; i <10; i++)
 | 
			
		||||
            for (int i = 0; i < times; i++)
 | 
			
		||||
            {
 | 
			
		||||
                var request = new HttpRequestMessage(new HttpMethod("GET"), _url);
 | 
			
		||||
                request.Headers.Add("ClientId", clientId);
 | 
			
		||||
 
 | 
			
		||||
@@ -14,7 +14,6 @@
 | 
			
		||||
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.0",
 | 
			
		||||
    "Microsoft.AspNetCore.Http": "1.1.0",
 | 
			
		||||
    "Ocelot": "0.0.0-dev",
 | 
			
		||||
    "xunit": "2.2.0-beta2-build3300",
 | 
			
		||||
    "dotnet-test-xunit": "2.2.0-preview2-build1029",
 | 
			
		||||
    "Moq": "4.6.38-alpha",
 | 
			
		||||
    "Microsoft.AspNetCore.TestHost": "1.1.0",
 | 
			
		||||
@@ -24,7 +23,8 @@
 | 
			
		||||
    "Shouldly": "2.8.2",
 | 
			
		||||
    "TestStack.BDDfy": "4.3.2",
 | 
			
		||||
    "Microsoft.AspNetCore.Authentication.OAuth": "1.1.0",
 | 
			
		||||
    "Microsoft.DotNet.InternalAbstractions": "1.0.0"
 | 
			
		||||
    "Microsoft.DotNet.InternalAbstractions": "1.0.0",
 | 
			
		||||
    "xunit": "2.2.0-rc1-build3507"
 | 
			
		||||
  },
 | 
			
		||||
  "runtimes": {
 | 
			
		||||
    "win10-x64": {},
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user