mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 12:50:49 +08:00 
			
		
		
		
	update .net core 3.0 RTM (#1025)
* feat: update to asp.net core 3.0 preview 9 * fix : AspDotNetLogger unittest * feat: update generic host and useMvc 1、Using 'UseMvc' to configure MVC is not supported while using Endpoint Routing https://github.com/aspnet/AspNetCore/issues/9542 2、 use IHost and IHostBuilder * feat : update .net core 3.0 rc1 * eureka extension * fixed logger formatter error * fixed synchronous operations are disallowed of ReadToEnd method * fix log tests * Flush method of FakeStream should do nothing * Update ContentTests.cs * Fixed ws tests * feat: delelte comment code * feat: update .net core 3.0 RTM * Update OcelotBuilderTests.cs * Update .travis.yml mono 6.0.0 and dotnet 3.0.100 * Update Ocelot.IntegrationTests.csproj update Microsoft.Data.SQLite 3.0.0 * Update .travis.yml * feat: remove FrameworkReference 1、 remove FrameworkReference 2、 update package * add appveyor configuration to use version of VS2019 with dotnet core 3 sdk support * update obsoleted SetCollectionValidator method * Swap out OpenCover for Coverlet * Bump Cake to 0.35.0 * Downgrade coveralls.net to 0.7.0 Fix disposing of PollConsul instance * Remove environment specific path separator * Do not return ReportGenerator on Mac/Linux * Remove direct dependency on IInternalConfiguration * Fix ordering of variable assignment * Fix broken tests * Fix acceptance tests for Consul
This commit is contained in:
		@@ -2,14 +2,15 @@ namespace Ocelot.UnitTests.Administration
 | 
			
		||||
{
 | 
			
		||||
    using IdentityServer4.AccessTokenValidation;
 | 
			
		||||
    using Microsoft.AspNetCore.Hosting;
 | 
			
		||||
    using Microsoft.AspNetCore.Hosting.Internal;
 | 
			
		||||
    using Microsoft.Extensions.Configuration;
 | 
			
		||||
    using Microsoft.Extensions.DependencyInjection;
 | 
			
		||||
    using Moq;
 | 
			
		||||
    using Ocelot.Administration;
 | 
			
		||||
    using Ocelot.DependencyInjection;
 | 
			
		||||
    using Shouldly;
 | 
			
		||||
    using System;
 | 
			
		||||
    using System.Collections.Generic;
 | 
			
		||||
    using System.Reflection;
 | 
			
		||||
    using TestStack.BDDfy;
 | 
			
		||||
    using Xunit;
 | 
			
		||||
 | 
			
		||||
@@ -25,9 +26,19 @@ namespace Ocelot.UnitTests.Administration
 | 
			
		||||
        {
 | 
			
		||||
            _configRoot = new ConfigurationRoot(new List<IConfigurationProvider>());
 | 
			
		||||
            _services = new ServiceCollection();
 | 
			
		||||
            _services.AddSingleton<IHostingEnvironment, HostingEnvironment>();
 | 
			
		||||
            _services.AddSingleton<IWebHostEnvironment>(GetHostingEnvironment());
 | 
			
		||||
            _services.AddSingleton(_configRoot);
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        private IWebHostEnvironment GetHostingEnvironment()
 | 
			
		||||
        {
 | 
			
		||||
            var environment = new Mock<IWebHostEnvironment>();
 | 
			
		||||
            environment
 | 
			
		||||
                .Setup(e => e.ApplicationName)
 | 
			
		||||
                .Returns(typeof(OcelotAdministrationBuilderTests).GetTypeInfo().Assembly.GetName().Name);
 | 
			
		||||
 | 
			
		||||
            return environment.Object;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        //keep
 | 
			
		||||
        [Fact]
 | 
			
		||||
 
 | 
			
		||||
@@ -2,9 +2,10 @@
 | 
			
		||||
{
 | 
			
		||||
    using global::CacheManager.Core;
 | 
			
		||||
    using Microsoft.AspNetCore.Hosting;
 | 
			
		||||
    using Microsoft.AspNetCore.Hosting.Internal;
 | 
			
		||||
    using Microsoft.Extensions.Configuration;
 | 
			
		||||
    using Microsoft.Extensions.DependencyInjection;
 | 
			
		||||
    using Microsoft.Extensions.Hosting.Internal;
 | 
			
		||||
    using Moq;
 | 
			
		||||
    using Ocelot.Cache;
 | 
			
		||||
    using Ocelot.Cache.CacheManager;
 | 
			
		||||
    using Ocelot.Configuration;
 | 
			
		||||
@@ -14,6 +15,7 @@
 | 
			
		||||
    using System;
 | 
			
		||||
    using System.Collections.Generic;
 | 
			
		||||
    using System.Linq;
 | 
			
		||||
    using System.Reflection;
 | 
			
		||||
    using TestStack.BDDfy;
 | 
			
		||||
    using Xunit;
 | 
			
		||||
 | 
			
		||||
@@ -30,11 +32,21 @@
 | 
			
		||||
        {
 | 
			
		||||
            _configRoot = new ConfigurationRoot(new List<IConfigurationProvider>());
 | 
			
		||||
            _services = new ServiceCollection();
 | 
			
		||||
            _services.AddSingleton<IHostingEnvironment, HostingEnvironment>();
 | 
			
		||||
            _services.AddSingleton<IWebHostEnvironment>(GetHostingEnvironment());
 | 
			
		||||
            _services.AddSingleton(_configRoot);
 | 
			
		||||
            _maxRetries = 100;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private IWebHostEnvironment GetHostingEnvironment()
 | 
			
		||||
        {
 | 
			
		||||
            var environment = new Mock<IWebHostEnvironment>();
 | 
			
		||||
            environment
 | 
			
		||||
                .Setup(e => e.ApplicationName)
 | 
			
		||||
                .Returns(typeof(OcelotBuilderExtensionsTests).GetTypeInfo().Assembly.GetName().Name);
 | 
			
		||||
 | 
			
		||||
            return environment.Object;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_set_up_cache_manager()
 | 
			
		||||
        {
 | 
			
		||||
 
 | 
			
		||||
@@ -15,7 +15,7 @@ namespace Ocelot.UnitTests.Configuration
 | 
			
		||||
 | 
			
		||||
    public class DiskFileConfigurationRepositoryTests : IDisposable
 | 
			
		||||
    {
 | 
			
		||||
        private readonly Mock<IHostingEnvironment> _hostingEnvironment;
 | 
			
		||||
        private readonly Mock<IWebHostEnvironment> _hostingEnvironment;
 | 
			
		||||
        private IFileConfigurationRepository _repo;
 | 
			
		||||
        private string _environmentSpecificPath;
 | 
			
		||||
        private string _ocelotJsonPath;
 | 
			
		||||
@@ -33,7 +33,7 @@ namespace Ocelot.UnitTests.Configuration
 | 
			
		||||
        {
 | 
			
		||||
            _semaphore = new SemaphoreSlim(1, 1);
 | 
			
		||||
            _semaphore.Wait();
 | 
			
		||||
            _hostingEnvironment = new Mock<IHostingEnvironment>();
 | 
			
		||||
            _hostingEnvironment = new Mock<IWebHostEnvironment>();
 | 
			
		||||
            _hostingEnvironment.Setup(he => he.EnvironmentName).Returns(_environmentName);
 | 
			
		||||
            _repo = new DiskFileConfigurationRepository(_hostingEnvironment.Object);
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,7 @@
 | 
			
		||||
namespace Ocelot.UnitTests.Consul
 | 
			
		||||
{
 | 
			
		||||
    using global::Consul;
 | 
			
		||||
    using Microsoft.Extensions.Options;
 | 
			
		||||
    using Moq;
 | 
			
		||||
    using Newtonsoft.Json;
 | 
			
		||||
    using Ocelot.Cache;
 | 
			
		||||
@@ -23,8 +24,8 @@
 | 
			
		||||
    public class ConsulFileConfigurationRepositoryTests
 | 
			
		||||
    {
 | 
			
		||||
        private ConsulFileConfigurationRepository _repo;
 | 
			
		||||
        private Mock<IOptions<FileConfiguration>> _options;
 | 
			
		||||
        private Mock<IOcelotCache<FileConfiguration>> _cache;
 | 
			
		||||
        private Mock<IInternalConfigurationRepository> _internalRepo;
 | 
			
		||||
        private Mock<IConsulClientFactory> _factory;
 | 
			
		||||
        private Mock<IOcelotLoggerFactory> _loggerFactory;
 | 
			
		||||
        private Mock<IConsulClient> _client;
 | 
			
		||||
@@ -36,9 +37,9 @@
 | 
			
		||||
        public ConsulFileConfigurationRepositoryTests()
 | 
			
		||||
        {
 | 
			
		||||
            _cache = new Mock<IOcelotCache<FileConfiguration>>();
 | 
			
		||||
            _internalRepo = new Mock<IInternalConfigurationRepository>();
 | 
			
		||||
            _loggerFactory = new Mock<IOcelotLoggerFactory>();
 | 
			
		||||
 | 
			
		||||
            _options = new Mock<IOptions<FileConfiguration>>();
 | 
			
		||||
            _factory = new Mock<IConsulClientFactory>();
 | 
			
		||||
            _client = new Mock<IConsulClient>();
 | 
			
		||||
            _kvEndpoint = new Mock<IKVEndpoint>();
 | 
			
		||||
@@ -51,11 +52,9 @@
 | 
			
		||||
                .Setup(x => x.Get(It.IsAny<ConsulRegistryConfiguration>()))
 | 
			
		||||
                .Returns(_client.Object);
 | 
			
		||||
 | 
			
		||||
            _internalRepo
 | 
			
		||||
                .Setup(x => x.Get())
 | 
			
		||||
                .Returns(new OkResponse<IInternalConfiguration>(new InternalConfiguration(new List<ReRoute>(), "", new ServiceProviderConfigurationBuilder().Build(), "", It.IsAny<LoadBalancerOptions>(), It.IsAny<string>(), It.IsAny<QoSOptions>(), It.IsAny<HttpHandlerOptions>())));
 | 
			
		||||
 | 
			
		||||
            _repo = new ConsulFileConfigurationRepository(_cache.Object, _internalRepo.Object, _factory.Object, _loggerFactory.Object);
 | 
			
		||||
            _options
 | 
			
		||||
                .SetupGet(x => x.Value)
 | 
			
		||||
                .Returns(() => _fileConfiguration);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
@@ -85,7 +84,10 @@
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_get_null_config()
 | 
			
		||||
        {
 | 
			
		||||
            this.Given(_ => GivenFetchFromConsulReturnsNull())
 | 
			
		||||
            var config = FakeFileConfiguration();
 | 
			
		||||
 | 
			
		||||
            this.Given(_ => GivenIHaveAConfiguration(config))
 | 
			
		||||
               .Given(_ => GivenFetchFromConsulReturnsNull())
 | 
			
		||||
               .When(_ => WhenIGetTheConfiguration())
 | 
			
		||||
               .Then(_ => ThenTheConfigurationIsNull())
 | 
			
		||||
               .BDDfy();
 | 
			
		||||
@@ -136,14 +138,8 @@
 | 
			
		||||
 | 
			
		||||
        private void GivenTheConfigKeyComesFromFileConfig(string key)
 | 
			
		||||
        {
 | 
			
		||||
            _internalRepo
 | 
			
		||||
                .Setup(x => x.Get())
 | 
			
		||||
                .Returns(new OkResponse<IInternalConfiguration>(new InternalConfiguration(new List<ReRoute>(), "",
 | 
			
		||||
                    new ServiceProviderConfigurationBuilder().WithConfigurationKey(key).Build(), "",
 | 
			
		||||
                    new LoadBalancerOptionsBuilder().Build(), "", new QoSOptionsBuilder().Build(),
 | 
			
		||||
                    new HttpHandlerOptionsBuilder().Build())));
 | 
			
		||||
 | 
			
		||||
            _repo = new ConsulFileConfigurationRepository(_cache.Object, _internalRepo.Object, _factory.Object, _loggerFactory.Object);
 | 
			
		||||
            _fileConfiguration.GlobalConfiguration.ServiceDiscoveryProvider.ConfigurationKey = key;
 | 
			
		||||
            _repo = new ConsulFileConfigurationRepository(_options.Object, _cache.Object, _factory.Object, _loggerFactory.Object);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void ThenTheConfigurationIsNull()
 | 
			
		||||
@@ -221,6 +217,8 @@
 | 
			
		||||
        private void GivenIHaveAConfiguration(FileConfiguration config)
 | 
			
		||||
        {
 | 
			
		||||
            _fileConfiguration = config;
 | 
			
		||||
 | 
			
		||||
            _repo = new ConsulFileConfigurationRepository(_options.Object, _cache.Object, _factory.Object, _loggerFactory.Object);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private FileConfiguration FakeFileConfiguration()
 | 
			
		||||
 
 | 
			
		||||
@@ -1,14 +1,15 @@
 | 
			
		||||
namespace Ocelot.UnitTests.Consul
 | 
			
		||||
{
 | 
			
		||||
    using Microsoft.AspNetCore.Hosting;
 | 
			
		||||
    using Microsoft.AspNetCore.Hosting.Internal;
 | 
			
		||||
    using Microsoft.Extensions.Configuration;
 | 
			
		||||
    using Microsoft.Extensions.DependencyInjection;
 | 
			
		||||
    using Moq;
 | 
			
		||||
    using Ocelot.DependencyInjection;
 | 
			
		||||
    using Provider.Consul;
 | 
			
		||||
    using Shouldly;
 | 
			
		||||
    using System;
 | 
			
		||||
    using System.Collections.Generic;
 | 
			
		||||
    using System.Reflection;
 | 
			
		||||
    using TestStack.BDDfy;
 | 
			
		||||
    using Xunit;
 | 
			
		||||
 | 
			
		||||
@@ -24,10 +25,21 @@
 | 
			
		||||
        {
 | 
			
		||||
            _configRoot = new ConfigurationRoot(new List<IConfigurationProvider>());
 | 
			
		||||
            _services = new ServiceCollection();
 | 
			
		||||
            _services.AddSingleton<IHostingEnvironment, HostingEnvironment>();
 | 
			
		||||
            _services.AddSingleton<IWebHostEnvironment>(GetHostingEnvironment());
 | 
			
		||||
            _services.AddSingleton(_configRoot);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        private IWebHostEnvironment GetHostingEnvironment()
 | 
			
		||||
        {
 | 
			
		||||
            var environment = new Mock<IWebHostEnvironment>();
 | 
			
		||||
            environment
 | 
			
		||||
                .Setup(e => e.ApplicationName)
 | 
			
		||||
                .Returns(typeof(OcelotBuilderExtensionsTests).GetTypeInfo().Assembly.GetName().Name);
 | 
			
		||||
 | 
			
		||||
            return environment.Object;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_set_up_consul()
 | 
			
		||||
        {
 | 
			
		||||
 
 | 
			
		||||
@@ -15,7 +15,6 @@
 | 
			
		||||
    public class PollingConsulServiceDiscoveryProviderTests
 | 
			
		||||
    {
 | 
			
		||||
        private readonly int _delay;
 | 
			
		||||
        private PollConsul _provider;
 | 
			
		||||
        private readonly List<Service> _services;
 | 
			
		||||
        private readonly Mock<IOcelotLoggerFactory> _factory;
 | 
			
		||||
        private readonly Mock<IOcelotLogger> _logger;
 | 
			
		||||
@@ -56,27 +55,28 @@
 | 
			
		||||
 | 
			
		||||
        private void WhenIGetTheServices(int expected)
 | 
			
		||||
        {
 | 
			
		||||
            _provider = new PollConsul(_delay, _factory.Object, _consulServiceDiscoveryProvider.Object);
 | 
			
		||||
 | 
			
		||||
            var result = Wait.WaitFor(3000).Until(() =>
 | 
			
		||||
            using (var provider = new PollConsul(_delay, _factory.Object, _consulServiceDiscoveryProvider.Object))
 | 
			
		||||
            {
 | 
			
		||||
                try
 | 
			
		||||
                var result = Wait.WaitFor(3000).Until(() =>
 | 
			
		||||
                {
 | 
			
		||||
                    _result = _provider.Get().GetAwaiter().GetResult();
 | 
			
		||||
                    if (_result.Count == expected)
 | 
			
		||||
                    try
 | 
			
		||||
                    {
 | 
			
		||||
                        return true;
 | 
			
		||||
                        _result = provider.Get().GetAwaiter().GetResult();
 | 
			
		||||
                        if (_result.Count == expected)
 | 
			
		||||
                        {
 | 
			
		||||
                            return true;
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        return false;
 | 
			
		||||
                    }
 | 
			
		||||
                    catch (Exception)
 | 
			
		||||
                    {
 | 
			
		||||
                        return false;
 | 
			
		||||
                    }
 | 
			
		||||
                });
 | 
			
		||||
 | 
			
		||||
                    return false;
 | 
			
		||||
                }
 | 
			
		||||
                catch (Exception)
 | 
			
		||||
                {
 | 
			
		||||
                    return false;
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
            result.ShouldBeTrue();
 | 
			
		||||
                result.ShouldBeTrue();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -49,7 +49,9 @@ namespace Ocelot.UnitTests.Consul
 | 
			
		||||
                .Build();
 | 
			
		||||
 | 
			
		||||
            var provider = ConsulProviderFactory.Get(_provider, new ServiceProviderConfiguration("pollconsul", "", 1, "", "", stopsPollerFromPolling), reRoute);
 | 
			
		||||
            provider.ShouldBeOfType<PollConsul>();
 | 
			
		||||
            var pollProvider = provider as PollConsul;
 | 
			
		||||
            pollProvider.ShouldNotBeNull();
 | 
			
		||||
            pollProvider.Dispose();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -22,11 +22,11 @@
 | 
			
		||||
        private FileConfiguration _reRouteB;
 | 
			
		||||
        private FileConfiguration _aggregate;
 | 
			
		||||
        private FileConfiguration _envSpecific;
 | 
			
		||||
        private Mock<IHostingEnvironment> _hostingEnvironment;
 | 
			
		||||
        private Mock<IWebHostEnvironment> _hostingEnvironment;
 | 
			
		||||
 | 
			
		||||
        public ConfigurationBuilderExtensionsTests()
 | 
			
		||||
        {
 | 
			
		||||
            _hostingEnvironment = new Mock<IHostingEnvironment>();
 | 
			
		||||
            _hostingEnvironment = new Mock<IWebHostEnvironment>();
 | 
			
		||||
            // Clean up config files before each test
 | 
			
		||||
            var subConfigFiles = new DirectoryInfo(".").GetFiles("ocelot.*.json");
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,11 +1,12 @@
 | 
			
		||||
namespace Ocelot.UnitTests.DependencyInjection
 | 
			
		||||
{
 | 
			
		||||
    using Microsoft.AspNetCore.Hosting;
 | 
			
		||||
    using Microsoft.AspNetCore.Hosting.Internal;
 | 
			
		||||
    using Microsoft.Extensions.Configuration;
 | 
			
		||||
    using Microsoft.Extensions.DependencyInjection;
 | 
			
		||||
    using Moq;
 | 
			
		||||
    using Ocelot.Configuration.Setter;
 | 
			
		||||
    using Ocelot.DependencyInjection;
 | 
			
		||||
    using Ocelot.Infrastructure;
 | 
			
		||||
    using Ocelot.Middleware.Multiplexer;
 | 
			
		||||
    using Ocelot.Requester;
 | 
			
		||||
    using Ocelot.UnitTests.Requester;
 | 
			
		||||
@@ -14,7 +15,7 @@ namespace Ocelot.UnitTests.DependencyInjection
 | 
			
		||||
    using System.Collections.Generic;
 | 
			
		||||
    using System.Linq;
 | 
			
		||||
    using System.Net.Http;
 | 
			
		||||
    using Ocelot.Infrastructure;
 | 
			
		||||
    using System.Reflection;
 | 
			
		||||
    using TestStack.BDDfy;
 | 
			
		||||
    using Xunit;
 | 
			
		||||
    using static Ocelot.UnitTests.Middleware.UserDefinedResponseAggregatorTests;
 | 
			
		||||
@@ -32,11 +33,21 @@ namespace Ocelot.UnitTests.DependencyInjection
 | 
			
		||||
        {
 | 
			
		||||
            _configRoot = new ConfigurationRoot(new List<IConfigurationProvider>());
 | 
			
		||||
            _services = new ServiceCollection();
 | 
			
		||||
            _services.AddSingleton<IHostingEnvironment, HostingEnvironment>();
 | 
			
		||||
            _services.AddSingleton<IWebHostEnvironment>(GetHostingEnvironment());
 | 
			
		||||
            _services.AddSingleton(_configRoot);
 | 
			
		||||
            _maxRetries = 100;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private IWebHostEnvironment GetHostingEnvironment()
 | 
			
		||||
        {
 | 
			
		||||
            var environment = new Mock<IWebHostEnvironment>();
 | 
			
		||||
            environment
 | 
			
		||||
                .Setup(e => e.ApplicationName)
 | 
			
		||||
                .Returns(typeof(OcelotBuilderTests).GetTypeInfo().Assembly.GetName().Name);
 | 
			
		||||
 | 
			
		||||
            return environment.Object;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_add_specific_delegating_handlers_transient()
 | 
			
		||||
        {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
namespace Ocelot.UnitTests.Eureka
 | 
			
		||||
{
 | 
			
		||||
    using Microsoft.AspNetCore.Builder.Internal;
 | 
			
		||||
    using Microsoft.AspNetCore.Builder;
 | 
			
		||||
    using Microsoft.Extensions.DependencyInjection;
 | 
			
		||||
    using Moq;
 | 
			
		||||
    using Ocelot.Configuration;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,12 +1,13 @@
 | 
			
		||||
using Microsoft.AspNetCore.Hosting;
 | 
			
		||||
using Microsoft.AspNetCore.Hosting.Internal;
 | 
			
		||||
using Microsoft.Extensions.Configuration;
 | 
			
		||||
using Microsoft.Extensions.DependencyInjection;
 | 
			
		||||
using Moq;
 | 
			
		||||
using Ocelot.DependencyInjection;
 | 
			
		||||
using Ocelot.Provider.Kubernetes;
 | 
			
		||||
using Shouldly;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Reflection;
 | 
			
		||||
using TestStack.BDDfy;
 | 
			
		||||
using Xunit;
 | 
			
		||||
 | 
			
		||||
@@ -24,10 +25,20 @@ namespace Ocelot.UnitTests.Kubernetes
 | 
			
		||||
        {
 | 
			
		||||
            _configRoot = new ConfigurationRoot(new List<IConfigurationProvider>());
 | 
			
		||||
            _services = new ServiceCollection();
 | 
			
		||||
            _services.AddSingleton<IHostingEnvironment, HostingEnvironment>();
 | 
			
		||||
            _services.AddSingleton<IWebHostEnvironment>(GetHostingEnvironment());
 | 
			
		||||
            _services.AddSingleton(_configRoot);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private IWebHostEnvironment GetHostingEnvironment()
 | 
			
		||||
        {
 | 
			
		||||
            var environment = new Mock<IWebHostEnvironment>();
 | 
			
		||||
            environment
 | 
			
		||||
                .Setup(e => e.ApplicationName)
 | 
			
		||||
                .Returns(typeof(OcelotBuilderExtensionsTests).GetTypeInfo().Assembly.GetName().Name);
 | 
			
		||||
 | 
			
		||||
            return environment.Object;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_set_up_kubernetes()
 | 
			
		||||
        {
 | 
			
		||||
 
 | 
			
		||||
@@ -10,8 +10,8 @@ namespace Ocelot.UnitTests.Logging
 | 
			
		||||
    public class AspDotNetLoggerTests
 | 
			
		||||
    {
 | 
			
		||||
        private readonly Mock<ILogger<object>> _coreLogger;
 | 
			
		||||
        private readonly Mock<IRequestScopedDataRepository> _repo;
 | 
			
		||||
        private readonly AspDotNetLogger _logger;
 | 
			
		||||
        private Mock<IRequestScopedDataRepository> _repo;
 | 
			
		||||
        private readonly string _b;
 | 
			
		||||
        private readonly string _a;
 | 
			
		||||
        private readonly Exception _ex;
 | 
			
		||||
@@ -55,7 +55,7 @@ namespace Ocelot.UnitTests.Logging
 | 
			
		||||
        {
 | 
			
		||||
            _logger.LogError($"a message from {_a} to {_b}", _ex);
 | 
			
		||||
 | 
			
		||||
            ThenLevelIsLogged("requestId: no request id, previousRequestId: no previous request id, message: a message from tom to laura, exception: System.Exception: oh no", LogLevel.Error);
 | 
			
		||||
            ThenLevelIsLogged("requestId: no request id, previousRequestId: no previous request id, message: a message from tom to laura", LogLevel.Error, _ex);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
@@ -63,18 +63,18 @@ namespace Ocelot.UnitTests.Logging
 | 
			
		||||
        {
 | 
			
		||||
            _logger.LogCritical($"a message from {_a} to {_b}", _ex);
 | 
			
		||||
 | 
			
		||||
            ThenLevelIsLogged("requestId: no request id, previousRequestId: no previous request id, message: a message from tom to laura, exception: System.Exception: oh no", LogLevel.Critical);
 | 
			
		||||
            ThenLevelIsLogged("requestId: no request id, previousRequestId: no previous request id, message: a message from tom to laura", LogLevel.Critical, _ex);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void ThenLevelIsLogged(string expected, LogLevel expectedLogLevel)
 | 
			
		||||
        private void ThenLevelIsLogged(string expected, LogLevel expectedLogLevel, Exception ex = null)
 | 
			
		||||
        {
 | 
			
		||||
            _coreLogger.Verify(
 | 
			
		||||
                x => x.Log(
 | 
			
		||||
                    expectedLogLevel,
 | 
			
		||||
                    It.IsAny<EventId>(),
 | 
			
		||||
                    It.Is<object>(o => o.ToString() == expected),
 | 
			
		||||
                    It.IsAny<Exception>(),
 | 
			
		||||
                    It.IsAny<Func<object, Exception, string>>()), Times.Once);
 | 
			
		||||
                    default(EventId),
 | 
			
		||||
                    expected,
 | 
			
		||||
                    ex,
 | 
			
		||||
                    It.IsAny<Func<string, Exception, string>>()), Times.Once);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -4,16 +4,17 @@ using System.Threading.Tasks;
 | 
			
		||||
namespace Ocelot.UnitTests.Middleware
 | 
			
		||||
{
 | 
			
		||||
    using Microsoft.AspNetCore.Hosting;
 | 
			
		||||
    using Microsoft.AspNetCore.Hosting.Internal;
 | 
			
		||||
    using Microsoft.AspNetCore.Http;
 | 
			
		||||
    using Microsoft.Extensions.Configuration;
 | 
			
		||||
    using Microsoft.Extensions.DependencyInjection;
 | 
			
		||||
    using Moq;
 | 
			
		||||
    using Ocelot.DependencyInjection;
 | 
			
		||||
    using Ocelot.Logging;
 | 
			
		||||
    using Ocelot.Middleware;
 | 
			
		||||
    using Ocelot.Middleware.Pipeline;
 | 
			
		||||
    using Shouldly;
 | 
			
		||||
    using System.Collections.Generic;
 | 
			
		||||
    using System.Reflection;
 | 
			
		||||
    using TestStack.BDDfy;
 | 
			
		||||
    using Xunit;
 | 
			
		||||
 | 
			
		||||
@@ -28,11 +29,22 @@ namespace Ocelot.UnitTests.Middleware
 | 
			
		||||
        {
 | 
			
		||||
            _configRoot = new ConfigurationRoot(new List<IConfigurationProvider>());
 | 
			
		||||
            _services = new ServiceCollection();
 | 
			
		||||
            _services.AddSingleton<IHostingEnvironment, HostingEnvironment>();
 | 
			
		||||
            _services.AddSingleton<IWebHostEnvironment>(GetHostingEnvironment());
 | 
			
		||||
            _services.AddSingleton<IConfiguration>(_configRoot);
 | 
			
		||||
            _services.AddOcelot();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        private IWebHostEnvironment GetHostingEnvironment()
 | 
			
		||||
        {
 | 
			
		||||
            var environment = new Mock<IWebHostEnvironment>();
 | 
			
		||||
            environment
 | 
			
		||||
                .Setup(e => e.ApplicationName)
 | 
			
		||||
                .Returns(typeof(OcelotPiplineBuilderTests).GetTypeInfo().Assembly.GetName().Name);
 | 
			
		||||
 | 
			
		||||
            return environment.Object;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_build_generic()
 | 
			
		||||
        {
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,7 @@
 | 
			
		||||
 | 
			
		||||
  <PropertyGroup>
 | 
			
		||||
    <VersionPrefix>0.0.0-dev</VersionPrefix>
 | 
			
		||||
    <TargetFramework>netcoreapp2.2</TargetFramework>
 | 
			
		||||
    <TargetFramework>netcoreapp3.0</TargetFramework>
 | 
			
		||||
    <AssemblyName>Ocelot.UnitTests</AssemblyName>
 | 
			
		||||
    <PackageId>Ocelot.UnitTests</PackageId>
 | 
			
		||||
    <OutputType>Exe</OutputType>
 | 
			
		||||
@@ -46,13 +46,13 @@
 | 
			
		||||
    <None Update="idsrv3test.pfx">
 | 
			
		||||
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
 | 
			
		||||
    </None>
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
  </ItemGroup>  
 | 
			
		||||
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <PackageReference Include="Microsoft.AspNetCore.App" />
 | 
			
		||||
    <PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.2.0" />
 | 
			
		||||
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.0" />
 | 
			
		||||
    <PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
 | 
			
		||||
    <PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
 | 
			
		||||
    <PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.0.0" />
 | 
			
		||||
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
 | 
			
		||||
    <PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.66">
 | 
			
		||||
      <PrivateAssets>all</PrivateAssets>
 | 
			
		||||
    </PackageReference>
 | 
			
		||||
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
 | 
			
		||||
@@ -60,30 +60,38 @@
 | 
			
		||||
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
 | 
			
		||||
    </PackageReference>
 | 
			
		||||
    <PackageReference Include="Microsoft.DotNet.InternalAbstractions" Version="1.0.500-preview2-1-003177" />
 | 
			
		||||
    <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.2.4" />
 | 
			
		||||
    <PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.2.0" />
 | 
			
		||||
    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
 | 
			
		||||
    <PackageReference Include="Microsoft.Extensions.Logging" Version="2.2.0" />
 | 
			
		||||
    <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.2.0" />
 | 
			
		||||
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.2.0" />
 | 
			
		||||
    <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.2.0" />
 | 
			
		||||
    <PackageReference Include="Moq" Version="4.10.1" />
 | 
			
		||||
    <PackageReference Include="Shouldly" Version="3.0.2" />
 | 
			
		||||
    <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="3.0.0" />
 | 
			
		||||
    <PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="3.0.0" />
 | 
			
		||||
    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.0.0" />
 | 
			
		||||
    <PackageReference Include="Microsoft.Extensions.Logging" Version="3.0.0" />
 | 
			
		||||
    <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.0.0" />
 | 
			
		||||
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.0.0" />
 | 
			
		||||
    <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="3.0.0" />
 | 
			
		||||
    <PackageReference Include="Moq" Version="4.13.0" />
 | 
			
		||||
    <PackageReference Include="Shouldly" Version="4.0.0-beta0002" />
 | 
			
		||||
    <PackageReference Include="TestStack.BDDfy" Version="4.3.2" />
 | 
			
		||||
    <PackageReference Include="xunit" Version="2.4.1" />
 | 
			
		||||
    <PackageReference Include="Butterfly.Client.AspNetCore" Version="0.0.8" />
 | 
			
		||||
    <PackageReference Include="IdentityServer4.AccessTokenValidation" Version="2.7.0" />
 | 
			
		||||
    <PackageReference Include="IdentityServer4" Version="2.4.0" />
 | 
			
		||||
    <PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
 | 
			
		||||
    <PackageReference Include="IdentityServer4" Version="3.0.1" />
 | 
			
		||||
    <PackageReference Include="Pivotal.Discovery.ClientCore" Version="2.2.0" />
 | 
			
		||||
    <PackageReference Include="Consul" Version="0.7.2.6" />
 | 
			
		||||
    <PackageReference Include="CacheManager.Core" Version="1.2.0" />
 | 
			
		||||
    <PackageReference Include="CacheManager.Microsoft.Extensions.Configuration" Version="1.2.0" />
 | 
			
		||||
    <PackageReference Include="CacheManager.Microsoft.Extensions.Logging" Version="1.2.0" />
 | 
			
		||||
    <PackageReference Include="Polly" Version="7.1.0" />
 | 
			
		||||
    <PackageReference Include="CacheManager.Core" Version="2.0.0-beta-1629" />
 | 
			
		||||
    <PackageReference Include="CacheManager.Microsoft.Extensions.Configuration" Version="2.0.0-beta-1629" />
 | 
			
		||||
    <PackageReference Include="CacheManager.Microsoft.Extensions.Logging" Version="2.0.0-beta-1629" />
 | 
			
		||||
    <PackageReference Include="Polly" Version="7.1.1" />
 | 
			
		||||
    <PackageReference Include="Rafty" Version="0.4.4" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <Folder Include="WebSockets\" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <PackageReference Update="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-19367-01" />
 | 
			
		||||
    <PackageReference Include="coverlet.collector" Version="1.1.0">
 | 
			
		||||
      <PrivateAssets>all</PrivateAssets>
 | 
			
		||||
      <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
 | 
			
		||||
    </PackageReference>
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
</Project>
 | 
			
		||||
@@ -1,15 +1,16 @@
 | 
			
		||||
namespace Ocelot.UnitTests.Rafty
 | 
			
		||||
{
 | 
			
		||||
    using Microsoft.AspNetCore.Hosting;
 | 
			
		||||
    using Microsoft.AspNetCore.Hosting.Internal;
 | 
			
		||||
    using Microsoft.Extensions.Configuration;
 | 
			
		||||
    using Microsoft.Extensions.DependencyInjection;
 | 
			
		||||
    using Moq;
 | 
			
		||||
    using Ocelot.Administration;
 | 
			
		||||
    using Ocelot.DependencyInjection;
 | 
			
		||||
    using Provider.Rafty;
 | 
			
		||||
    using Shouldly;
 | 
			
		||||
    using System;
 | 
			
		||||
    using System.Collections.Generic;
 | 
			
		||||
    using System.Reflection;
 | 
			
		||||
    using TestStack.BDDfy;
 | 
			
		||||
    using Xunit;
 | 
			
		||||
 | 
			
		||||
@@ -25,10 +26,20 @@
 | 
			
		||||
        {
 | 
			
		||||
            _configRoot = new ConfigurationRoot(new List<IConfigurationProvider>());
 | 
			
		||||
            _services = new ServiceCollection();
 | 
			
		||||
            _services.AddSingleton<IHostingEnvironment, HostingEnvironment>();
 | 
			
		||||
            _services.AddSingleton<IWebHostEnvironment>(GetHostingEnvironment());
 | 
			
		||||
            _services.AddSingleton(_configRoot);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private IWebHostEnvironment GetHostingEnvironment()
 | 
			
		||||
        {
 | 
			
		||||
            var environment = new Mock<IWebHostEnvironment>();
 | 
			
		||||
            environment
 | 
			
		||||
                .Setup(e => e.ApplicationName)
 | 
			
		||||
                .Returns(typeof(OcelotAdministrationBuilderExtensionsTests).GetTypeInfo().Assembly.GetName().Name);
 | 
			
		||||
 | 
			
		||||
            return environment.Object;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_set_up_rafty()
 | 
			
		||||
        {
 | 
			
		||||
 
 | 
			
		||||
@@ -69,7 +69,7 @@ namespace Ocelot.UnitTests.RateLimit
 | 
			
		||||
            this.Given(x => x.GivenTheDownStreamRouteIs(downstreamRoute))
 | 
			
		||||
                .When(x => x.WhenICallTheMiddlewareMultipleTime(2))
 | 
			
		||||
                .Then(x => x.ThenresponseStatusCodeIs200())
 | 
			
		||||
                .When(x => x.WhenICallTheMiddlewareMultipleTime(2))
 | 
			
		||||
                .When(x => x.WhenICallTheMiddlewareMultipleTime(3))
 | 
			
		||||
                .Then(x => x.ThenresponseStatusCodeIs429())
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
@@ -145,8 +145,9 @@ namespace Ocelot.UnitTests.RateLimit
 | 
			
		||||
    internal class FakeStream : Stream
 | 
			
		||||
    {
 | 
			
		||||
        public override void Flush()
 | 
			
		||||
        {
 | 
			
		||||
            throw new System.NotImplementedException();
 | 
			
		||||
        {
 | 
			
		||||
            //do nothing
 | 
			
		||||
            //throw new System.NotImplementedException();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public override int Read(byte[] buffer, int offset, int count)
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,6 @@
 | 
			
		||||
namespace Ocelot.UnitTests.Request.Mapper
 | 
			
		||||
{
 | 
			
		||||
    using Microsoft.AspNetCore.Http;
 | 
			
		||||
    using Microsoft.AspNetCore.Http.Internal;
 | 
			
		||||
    using Microsoft.Extensions.Primitives;
 | 
			
		||||
    using Ocelot.Request.Mapper;
 | 
			
		||||
    using Ocelot.Responses;
 | 
			
		||||
@@ -19,6 +18,7 @@
 | 
			
		||||
 | 
			
		||||
    public class RequestMapperTests
 | 
			
		||||
    {
 | 
			
		||||
        private readonly HttpContext _httpContext;
 | 
			
		||||
        private readonly HttpRequest _inputRequest;
 | 
			
		||||
 | 
			
		||||
        private readonly RequestMapper _requestMapper;
 | 
			
		||||
@@ -29,8 +29,8 @@
 | 
			
		||||
 | 
			
		||||
        public RequestMapperTests()
 | 
			
		||||
        {
 | 
			
		||||
            _inputRequest = new DefaultHttpRequest(new DefaultHttpContext());
 | 
			
		||||
 | 
			
		||||
            _httpContext = new DefaultHttpContext();
 | 
			
		||||
            _inputRequest = _httpContext.Request;
 | 
			
		||||
            _requestMapper = new RequestMapper();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										23
									
								
								test/Ocelot.UnitTests/UnitTests.runsettings
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								test/Ocelot.UnitTests/UnitTests.runsettings
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,23 @@
 | 
			
		||||
<?xml version="1.0" encoding="utf-8" ?>
 | 
			
		||||
<RunSettings>
 | 
			
		||||
  <DataCollectionRunSettings>
 | 
			
		||||
    <DataCollectors>
 | 
			
		||||
      <DataCollector friendlyName="XPlat code coverage">
 | 
			
		||||
        <Configuration>
 | 
			
		||||
          <Format>opencover</Format>
 | 
			
		||||
          <SingleHit>false</SingleHit>
 | 
			
		||||
          <UseSourceLink>true</UseSourceLink>
 | 
			
		||||
        </Configuration>
 | 
			
		||||
      </DataCollector>
 | 
			
		||||
    </DataCollectors>
 | 
			
		||||
  </DataCollectionRunSettings>
 | 
			
		||||
  <!-- This is a workaround for an issue with Coverlet.Collector > 1.0.0 (see https://github.com/microsoft/vstest/issues/2205)-->
 | 
			
		||||
  <InProcDataCollectionRunSettings>
 | 
			
		||||
    <InProcDataCollectors>
 | 
			
		||||
      <InProcDataCollector assemblyQualifiedName="Coverlet.Collector.DataCollection.CoverletInProcDataCollector, coverlet.collector, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null"
 | 
			
		||||
                     friendlyName="XPlat Code Coverage"
 | 
			
		||||
                     enabled="True"
 | 
			
		||||
                     codebase="coverlet.collector.dll" />
 | 
			
		||||
    </InProcDataCollectors>
 | 
			
		||||
  </InProcDataCollectionRunSettings>
 | 
			
		||||
</RunSettings>
 | 
			
		||||
		Reference in New Issue
	
	Block a user