mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 12:30:49 +08:00 
			
		
		
		
	Feature/remove pivotal (#541)
* #529 removed eureka client * #529 removed some unused code
This commit is contained in:
		@@ -42,8 +42,6 @@ namespace Ocelot.DependencyInjection
 | 
				
			|||||||
    using Ocelot.Infrastructure;
 | 
					    using Ocelot.Infrastructure;
 | 
				
			||||||
    using Ocelot.Middleware.Multiplexer;
 | 
					    using Ocelot.Middleware.Multiplexer;
 | 
				
			||||||
    using ServiceDiscovery.Providers;
 | 
					    using ServiceDiscovery.Providers;
 | 
				
			||||||
    using Steeltoe.Common.Discovery;
 | 
					 | 
				
			||||||
    using Pivotal.Discovery.Client;
 | 
					 | 
				
			||||||
    using Ocelot.Request.Creator;
 | 
					    using Ocelot.Request.Creator;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public class OcelotBuilder : IOcelotBuilder
 | 
					    public class OcelotBuilder : IOcelotBuilder
 | 
				
			||||||
@@ -109,16 +107,6 @@ namespace Ocelot.DependencyInjection
 | 
				
			|||||||
            Services.TryAddSingleton<IHttpHandlerOptionsCreator, HttpHandlerOptionsCreator>();
 | 
					            Services.TryAddSingleton<IHttpHandlerOptionsCreator, HttpHandlerOptionsCreator>();
 | 
				
			||||||
            Services.TryAddSingleton<IDownstreamAddressesCreator, DownstreamAddressesCreator>();
 | 
					            Services.TryAddSingleton<IDownstreamAddressesCreator, DownstreamAddressesCreator>();
 | 
				
			||||||
            Services.TryAddSingleton<IDelegatingHandlerHandlerFactory, DelegatingHandlerHandlerFactory>();
 | 
					            Services.TryAddSingleton<IDelegatingHandlerHandlerFactory, DelegatingHandlerHandlerFactory>();
 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (UsingEurekaServiceDiscoveryProvider(configurationRoot))
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                Services.AddDiscoveryClient(configurationRoot);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            else
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                Services.TryAddSingleton<IDiscoveryClient, FakeEurekaDiscoveryClient>();
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            Services.TryAddSingleton<IHttpRequester, HttpClientHttpRequester>();
 | 
					            Services.TryAddSingleton<IHttpRequester, HttpClientHttpRequester>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // see this for why we register this as singleton http://stackoverflow.com/questions/37371264/invalidoperationexception-unable-to-resolve-service-for-type-microsoft-aspnetc
 | 
					            // see this for why we register this as singleton http://stackoverflow.com/questions/37371264/invalidoperationexception-unable-to-resolve-service-for-type-microsoft-aspnetc
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,7 +18,6 @@
 | 
				
			|||||||
    using Rafty.Concensus;
 | 
					    using Rafty.Concensus;
 | 
				
			||||||
    using Rafty.Infrastructure;
 | 
					    using Rafty.Infrastructure;
 | 
				
			||||||
    using Ocelot.Middleware.Pipeline;
 | 
					    using Ocelot.Middleware.Pipeline;
 | 
				
			||||||
    using Pivotal.Discovery.Client;
 | 
					 | 
				
			||||||
    using Rafty.Concensus.Node;
 | 
					    using Rafty.Concensus.Node;
 | 
				
			||||||
    using Microsoft.Extensions.DependencyInjection;
 | 
					    using Microsoft.Extensions.DependencyInjection;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -48,15 +47,9 @@
 | 
				
			|||||||
                SetUpRafty(builder);
 | 
					                SetUpRafty(builder);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (UsingEurekaServiceDiscoveryProvider(configuration))
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                builder.UseDiscoveryClient();
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            ConfigureDiagnosticListener(builder);
 | 
					            ConfigureDiagnosticListener(builder);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return CreateOcelotPipeline(builder, pipelineConfiguration);
 | 
					            return CreateOcelotPipeline(builder, pipelineConfiguration);
 | 
				
			||||||
            
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private static IApplicationBuilder CreateOcelotPipeline(IApplicationBuilder builder, OcelotPipelineConfiguration pipelineConfiguration)
 | 
					        private static IApplicationBuilder CreateOcelotPipeline(IApplicationBuilder builder, OcelotPipelineConfiguration pipelineConfiguration)
 | 
				
			||||||
@@ -84,11 +77,6 @@
 | 
				
			|||||||
            return builder;
 | 
					            return builder;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private static bool UsingEurekaServiceDiscoveryProvider(IInternalConfiguration configuration)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            return configuration?.ServiceProviderConfiguration != null && configuration.ServiceProviderConfiguration.Type?.ToLower() == "eureka";
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        private static bool UsingRafty(IApplicationBuilder builder)
 | 
					        private static bool UsingRafty(IApplicationBuilder builder)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            var node = builder.ApplicationServices.GetService<INode>();
 | 
					            var node = builder.ApplicationServices.GetService<INode>();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -48,7 +48,6 @@
 | 
				
			|||||||
    <PackageReference Include="System.Text.RegularExpressions" Version="4.3.0" />
 | 
					    <PackageReference Include="System.Text.RegularExpressions" Version="4.3.0" />
 | 
				
			||||||
    <PackageReference Include="Polly" Version="6.0.1" />
 | 
					    <PackageReference Include="Polly" Version="6.0.1" />
 | 
				
			||||||
    <PackageReference Include="IdentityServer4" Version="2.2.0" />
 | 
					    <PackageReference Include="IdentityServer4" Version="2.2.0" />
 | 
				
			||||||
    <PackageReference Include="Pivotal.Discovery.ClientCore" Version="2.0.1" />
 | 
					 | 
				
			||||||
    <PackageReference Include="Rafty" Version="0.4.4" />
 | 
					    <PackageReference Include="Rafty" Version="0.4.4" />
 | 
				
			||||||
  </ItemGroup>
 | 
					  </ItemGroup>
 | 
				
			||||||
</Project>
 | 
					</Project>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,34 +0,0 @@
 | 
				
			|||||||
namespace Ocelot.ServiceDiscovery.Providers
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    using System.Collections.Generic;
 | 
					 | 
				
			||||||
    using System.Linq;
 | 
					 | 
				
			||||||
    using System.Threading.Tasks;
 | 
					 | 
				
			||||||
    using Steeltoe.Common.Discovery;
 | 
					 | 
				
			||||||
    using Values;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public class EurekaServiceDiscoveryProvider : IServiceDiscoveryProvider
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        private readonly IDiscoveryClient _client;
 | 
					 | 
				
			||||||
        private readonly string _serviceName;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        public EurekaServiceDiscoveryProvider(string serviceName, IDiscoveryClient client)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            _client = client;
 | 
					 | 
				
			||||||
            _serviceName = serviceName;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        public Task<List<Service>> Get()
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            var services = new List<Service>();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            var instances = _client.GetInstances(_serviceName);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (instances != null && instances.Any())
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                services.AddRange(instances.Select(i => new Service(i.ServiceId, new ServiceHostAndPort(i.Host, i.Port), "", "", new List<string>())));
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
            return Task.FromResult(services);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,27 +0,0 @@
 | 
				
			|||||||
namespace Ocelot.ServiceDiscovery.Providers
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    using System.Collections.Generic;
 | 
					 | 
				
			||||||
    using System.Threading.Tasks;
 | 
					 | 
				
			||||||
    using Steeltoe.Common.Discovery;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public class FakeEurekaDiscoveryClient : IDiscoveryClient
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        public IServiceInstance GetLocalServiceInstance()
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            throw new System.NotImplementedException();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        public IList<IServiceInstance> GetInstances(string serviceId)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            throw new System.NotImplementedException();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        public Task ShutdownAsync()
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            throw new System.NotImplementedException();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        public string Description { get; }
 | 
					 | 
				
			||||||
        public IList<string> Services { get; }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -9,19 +9,16 @@ namespace Ocelot.ServiceDiscovery
 | 
				
			|||||||
    using System;
 | 
					    using System;
 | 
				
			||||||
    using System.Linq;
 | 
					    using System.Linq;
 | 
				
			||||||
    using Microsoft.Extensions.DependencyInjection;
 | 
					    using Microsoft.Extensions.DependencyInjection;
 | 
				
			||||||
    using Steeltoe.Common.Discovery;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public class ServiceDiscoveryProviderFactory : IServiceDiscoveryProviderFactory
 | 
					    public class ServiceDiscoveryProviderFactory : IServiceDiscoveryProviderFactory
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        private readonly IOcelotLoggerFactory _factory;
 | 
					        private readonly IOcelotLoggerFactory _factory;
 | 
				
			||||||
        private readonly IDiscoveryClient _eurekaClient;
 | 
					 | 
				
			||||||
        private readonly List<ServiceDiscoveryFinderDelegate> _delegates;
 | 
					        private readonly List<ServiceDiscoveryFinderDelegate> _delegates;
 | 
				
			||||||
        private readonly IServiceProvider _provider;
 | 
					        private readonly IServiceProvider _provider;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public ServiceDiscoveryProviderFactory(IOcelotLoggerFactory factory, IDiscoveryClient eurekaClient, IServiceProvider provider)
 | 
					        public ServiceDiscoveryProviderFactory(IOcelotLoggerFactory factory, IServiceProvider provider)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            _factory = factory;
 | 
					            _factory = factory;
 | 
				
			||||||
            _eurekaClient = eurekaClient;
 | 
					 | 
				
			||||||
            _provider = provider;
 | 
					            _provider = provider;
 | 
				
			||||||
            _delegates = provider
 | 
					            _delegates = provider
 | 
				
			||||||
                .GetServices<ServiceDiscoveryFinderDelegate>()
 | 
					                .GetServices<ServiceDiscoveryFinderDelegate>()
 | 
				
			||||||
@@ -55,11 +52,6 @@ namespace Ocelot.ServiceDiscovery
 | 
				
			|||||||
                return new ServiceFabricServiceDiscoveryProvider(sfConfig);
 | 
					                return new ServiceFabricServiceDiscoveryProvider(sfConfig);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (config.Type?.ToLower() == "eureka")
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                return new EurekaServiceDiscoveryProvider(key, _eurekaClient);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            foreach (var serviceDiscoveryFinderDelegate in _delegates)
 | 
					            foreach (var serviceDiscoveryFinderDelegate in _delegates)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                var provider = serviceDiscoveryFinderDelegate?.Invoke(_provider, config, key);
 | 
					                var provider = serviceDiscoveryFinderDelegate?.Invoke(_provider, config, key);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,282 +0,0 @@
 | 
				
			|||||||
namespace Ocelot.AcceptanceTests
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    using System;
 | 
					 | 
				
			||||||
    using System.Collections.Generic;
 | 
					 | 
				
			||||||
    using System.Net;
 | 
					 | 
				
			||||||
    using Microsoft.AspNetCore.Http;
 | 
					 | 
				
			||||||
    using Ocelot.Configuration.File;
 | 
					 | 
				
			||||||
    using TestStack.BDDfy;
 | 
					 | 
				
			||||||
    using Xunit;
 | 
					 | 
				
			||||||
    using Newtonsoft.Json;
 | 
					 | 
				
			||||||
    using Steeltoe.Common.Discovery;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public class ServiceDiscoveryTests : IDisposable
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        private readonly Steps _steps;
 | 
					 | 
				
			||||||
        private readonly List<IServiceInstance> _eurekaInstances;
 | 
					 | 
				
			||||||
        private readonly ServiceHandler _serviceHandler;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        public ServiceDiscoveryTests()
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            _serviceHandler = new ServiceHandler();
 | 
					 | 
				
			||||||
            _steps = new Steps();
 | 
					 | 
				
			||||||
            _eurekaInstances = new List<IServiceInstance>();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        [Fact]
 | 
					 | 
				
			||||||
        public void should_use_eureka_service_discovery_and_make_request()
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            var eurekaPort = 8761;
 | 
					 | 
				
			||||||
            var serviceName = "product";
 | 
					 | 
				
			||||||
            var downstreamServicePort = 50371;
 | 
					 | 
				
			||||||
            var downstreamServiceOneUrl = $"http://localhost:{downstreamServicePort}";
 | 
					 | 
				
			||||||
            var fakeEurekaServiceDiscoveryUrl = $"http://localhost:{eurekaPort}";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            var instanceOne = new FakeEurekaService(serviceName, "localhost", downstreamServicePort, false,
 | 
					 | 
				
			||||||
                new Uri($"http://localhost:{downstreamServicePort}"), new Dictionary<string, string>());
 | 
					 | 
				
			||||||
       
 | 
					 | 
				
			||||||
            var configuration = new FileConfiguration
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                ReRoutes = new List<FileReRoute>
 | 
					 | 
				
			||||||
                    {
 | 
					 | 
				
			||||||
                        new FileReRoute
 | 
					 | 
				
			||||||
                        {
 | 
					 | 
				
			||||||
                            DownstreamPathTemplate = "/",
 | 
					 | 
				
			||||||
                            DownstreamScheme = "http",
 | 
					 | 
				
			||||||
                            UpstreamPathTemplate = "/",
 | 
					 | 
				
			||||||
                            UpstreamHttpMethod = new List<string> { "Get" },
 | 
					 | 
				
			||||||
                            ServiceName = serviceName,
 | 
					 | 
				
			||||||
                            LoadBalancerOptions = new FileLoadBalancerOptions { Type = "LeastConnection" },
 | 
					 | 
				
			||||||
                            UseServiceDiscovery = true,
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                    },
 | 
					 | 
				
			||||||
                GlobalConfiguration = new FileGlobalConfiguration()
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
 | 
					 | 
				
			||||||
                    {
 | 
					 | 
				
			||||||
                        Type = "Eureka"
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            this.Given(x => x.GivenEurekaProductServiceOneIsRunning(downstreamServiceOneUrl))
 | 
					 | 
				
			||||||
                .And(x => x.GivenThereIsAFakeEurekaServiceDiscoveryProvider(fakeEurekaServiceDiscoveryUrl, serviceName))
 | 
					 | 
				
			||||||
                .And(x => x.GivenTheServicesAreRegisteredWithEureka(instanceOne))
 | 
					 | 
				
			||||||
                .And(x => _steps.GivenThereIsAConfiguration(configuration))
 | 
					 | 
				
			||||||
                .And(x => _steps.GivenOcelotIsRunning())
 | 
					 | 
				
			||||||
                .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
 | 
					 | 
				
			||||||
                .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))                
 | 
					 | 
				
			||||||
                .And(_ => _steps.ThenTheResponseBodyShouldBe(nameof(ServiceDiscoveryTests)))
 | 
					 | 
				
			||||||
                .BDDfy();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        private void GivenTheServicesAreRegisteredWithEureka(params IServiceInstance[] serviceInstances)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            foreach (var instance in serviceInstances)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                _eurekaInstances.Add(instance);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        private void GivenThereIsAFakeEurekaServiceDiscoveryProvider(string url, string serviceName)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            _serviceHandler.GivenThereIsAServiceRunningOn(url, async context =>
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                if (context.Request.Path.Value == "/eureka/apps/")
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    var apps = new List<Application>();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    foreach (var serviceInstance in _eurekaInstances)
 | 
					 | 
				
			||||||
                    {
 | 
					 | 
				
			||||||
                        var a = new Application
 | 
					 | 
				
			||||||
                        {
 | 
					 | 
				
			||||||
                            name = serviceName,
 | 
					 | 
				
			||||||
                            instance = new List<Instance>
 | 
					 | 
				
			||||||
                                    {
 | 
					 | 
				
			||||||
                                        new Instance
 | 
					 | 
				
			||||||
                                        {
 | 
					 | 
				
			||||||
                                            instanceId = $"{serviceInstance.Host}:{serviceInstance}",
 | 
					 | 
				
			||||||
                                            hostName = serviceInstance.Host,
 | 
					 | 
				
			||||||
                                            app = serviceName,
 | 
					 | 
				
			||||||
                                            ipAddr = "127.0.0.1",
 | 
					 | 
				
			||||||
                                            status = "UP",
 | 
					 | 
				
			||||||
                                            overriddenstatus = "UNKNOWN",
 | 
					 | 
				
			||||||
                                            port = new Port {value = serviceInstance.Port, enabled = "true"},
 | 
					 | 
				
			||||||
                                            securePort = new SecurePort {value = serviceInstance.Port, enabled = "true"},
 | 
					 | 
				
			||||||
                                            countryId = 1,
 | 
					 | 
				
			||||||
                                            dataCenterInfo = new DataCenterInfo {value = "com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo", name = "MyOwn"},
 | 
					 | 
				
			||||||
                                            leaseInfo = new LeaseInfo
 | 
					 | 
				
			||||||
                                            {
 | 
					 | 
				
			||||||
                                                renewalIntervalInSecs = 30,
 | 
					 | 
				
			||||||
                                                durationInSecs = 90,
 | 
					 | 
				
			||||||
                                                registrationTimestamp = 1457714988223,
 | 
					 | 
				
			||||||
                                                lastRenewalTimestamp= 1457716158319,
 | 
					 | 
				
			||||||
                                                evictionTimestamp = 0,
 | 
					 | 
				
			||||||
                                                serviceUpTimestamp = 1457714988223
 | 
					 | 
				
			||||||
                                            },
 | 
					 | 
				
			||||||
                                            metadata = new Metadata
 | 
					 | 
				
			||||||
                                            {
 | 
					 | 
				
			||||||
                                                value = "java.util.Collections$EmptyMap"
 | 
					 | 
				
			||||||
                                            },
 | 
					 | 
				
			||||||
                                            homePageUrl = $"{serviceInstance.Host}:{serviceInstance.Port}",
 | 
					 | 
				
			||||||
                                            statusPageUrl = $"{serviceInstance.Host}:{serviceInstance.Port}",
 | 
					 | 
				
			||||||
                                            healthCheckUrl = $"{serviceInstance.Host}:{serviceInstance.Port}",
 | 
					 | 
				
			||||||
                                            vipAddress = serviceName,
 | 
					 | 
				
			||||||
                                            isCoordinatingDiscoveryServer = "false",
 | 
					 | 
				
			||||||
                                            lastUpdatedTimestamp = "1457714988223",
 | 
					 | 
				
			||||||
                                            lastDirtyTimestamp = "1457714988172",
 | 
					 | 
				
			||||||
                                            actionType = "ADDED"
 | 
					 | 
				
			||||||
                                        }
 | 
					 | 
				
			||||||
                                    }
 | 
					 | 
				
			||||||
                        };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                        apps.Add(a);
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    var applications = new EurekaApplications
 | 
					 | 
				
			||||||
                    {
 | 
					 | 
				
			||||||
                        applications = new Applications
 | 
					 | 
				
			||||||
                        {
 | 
					 | 
				
			||||||
                            application = apps,
 | 
					 | 
				
			||||||
                            apps__hashcode = "UP_1_",
 | 
					 | 
				
			||||||
                            versions__delta = "1"
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                    };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    await context.Response.WriteJsonAsync(applications);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        private void GivenEurekaProductServiceOneIsRunning(string url)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            _serviceHandler.GivenThereIsAServiceRunningOn(url, async context =>
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                try
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    context.Response.StatusCode = 200;
 | 
					 | 
				
			||||||
                    await context.Response.WriteAsync(nameof(ServiceDiscoveryTests));
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                catch (Exception exception)
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    await context.Response.WriteAsync(exception.StackTrace);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        public void Dispose()
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            _serviceHandler?.Dispose();
 | 
					 | 
				
			||||||
            _steps.Dispose();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public class FakeEurekaService : IServiceInstance
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        public FakeEurekaService(string serviceId, string host, int port, bool isSecure, Uri uri, IDictionary<string, string> metadata)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            ServiceId = serviceId;
 | 
					 | 
				
			||||||
            Host = host;
 | 
					 | 
				
			||||||
            Port = port;
 | 
					 | 
				
			||||||
            IsSecure = isSecure;
 | 
					 | 
				
			||||||
            Uri = uri;
 | 
					 | 
				
			||||||
            Metadata = metadata;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        public string ServiceId { get; }
 | 
					 | 
				
			||||||
        public string Host { get; }
 | 
					 | 
				
			||||||
        public int Port { get; }
 | 
					 | 
				
			||||||
        public bool IsSecure { get; }
 | 
					 | 
				
			||||||
        public Uri Uri { get; }
 | 
					 | 
				
			||||||
        public IDictionary<string, string> Metadata { get; }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public class Port
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        [JsonProperty("$")]
 | 
					 | 
				
			||||||
        public int value { get; set; }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        [JsonProperty("@enabled")]
 | 
					 | 
				
			||||||
        public string enabled { get; set; }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public class SecurePort
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        [JsonProperty("$")]
 | 
					 | 
				
			||||||
        public int value { get; set; }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        [JsonProperty("@enabled")]
 | 
					 | 
				
			||||||
        public string enabled { get; set; }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public class DataCenterInfo
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        [JsonProperty("@class")]
 | 
					 | 
				
			||||||
        public string value { get; set; }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        public string name { get; set; }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public class LeaseInfo
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        public int renewalIntervalInSecs { get; set; }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        public int durationInSecs { get; set; }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        public long registrationTimestamp { get; set; }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        public long lastRenewalTimestamp { get; set; }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        public int evictionTimestamp { get; set; }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        public long serviceUpTimestamp { get; set; }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public class Metadata
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        [JsonProperty("@class")]
 | 
					 | 
				
			||||||
        public string value { get; set; }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public class Instance
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        public string instanceId { get; set; }
 | 
					 | 
				
			||||||
        public string hostName { get; set; }
 | 
					 | 
				
			||||||
        public string app { get; set; }
 | 
					 | 
				
			||||||
        public string ipAddr { get; set; }
 | 
					 | 
				
			||||||
        public string status { get; set; }
 | 
					 | 
				
			||||||
        public string overriddenstatus { get; set; }
 | 
					 | 
				
			||||||
        public Port port { get; set; }
 | 
					 | 
				
			||||||
        public SecurePort securePort { get; set; }
 | 
					 | 
				
			||||||
        public int countryId { get; set; }
 | 
					 | 
				
			||||||
        public DataCenterInfo dataCenterInfo { get; set; }
 | 
					 | 
				
			||||||
        public LeaseInfo leaseInfo { get; set; }
 | 
					 | 
				
			||||||
        public Metadata metadata { get; set; }
 | 
					 | 
				
			||||||
        public string homePageUrl { get; set; }
 | 
					 | 
				
			||||||
        public string statusPageUrl { get; set; }
 | 
					 | 
				
			||||||
        public string healthCheckUrl { get; set; }
 | 
					 | 
				
			||||||
        public string vipAddress { get; set; }
 | 
					 | 
				
			||||||
        public string isCoordinatingDiscoveryServer { get; set; }
 | 
					 | 
				
			||||||
        public string lastUpdatedTimestamp { get; set; }
 | 
					 | 
				
			||||||
        public string lastDirtyTimestamp { get; set; }
 | 
					 | 
				
			||||||
        public string actionType { get; set; }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public class Application
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        public string name { get; set; }
 | 
					 | 
				
			||||||
        public List<Instance> instance { get; set; }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public class Applications
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        public string versions__delta { get; set; }
 | 
					 | 
				
			||||||
        public string apps__hashcode { get; set; }
 | 
					 | 
				
			||||||
        public List<Application> application { get; set; }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public class EurekaApplications
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        public Applications applications { get; set; }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -159,15 +159,6 @@ namespace Ocelot.UnitTests.DependencyInjection
 | 
				
			|||||||
            _ocelotBuilder.AddTransientDefinedAggregator<T>();
 | 
					            _ocelotBuilder.AddTransientDefinedAggregator<T>();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private void ThenTheSpecificHandlersAreSingleton()
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            var handlers = _serviceProvider.GetServices<DelegatingHandler>().ToList();
 | 
					 | 
				
			||||||
            var first = handlers[0];
 | 
					 | 
				
			||||||
            handlers = _serviceProvider.GetServices<DelegatingHandler>().ToList();
 | 
					 | 
				
			||||||
            var second = handlers[0];
 | 
					 | 
				
			||||||
            first.ShouldBe(second);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        private void ThenTheSpecificHandlersAreTransient()
 | 
					        private void ThenTheSpecificHandlersAreTransient()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            var handlers = _serviceProvider.GetServices<DelegatingHandler>().ToList();
 | 
					            var handlers = _serviceProvider.GetServices<DelegatingHandler>().ToList();
 | 
				
			||||||
@@ -269,18 +260,6 @@ namespace Ocelot.UnitTests.DependencyInjection
 | 
				
			|||||||
            }       
 | 
					            }       
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private void AddGlobalDelegatingHandler<T>()
 | 
					 | 
				
			||||||
            where T : DelegatingHandler
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            _ocelotBuilder.AddDelegatingHandler<T>(true);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        private void AddSpecificDelegatingHandler<T>()
 | 
					 | 
				
			||||||
            where T : DelegatingHandler
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            _ocelotBuilder.AddDelegatingHandler<T>();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        private void ThenAnOcelotBuilderIsReturned()
 | 
					        private void ThenAnOcelotBuilderIsReturned()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            _ocelotBuilder.ShouldBeOfType<OcelotBuilder>();
 | 
					            _ocelotBuilder.ShouldBeOfType<OcelotBuilder>();
 | 
				
			||||||
@@ -324,19 +303,6 @@ namespace Ocelot.UnitTests.DependencyInjection
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private void WhenIAccessOcelotHttpTracingHandler()
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            try
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                var tracingHandler = _serviceProvider.GetService<OcelotHttpTracingHandler>();
 | 
					 | 
				
			||||||
                tracingHandler.ShouldNotBeNull();
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            catch (Exception e)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                _ex = e;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        private void WhenIValidateScopes()
 | 
					        private void WhenIValidateScopes()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            try
 | 
					            try
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,9 +1,7 @@
 | 
				
			|||||||
namespace Ocelot.UnitTests.Middleware
 | 
					namespace Ocelot.UnitTests.Middleware
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    using System;
 | 
					 | 
				
			||||||
    using Microsoft.Extensions.Configuration;
 | 
					    using Microsoft.Extensions.Configuration;
 | 
				
			||||||
    using Microsoft.Extensions.DependencyInjection;
 | 
					    using Microsoft.Extensions.DependencyInjection;
 | 
				
			||||||
    using Ocelot.Cache;
 | 
					 | 
				
			||||||
    using Ocelot.DependencyInjection;
 | 
					    using Ocelot.DependencyInjection;
 | 
				
			||||||
    using Ocelot.DownstreamRouteFinder.Middleware;
 | 
					    using Ocelot.DownstreamRouteFinder.Middleware;
 | 
				
			||||||
    using Ocelot.DownstreamUrlCreator.Middleware;
 | 
					    using Ocelot.DownstreamUrlCreator.Middleware;
 | 
				
			||||||
@@ -12,10 +10,7 @@ namespace Ocelot.UnitTests.Middleware
 | 
				
			|||||||
    using Ocelot.Middleware.Pipeline;
 | 
					    using Ocelot.Middleware.Pipeline;
 | 
				
			||||||
    using Ocelot.Request.Middleware;
 | 
					    using Ocelot.Request.Middleware;
 | 
				
			||||||
    using Ocelot.WebSockets.Middleware;
 | 
					    using Ocelot.WebSockets.Middleware;
 | 
				
			||||||
    using Pivotal.Discovery.Client;
 | 
					 | 
				
			||||||
    using Shouldly;
 | 
					    using Shouldly;
 | 
				
			||||||
    using Steeltoe.Common.Discovery;
 | 
					 | 
				
			||||||
    using Steeltoe.Discovery.Eureka;
 | 
					 | 
				
			||||||
    using TestStack.BDDfy;
 | 
					    using TestStack.BDDfy;
 | 
				
			||||||
    using Xunit;
 | 
					    using Xunit;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -74,15 +69,6 @@ namespace Ocelot.UnitTests.Middleware
 | 
				
			|||||||
            var root = test.Build();
 | 
					            var root = test.Build();
 | 
				
			||||||
            var services = new ServiceCollection();
 | 
					            var services = new ServiceCollection();
 | 
				
			||||||
            services.AddSingleton<IConfiguration>(root);
 | 
					            services.AddSingleton<IConfiguration>(root);
 | 
				
			||||||
            services.AddDiscoveryClient(new DiscoveryOptions 
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                ClientType = DiscoveryClientType.EUREKA,
 | 
					 | 
				
			||||||
                ClientOptions = new EurekaClientOptions()
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    ShouldFetchRegistry = false,
 | 
					 | 
				
			||||||
                    ShouldRegisterWithEureka = false
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
            services.AddOcelot();
 | 
					            services.AddOcelot();
 | 
				
			||||||
            var provider = services.BuildServiceProvider();
 | 
					            var provider = services.BuildServiceProvider();
 | 
				
			||||||
            _builder = new OcelotPipelineBuilder(provider);
 | 
					            _builder = new OcelotPipelineBuilder(provider);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,118 +0,0 @@
 | 
				
			|||||||
namespace Ocelot.UnitTests.ServiceDiscovery
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    using System;
 | 
					 | 
				
			||||||
    using System.Collections.Generic;
 | 
					 | 
				
			||||||
    using System.Threading.Tasks;
 | 
					 | 
				
			||||||
    using Moq;
 | 
					 | 
				
			||||||
    using Ocelot.ServiceDiscovery.Providers;
 | 
					 | 
				
			||||||
    using Pivotal.Discovery.Client;
 | 
					 | 
				
			||||||
    using Shouldly;
 | 
					 | 
				
			||||||
    using Steeltoe.Common.Discovery;
 | 
					 | 
				
			||||||
    using TestStack.BDDfy;
 | 
					 | 
				
			||||||
    using Values;
 | 
					 | 
				
			||||||
    using Xunit;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public class EurekaServiceDiscoveryProviderTests
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        private readonly EurekaServiceDiscoveryProvider _provider;
 | 
					 | 
				
			||||||
        private readonly Mock<IDiscoveryClient> _client;
 | 
					 | 
				
			||||||
        private readonly string _serviceId;
 | 
					 | 
				
			||||||
        private List<IServiceInstance> _instances;
 | 
					 | 
				
			||||||
        private List<Service> _result;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        public EurekaServiceDiscoveryProviderTests()
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            _serviceId = "Laura";
 | 
					 | 
				
			||||||
            _client = new Mock<IDiscoveryClient>();
 | 
					 | 
				
			||||||
            _provider = new EurekaServiceDiscoveryProvider(_serviceId, _client.Object);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        [Fact]
 | 
					 | 
				
			||||||
        public void should_return_empty_services()
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            this.When(_ => WhenIGet())
 | 
					 | 
				
			||||||
                .Then(_ => ThenTheCountIs(0))
 | 
					 | 
				
			||||||
                .BDDfy();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        [Fact]
 | 
					 | 
				
			||||||
        public void should_return_service_from_client()
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            var instances = new List<IServiceInstance>
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                new EurekaService(_serviceId, "somehost", 801, false, new Uri("http://somehost:801"), new Dictionary<string, string>())
 | 
					 | 
				
			||||||
            };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            this.Given(_ => GivenThe(instances))
 | 
					 | 
				
			||||||
                .When(_ => WhenIGet())
 | 
					 | 
				
			||||||
                .Then(_ => ThenTheCountIs(1))
 | 
					 | 
				
			||||||
                .And(_ => ThenTheClientIsCalledCorrectly())
 | 
					 | 
				
			||||||
                .And(_ => ThenTheServiceIsMapped())
 | 
					 | 
				
			||||||
                .BDDfy();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        [Fact]
 | 
					 | 
				
			||||||
        public void should_return_services_from_client()
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            var instances = new List<IServiceInstance>
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                new EurekaService(_serviceId, "somehost", 801, false, new Uri("http://somehost:801"), new Dictionary<string, string>()),
 | 
					 | 
				
			||||||
                new EurekaService(_serviceId, "somehost", 801, false, new Uri("http://somehost:801"), new Dictionary<string, string>())
 | 
					 | 
				
			||||||
            };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            this.Given(_ => GivenThe(instances))
 | 
					 | 
				
			||||||
                .When(_ => WhenIGet())
 | 
					 | 
				
			||||||
                .Then(_ => ThenTheCountIs(2))
 | 
					 | 
				
			||||||
                .And(_ => ThenTheClientIsCalledCorrectly())
 | 
					 | 
				
			||||||
                .BDDfy();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        private void ThenTheServiceIsMapped()
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            _result[0].HostAndPort.DownstreamHost.ShouldBe("somehost");
 | 
					 | 
				
			||||||
            _result[0].HostAndPort.DownstreamPort.ShouldBe(801);
 | 
					 | 
				
			||||||
            _result[0].Name.ShouldBe(_serviceId);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        private void ThenTheCountIs(int expected)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            _result.Count.ShouldBe(expected);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        private void ThenTheClientIsCalledCorrectly()
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            _client.Verify(x => x.GetInstances(_serviceId), Times.Once);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        private async Task WhenIGet()
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            _result = await _provider.Get();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        private void GivenThe(List<IServiceInstance> instances)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            _instances = instances;
 | 
					 | 
				
			||||||
            _client.Setup(x => x.GetInstances(It.IsAny<string>())).Returns(instances);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public class EurekaService : IServiceInstance
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        public EurekaService(string serviceId, string host, int port, bool isSecure, Uri uri, IDictionary<string, string> metadata)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            ServiceId = serviceId;
 | 
					 | 
				
			||||||
            Host = host;
 | 
					 | 
				
			||||||
            Port = port;
 | 
					 | 
				
			||||||
            IsSecure = isSecure;
 | 
					 | 
				
			||||||
            Uri = uri;
 | 
					 | 
				
			||||||
            Metadata = metadata;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        public string ServiceId { get; }
 | 
					 | 
				
			||||||
        public string Host { get; }
 | 
					 | 
				
			||||||
        public int Port { get; }
 | 
					 | 
				
			||||||
        public bool IsSecure { get; }
 | 
					 | 
				
			||||||
        public Uri Uri { get; }
 | 
					 | 
				
			||||||
        public IDictionary<string, string> Metadata { get; }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -3,7 +3,6 @@ namespace Ocelot.UnitTests.ServiceDiscovery
 | 
				
			|||||||
    using System;
 | 
					    using System;
 | 
				
			||||||
    using System.Threading.Tasks;
 | 
					    using System.Threading.Tasks;
 | 
				
			||||||
    using Microsoft.Extensions.DependencyInjection;
 | 
					    using Microsoft.Extensions.DependencyInjection;
 | 
				
			||||||
    using Steeltoe.Common.Discovery;
 | 
					 | 
				
			||||||
    using Values;
 | 
					    using Values;
 | 
				
			||||||
    using System.Collections.Generic;
 | 
					    using System.Collections.Generic;
 | 
				
			||||||
    using Moq;
 | 
					    using Moq;
 | 
				
			||||||
@@ -22,20 +21,18 @@ namespace Ocelot.UnitTests.ServiceDiscovery
 | 
				
			|||||||
        private IServiceDiscoveryProvider _result;
 | 
					        private IServiceDiscoveryProvider _result;
 | 
				
			||||||
        private ServiceDiscoveryProviderFactory _factory;
 | 
					        private ServiceDiscoveryProviderFactory _factory;
 | 
				
			||||||
        private DownstreamReRoute _reRoute;
 | 
					        private DownstreamReRoute _reRoute;
 | 
				
			||||||
        private Mock<IOcelotLoggerFactory> _loggerFactory;
 | 
					        private readonly Mock<IOcelotLoggerFactory> _loggerFactory;
 | 
				
			||||||
        private Mock<IDiscoveryClient> _discoveryClient;
 | 
					 | 
				
			||||||
        private Mock<IOcelotLogger> _logger;
 | 
					        private Mock<IOcelotLogger> _logger;
 | 
				
			||||||
        private IServiceProvider _provider;
 | 
					        private IServiceProvider _provider;
 | 
				
			||||||
        private IServiceCollection _collection;
 | 
					        private readonly IServiceCollection _collection;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public ServiceProviderFactoryTests()
 | 
					        public ServiceProviderFactoryTests()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            _loggerFactory = new Mock<IOcelotLoggerFactory>();
 | 
					            _loggerFactory = new Mock<IOcelotLoggerFactory>();
 | 
				
			||||||
            _logger = new Mock<IOcelotLogger>();
 | 
					            _logger = new Mock<IOcelotLogger>();
 | 
				
			||||||
            _discoveryClient = new Mock<IDiscoveryClient>();
 | 
					 | 
				
			||||||
            _collection = new ServiceCollection();
 | 
					            _collection = new ServiceCollection();
 | 
				
			||||||
            _provider = _collection.BuildServiceProvider();
 | 
					            _provider = _collection.BuildServiceProvider();
 | 
				
			||||||
            _factory = new ServiceDiscoveryProviderFactory(_loggerFactory.Object, _discoveryClient.Object, _provider);
 | 
					            _factory = new ServiceDiscoveryProviderFactory(_loggerFactory.Object, _provider);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        [Fact]
 | 
					        [Fact]
 | 
				
			||||||
@@ -109,30 +106,12 @@ namespace Ocelot.UnitTests.ServiceDiscovery
 | 
				
			|||||||
                .BDDfy();
 | 
					                .BDDfy();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        [Fact]
 | 
					 | 
				
			||||||
        public void should_return_eureka_provider()
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            var reRoute = new DownstreamReRouteBuilder()
 | 
					 | 
				
			||||||
                .WithServiceName("product")
 | 
					 | 
				
			||||||
                .WithUseServiceDiscovery(true)
 | 
					 | 
				
			||||||
                .Build();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            var serviceConfig = new ServiceProviderConfigurationBuilder()
 | 
					 | 
				
			||||||
                .WithType("Eureka")
 | 
					 | 
				
			||||||
                .Build();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            this.Given(x => x.GivenTheReRoute(serviceConfig, reRoute))
 | 
					 | 
				
			||||||
                .When(x => x.WhenIGetTheServiceProvider())
 | 
					 | 
				
			||||||
                .Then(x => x.ThenTheServiceProviderIs<EurekaServiceDiscoveryProvider>())
 | 
					 | 
				
			||||||
                .BDDfy();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        private void GivenAFakeDelegate()
 | 
					        private void GivenAFakeDelegate()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            ServiceDiscoveryFinderDelegate fake = (provider, config, name) => new Fake();
 | 
					            ServiceDiscoveryFinderDelegate fake = (provider, config, name) => new Fake();
 | 
				
			||||||
            _collection.AddSingleton(fake);
 | 
					            _collection.AddSingleton(fake);
 | 
				
			||||||
            _provider = _collection.BuildServiceProvider();
 | 
					            _provider = _collection.BuildServiceProvider();
 | 
				
			||||||
            _factory = new ServiceDiscoveryProviderFactory(_loggerFactory.Object, _discoveryClient.Object, _provider);
 | 
					            _factory = new ServiceDiscoveryProviderFactory(_loggerFactory.Object, _provider);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        class Fake : IServiceDiscoveryProvider
 | 
					        class Fake : IServiceDiscoveryProvider
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user