mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 17:40:50 +08:00 
			
		
		
		
	Merge branch 'awarrenlove-ocelot-builder-lifetimes' into develop
This commit is contained in:
		@@ -5,12 +5,15 @@ using System.Net.Http;
 | 
				
			|||||||
using System.Text;
 | 
					using System.Text;
 | 
				
			||||||
using CacheManager.Core;
 | 
					using CacheManager.Core;
 | 
				
			||||||
using Microsoft.AspNetCore.Hosting;
 | 
					using Microsoft.AspNetCore.Hosting;
 | 
				
			||||||
 | 
					using Microsoft.AspNetCore.Hosting.Internal;
 | 
				
			||||||
using Microsoft.Extensions.Configuration;
 | 
					using Microsoft.Extensions.Configuration;
 | 
				
			||||||
using Microsoft.Extensions.DependencyInjection;
 | 
					using Microsoft.Extensions.DependencyInjection;
 | 
				
			||||||
using Ocelot.Cache;
 | 
					using Ocelot.Cache;
 | 
				
			||||||
using Ocelot.Configuration;
 | 
					using Ocelot.Configuration;
 | 
				
			||||||
using Ocelot.Configuration.File;
 | 
					using Ocelot.Configuration.File;
 | 
				
			||||||
 | 
					using Ocelot.Configuration.Setter;
 | 
				
			||||||
using Ocelot.DependencyInjection;
 | 
					using Ocelot.DependencyInjection;
 | 
				
			||||||
 | 
					using Ocelot.Logging;
 | 
				
			||||||
using Shouldly;
 | 
					using Shouldly;
 | 
				
			||||||
using TestStack.BDDfy;
 | 
					using TestStack.BDDfy;
 | 
				
			||||||
using Xunit;
 | 
					using Xunit;
 | 
				
			||||||
@@ -20,6 +23,7 @@ namespace Ocelot.UnitTests.DependencyInjection
 | 
				
			|||||||
    public class OcelotBuilderTests
 | 
					    public class OcelotBuilderTests
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        private IServiceCollection _services;
 | 
					        private IServiceCollection _services;
 | 
				
			||||||
 | 
					        private IServiceProvider _serviceProvider;
 | 
				
			||||||
        private IConfigurationRoot _configRoot;
 | 
					        private IConfigurationRoot _configRoot;
 | 
				
			||||||
        private IOcelotBuilder _ocelotBuilder;
 | 
					        private IOcelotBuilder _ocelotBuilder;
 | 
				
			||||||
        private int _maxRetries;
 | 
					        private int _maxRetries;
 | 
				
			||||||
@@ -30,6 +34,7 @@ namespace Ocelot.UnitTests.DependencyInjection
 | 
				
			|||||||
                _configRoot = new ConfigurationRoot(new List<IConfigurationProvider>());
 | 
					                _configRoot = new ConfigurationRoot(new List<IConfigurationProvider>());
 | 
				
			||||||
                _services = new ServiceCollection();
 | 
					                _services = new ServiceCollection();
 | 
				
			||||||
                _services.AddSingleton(builder);
 | 
					                _services.AddSingleton(builder);
 | 
				
			||||||
 | 
					                _services.AddSingleton<IHostingEnvironment, HostingEnvironment>();
 | 
				
			||||||
                _maxRetries = 100;
 | 
					                _maxRetries = 100;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        private Exception _ex;
 | 
					        private Exception _ex;
 | 
				
			||||||
@@ -70,6 +75,16 @@ namespace Ocelot.UnitTests.DependencyInjection
 | 
				
			|||||||
                .BDDfy();
 | 
					                .BDDfy();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        [Fact]
 | 
				
			||||||
 | 
					        public void should_use_logger_factory()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            this.Given(x => WhenISetUpOcelotServices())
 | 
				
			||||||
 | 
					                .When(x => WhenIValidateScopes())
 | 
				
			||||||
 | 
					                .When(x => WhenIAccessLoggerFactory())
 | 
				
			||||||
 | 
					                .Then(x => ThenAnExceptionIsntThrown())
 | 
				
			||||||
 | 
					                .BDDfy();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private void OnlyOneVersionOfEachCacheIsRegistered()
 | 
					        private void OnlyOneVersionOfEachCacheIsRegistered()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            var outputCache = _services.Single(x => x.ServiceType == typeof(IOcelotCache<CachedResponse>));
 | 
					            var outputCache = _services.Single(x => x.ServiceType == typeof(IOcelotCache<CachedResponse>));
 | 
				
			||||||
@@ -127,6 +142,30 @@ namespace Ocelot.UnitTests.DependencyInjection
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        private void WhenIAccessLoggerFactory()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            try
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                var logger = _serviceProvider.GetService<IFileConfigurationSetter>();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            catch (Exception e)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                _ex = e;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        private void WhenIValidateScopes()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            try
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                _serviceProvider = _services.BuildServiceProvider(new ServiceProviderOptions { ValidateScopes = true });
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            catch (Exception e)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                _ex = e;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private void ThenAnExceptionIsntThrown()
 | 
					        private void ThenAnExceptionIsntThrown()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            _ex.ShouldBeNull();
 | 
					            _ex.ShouldBeNull();
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user