mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 20:30:50 +08:00 
			
		
		
		
	Removed unused usings, removed empty spaces, removed tons os warnings (#903)
This commit is contained in:
		@@ -1,20 +1,20 @@
 | 
			
		||||
namespace Ocelot.UnitTests.LoadBalancer
 | 
			
		||||
{
 | 
			
		||||
    using System;
 | 
			
		||||
    using System.Threading.Tasks;
 | 
			
		||||
    using Microsoft.AspNetCore.Http;
 | 
			
		||||
    using Moq;
 | 
			
		||||
    using Ocelot.Infrastructure;
 | 
			
		||||
    using Ocelot.LoadBalancer.LoadBalancers;
 | 
			
		||||
    using Ocelot.Middleware;
 | 
			
		||||
    using Ocelot.Responses;
 | 
			
		||||
    using Ocelot.UnitTests.Responder;
 | 
			
		||||
    using Ocelot.Values;
 | 
			
		||||
    using Shouldly;
 | 
			
		||||
    using Xunit;
 | 
			
		||||
    using Moq;
 | 
			
		||||
    using Microsoft.AspNetCore.Http;
 | 
			
		||||
    using System.Collections.Generic;
 | 
			
		||||
    using System;
 | 
			
		||||
    using System.Collections;
 | 
			
		||||
    using Ocelot.Middleware;
 | 
			
		||||
    using Ocelot.UnitTests.Responder;
 | 
			
		||||
    using System.Collections.Generic;
 | 
			
		||||
    using System.Threading.Tasks;
 | 
			
		||||
    using TestStack.BDDfy;
 | 
			
		||||
    using Ocelot.Infrastructure;
 | 
			
		||||
    using Xunit;
 | 
			
		||||
 | 
			
		||||
    public class CookieStickySessionsTests
 | 
			
		||||
    {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,12 +1,12 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using Microsoft.AspNetCore.Http;
 | 
			
		||||
using Ocelot.LoadBalancer.LoadBalancers;
 | 
			
		||||
using Ocelot.Middleware;
 | 
			
		||||
using Ocelot.Responses;
 | 
			
		||||
using Ocelot.Values;
 | 
			
		||||
using Shouldly;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using TestStack.BDDfy;
 | 
			
		||||
using Xunit;
 | 
			
		||||
 | 
			
		||||
@@ -42,8 +42,8 @@ namespace Ocelot.UnitTests.LoadBalancer
 | 
			
		||||
            _leastConnection = new LeastConnection(() => Task.FromResult(_services), serviceName);
 | 
			
		||||
 | 
			
		||||
            var tasks = new Task[100];
 | 
			
		||||
           
 | 
			
		||||
            for(var i = 0; i < tasks.Length; i++)
 | 
			
		||||
 | 
			
		||||
            for (var i = 0; i < tasks.Length; i++)
 | 
			
		||||
            {
 | 
			
		||||
                tasks[i] = LeaseDelayAndRelease();
 | 
			
		||||
            }
 | 
			
		||||
@@ -154,7 +154,7 @@ namespace Ocelot.UnitTests.LoadBalancer
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_build_connections_per_service()
 | 
			
		||||
        {
 | 
			
		||||
             var serviceName = "products";
 | 
			
		||||
            var serviceName = "products";
 | 
			
		||||
 | 
			
		||||
            var availableServices = new List<Service>
 | 
			
		||||
            {
 | 
			
		||||
@@ -185,7 +185,7 @@ namespace Ocelot.UnitTests.LoadBalancer
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_release_connection()
 | 
			
		||||
        {
 | 
			
		||||
             var serviceName = "products";
 | 
			
		||||
            var serviceName = "products";
 | 
			
		||||
 | 
			
		||||
            var availableServices = new List<Service>
 | 
			
		||||
            {
 | 
			
		||||
@@ -226,11 +226,11 @@ namespace Ocelot.UnitTests.LoadBalancer
 | 
			
		||||
            var serviceName = "products";
 | 
			
		||||
 | 
			
		||||
            var hostAndPort = new ServiceHostAndPort("localhost", 80);
 | 
			
		||||
               this.Given(x => x.GivenAHostAndPort(hostAndPort))
 | 
			
		||||
                .And(x => x.GivenTheLoadBalancerStarts(null, serviceName))
 | 
			
		||||
                .When(x => x.WhenIGetTheNextHostAndPort())
 | 
			
		||||
                .Then(x => x.ThenServiceAreNullErrorIsReturned())
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
            this.Given(x => x.GivenAHostAndPort(hostAndPort))
 | 
			
		||||
             .And(x => x.GivenTheLoadBalancerStarts(null, serviceName))
 | 
			
		||||
             .When(x => x.WhenIGetTheNextHostAndPort())
 | 
			
		||||
             .Then(x => x.ThenServiceAreNullErrorIsReturned())
 | 
			
		||||
             .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
@@ -239,11 +239,11 @@ namespace Ocelot.UnitTests.LoadBalancer
 | 
			
		||||
            var serviceName = "products";
 | 
			
		||||
 | 
			
		||||
            var hostAndPort = new ServiceHostAndPort("localhost", 80);
 | 
			
		||||
               this.Given(x => x.GivenAHostAndPort(hostAndPort))
 | 
			
		||||
                .And(x => x.GivenTheLoadBalancerStarts(new List<Service>(), serviceName))
 | 
			
		||||
                .When(x => x.WhenIGetTheNextHostAndPort())
 | 
			
		||||
                .Then(x => x.ThenServiceAreEmptyErrorIsReturned())
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
            this.Given(x => x.GivenAHostAndPort(hostAndPort))
 | 
			
		||||
             .And(x => x.GivenTheLoadBalancerStarts(new List<Service>(), serviceName))
 | 
			
		||||
             .When(x => x.WhenIGetTheNextHostAndPort())
 | 
			
		||||
             .Then(x => x.ThenServiceAreEmptyErrorIsReturned())
 | 
			
		||||
             .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void ThenServiceAreNullErrorIsReturned()
 | 
			
		||||
 
 | 
			
		||||
@@ -2,13 +2,13 @@ using Moq;
 | 
			
		||||
using Ocelot.Configuration;
 | 
			
		||||
using Ocelot.Configuration.Builder;
 | 
			
		||||
using Ocelot.LoadBalancer.LoadBalancers;
 | 
			
		||||
using Ocelot.Responses;
 | 
			
		||||
using Ocelot.ServiceDiscovery;
 | 
			
		||||
using Ocelot.ServiceDiscovery.Providers;
 | 
			
		||||
using Shouldly;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using Ocelot.ServiceDiscovery.Providers;
 | 
			
		||||
using TestStack.BDDfy;
 | 
			
		||||
using Xunit;
 | 
			
		||||
using Ocelot.Responses;
 | 
			
		||||
 | 
			
		||||
namespace Ocelot.UnitTests.LoadBalancer
 | 
			
		||||
{
 | 
			
		||||
@@ -48,7 +48,7 @@ namespace Ocelot.UnitTests.LoadBalancer
 | 
			
		||||
        {
 | 
			
		||||
            var reRoute = new DownstreamReRouteBuilder()
 | 
			
		||||
                .WithLoadBalancerOptions(new LoadBalancerOptions("RoundRobin", "", 0))
 | 
			
		||||
                .WithUpstreamHttpMethod(new List<string> {"Get"})
 | 
			
		||||
                .WithUpstreamHttpMethod(new List<string> { "Get" })
 | 
			
		||||
                .Build();
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenAReRoute(reRoute))
 | 
			
		||||
@@ -64,7 +64,7 @@ namespace Ocelot.UnitTests.LoadBalancer
 | 
			
		||||
        {
 | 
			
		||||
            var reRoute = new DownstreamReRouteBuilder()
 | 
			
		||||
                .WithLoadBalancerOptions(new LoadBalancerOptions("LeastConnection", "", 0))
 | 
			
		||||
                .WithUpstreamHttpMethod(new List<string> {"Get"})
 | 
			
		||||
                .WithUpstreamHttpMethod(new List<string> { "Get" })
 | 
			
		||||
                .Build();
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenAReRoute(reRoute))
 | 
			
		||||
@@ -80,7 +80,7 @@ namespace Ocelot.UnitTests.LoadBalancer
 | 
			
		||||
        {
 | 
			
		||||
            var reRoute = new DownstreamReRouteBuilder()
 | 
			
		||||
                .WithLoadBalancerOptions(new LoadBalancerOptions("RoundRobin", "", 0))
 | 
			
		||||
                .WithUpstreamHttpMethod(new List<string> {"Get"})
 | 
			
		||||
                .WithUpstreamHttpMethod(new List<string> { "Get" })
 | 
			
		||||
                .Build();
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenAReRoute(reRoute))
 | 
			
		||||
@@ -96,7 +96,7 @@ namespace Ocelot.UnitTests.LoadBalancer
 | 
			
		||||
        {
 | 
			
		||||
            var reRoute = new DownstreamReRouteBuilder()
 | 
			
		||||
                .WithLoadBalancerOptions(new LoadBalancerOptions("CookieStickySessions", "", 0))
 | 
			
		||||
                .WithUpstreamHttpMethod(new List<string> {"Get"})
 | 
			
		||||
                .WithUpstreamHttpMethod(new List<string> { "Get" })
 | 
			
		||||
                .Build();
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenAReRoute(reRoute))
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,4 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using Moq;
 | 
			
		||||
using Moq;
 | 
			
		||||
using Ocelot.Configuration;
 | 
			
		||||
using Ocelot.Configuration.Builder;
 | 
			
		||||
using Ocelot.LoadBalancer.LoadBalancers;
 | 
			
		||||
@@ -8,6 +6,8 @@ using Ocelot.Middleware;
 | 
			
		||||
using Ocelot.Responses;
 | 
			
		||||
using Ocelot.Values;
 | 
			
		||||
using Shouldly;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using TestStack.BDDfy;
 | 
			
		||||
using Xunit;
 | 
			
		||||
 | 
			
		||||
@@ -26,7 +26,7 @@ namespace Ocelot.UnitTests.LoadBalancer
 | 
			
		||||
        {
 | 
			
		||||
            _factory = new Mock<ILoadBalancerFactory>();
 | 
			
		||||
            _loadBalancerHouse = new LoadBalancerHouse(_factory.Object);
 | 
			
		||||
            _serviceProviderConfig = new ServiceProviderConfiguration("myType","myHost",123, string.Empty, "configKey", 0);
 | 
			
		||||
            _serviceProviderConfig = new ServiceProviderConfiguration("myType", "myHost", 123, string.Empty, "configKey", 0);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
@@ -62,7 +62,7 @@ namespace Ocelot.UnitTests.LoadBalancer
 | 
			
		||||
                .WithLoadBalancerOptions(new LoadBalancerOptions("FakeLoadBalancer", "", 0))
 | 
			
		||||
                .WithLoadBalancerKey("test")
 | 
			
		||||
                .Build();
 | 
			
		||||
            
 | 
			
		||||
 | 
			
		||||
            var reRouteTwo = new DownstreamReRouteBuilder()
 | 
			
		||||
                .WithLoadBalancerOptions(new LoadBalancerOptions("FakeRoundRobinLoadBalancer", "", 0))
 | 
			
		||||
                .WithLoadBalancerKey("testtwo")
 | 
			
		||||
@@ -115,7 +115,7 @@ namespace Ocelot.UnitTests.LoadBalancer
 | 
			
		||||
            _getResult = _loadBalancerHouse.Get(_reRoute, _serviceProviderConfig).Result;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
         private void ThenAnErrorIsReturned()
 | 
			
		||||
        private void ThenAnErrorIsReturned()
 | 
			
		||||
        {
 | 
			
		||||
            _getResult.IsError.ShouldBeTrue();
 | 
			
		||||
            _getResult.Errors[0].ShouldBeOfType<UnableToFindLoadBalancerError>();
 | 
			
		||||
@@ -153,7 +153,7 @@ namespace Ocelot.UnitTests.LoadBalancer
 | 
			
		||||
            _factory.Verify(x => x.Get(_reRoute, _serviceProviderConfig), Times.Once);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        class FakeLoadBalancer : ILoadBalancer
 | 
			
		||||
        private class FakeLoadBalancer : ILoadBalancer
 | 
			
		||||
        {
 | 
			
		||||
            public Task<Response<ServiceHostAndPort>> Lease(DownstreamContext context)
 | 
			
		||||
            {
 | 
			
		||||
@@ -166,7 +166,7 @@ namespace Ocelot.UnitTests.LoadBalancer
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        class FakeRoundRobinLoadBalancer : ILoadBalancer
 | 
			
		||||
        private class FakeRoundRobinLoadBalancer : ILoadBalancer
 | 
			
		||||
        {
 | 
			
		||||
            public Task<Response<ServiceHostAndPort>> Lease(DownstreamContext context)
 | 
			
		||||
            {
 | 
			
		||||
 
 | 
			
		||||
@@ -2,9 +2,6 @@ using Ocelot.Middleware;
 | 
			
		||||
 | 
			
		||||
namespace Ocelot.UnitTests.LoadBalancer
 | 
			
		||||
{
 | 
			
		||||
    using System.Collections.Generic;
 | 
			
		||||
    using System.Net.Http;
 | 
			
		||||
    using System.Threading.Tasks;
 | 
			
		||||
    using Microsoft.AspNetCore.Http;
 | 
			
		||||
    using Moq;
 | 
			
		||||
    using Ocelot.Configuration;
 | 
			
		||||
@@ -17,6 +14,9 @@ namespace Ocelot.UnitTests.LoadBalancer
 | 
			
		||||
    using Ocelot.Responses;
 | 
			
		||||
    using Ocelot.Values;
 | 
			
		||||
    using Shouldly;
 | 
			
		||||
    using System.Collections.Generic;
 | 
			
		||||
    using System.Net.Http;
 | 
			
		||||
    using System.Threading.Tasks;
 | 
			
		||||
    using TestStack.BDDfy;
 | 
			
		||||
    using Xunit;
 | 
			
		||||
 | 
			
		||||
@@ -71,7 +71,7 @@ namespace Ocelot.UnitTests.LoadBalancer
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_set_pipeline_error_if_cannot_get_load_balancer()
 | 
			
		||||
        {         
 | 
			
		||||
        {
 | 
			
		||||
            var downstreamRoute = new DownstreamReRouteBuilder()
 | 
			
		||||
                    .WithUpstreamHttpMethod(new List<string> { "Get" })
 | 
			
		||||
                    .Build();
 | 
			
		||||
@@ -94,9 +94,9 @@ namespace Ocelot.UnitTests.LoadBalancer
 | 
			
		||||
            var downstreamRoute = new DownstreamReRouteBuilder()
 | 
			
		||||
                    .WithUpstreamHttpMethod(new List<string> { "Get" })
 | 
			
		||||
                    .Build();
 | 
			
		||||
                
 | 
			
		||||
             var serviceProviderConfig = new ServiceProviderConfigurationBuilder()
 | 
			
		||||
                .Build();
 | 
			
		||||
 | 
			
		||||
            var serviceProviderConfig = new ServiceProviderConfigurationBuilder()
 | 
			
		||||
               .Build();
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenTheDownStreamUrlIs("http://my.url/abc?q=123"))
 | 
			
		||||
                .And(x => GivenTheConfigurationIs(serviceProviderConfig))
 | 
			
		||||
@@ -130,9 +130,9 @@ namespace Ocelot.UnitTests.LoadBalancer
 | 
			
		||||
        private void GivenTheLoadBalancerReturnsAnError()
 | 
			
		||||
        {
 | 
			
		||||
            _getHostAndPortError = new ErrorResponse<ServiceHostAndPort>(new List<Error>() { new ServicesAreNullError($"services were null for bah") });
 | 
			
		||||
             _loadBalancer
 | 
			
		||||
                .Setup(x => x.Lease(It.IsAny<DownstreamContext>()))
 | 
			
		||||
                .ReturnsAsync(_getHostAndPortError);
 | 
			
		||||
            _loadBalancer
 | 
			
		||||
               .Setup(x => x.Lease(It.IsAny<DownstreamContext>()))
 | 
			
		||||
               .ReturnsAsync(_getHostAndPortError);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void GivenTheLoadBalancerReturns()
 | 
			
		||||
 
 | 
			
		||||
@@ -1,12 +1,11 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using Microsoft.AspNetCore.Http;
 | 
			
		||||
using Ocelot.LoadBalancer.LoadBalancers;
 | 
			
		||||
using Ocelot.Middleware;
 | 
			
		||||
using Ocelot.Responses;
 | 
			
		||||
using Ocelot.Values;
 | 
			
		||||
using Shouldly;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using TestStack.BDDfy;
 | 
			
		||||
using Xunit;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,14 +1,14 @@
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Diagnostics;
 | 
			
		||||
using Microsoft.AspNetCore.Http;
 | 
			
		||||
using Ocelot.LoadBalancer.LoadBalancers;
 | 
			
		||||
using Ocelot.Middleware;
 | 
			
		||||
using Ocelot.Responses;
 | 
			
		||||
using Ocelot.Values;
 | 
			
		||||
using Shouldly;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Diagnostics;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using TestStack.BDDfy;
 | 
			
		||||
using Xunit;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using Ocelot.Middleware;
 | 
			
		||||
using Microsoft.AspNetCore.Http;
 | 
			
		||||
 | 
			
		||||
namespace Ocelot.UnitTests.LoadBalancer
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user