mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 08:55:28 +08:00 
			
		
		
		
	allow to add delegating handlers by type (#943)
This commit is contained in:
		@@ -47,6 +47,17 @@ namespace Ocelot.UnitTests.DependencyInjection
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_add_type_specific_delegating_handlers_transient()
 | 
			
		||||
        {
 | 
			
		||||
            this.Given(x => WhenISetUpOcelotServices())
 | 
			
		||||
                .When(x => AddTypeSpecificTransientDelegatingHandler(typeof(FakeDelegatingHandler)))
 | 
			
		||||
                .And(x => AddTypeSpecificTransientDelegatingHandler(typeof(FakeDelegatingHandlerTwo)))
 | 
			
		||||
                .Then(x => ThenTheProviderIsRegisteredAndReturnsSpecificHandlers<FakeDelegatingHandler, FakeDelegatingHandlerTwo>())
 | 
			
		||||
                .And(x => ThenTheSpecificHandlersAreTransient())
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_add_global_delegating_handlers_transient()
 | 
			
		||||
        {
 | 
			
		||||
@@ -58,6 +69,17 @@ namespace Ocelot.UnitTests.DependencyInjection
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_add_global_type_delegating_handlers_transient()
 | 
			
		||||
        {
 | 
			
		||||
            this.Given(x => WhenISetUpOcelotServices())
 | 
			
		||||
                .When(x => AddTransientGlobalDelegatingHandler<FakeDelegatingHandler>())
 | 
			
		||||
                .And(x => AddTransientGlobalDelegatingHandler<FakeDelegatingHandlerTwo>())
 | 
			
		||||
                .Then(x => ThenTheProviderIsRegisteredAndReturnsHandlers<FakeDelegatingHandler, FakeDelegatingHandlerTwo>())
 | 
			
		||||
                .And(x => ThenTheGlobalHandlersAreTransient())
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_set_up_services()
 | 
			
		||||
        {
 | 
			
		||||
@@ -156,6 +178,16 @@ namespace Ocelot.UnitTests.DependencyInjection
 | 
			
		||||
            _ocelotBuilder.AddDelegatingHandler<T>();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void AddTypeTransientGlobalDelegatingHandler(Type type)
 | 
			
		||||
        {
 | 
			
		||||
            _ocelotBuilder.AddDelegatingHandler(type, true);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void AddTypeSpecificTransientDelegatingHandler(Type type)
 | 
			
		||||
        {
 | 
			
		||||
            _ocelotBuilder.AddDelegatingHandler(type);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void ThenTheProviderIsRegisteredAndReturnsHandlers<TOne, TWo>()
 | 
			
		||||
        {
 | 
			
		||||
            _serviceProvider = _services.BuildServiceProvider();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user