allow to add delegating handlers by type (#943)

This commit is contained in:
Marcelo Castagna
2019-07-01 08:23:06 -03:00
committed by GitHub
parent c08f873dab
commit 176a7bb960
3 changed files with 58 additions and 0 deletions

View File

@ -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();