Feature/inject error mapper (#562)

* added delegate to select last handler

* #529 implemented a way we can inject the last delegating handler

* wip - moving code

* #529 removed loads of qos code and moved it into Ocelot.Provider.Polly

* #529 can now inject http client expcetions to ocelot errors mappers and updated docs
This commit is contained in:
Tom Pallister
2018-08-19 12:57:43 +01:00
committed by GitHub
parent 98ba0271be
commit 6d8b18c01d
13 changed files with 177 additions and 317 deletions

View File

@ -0,0 +1,52 @@
namespace Ocelot.UnitTests.Requester
{
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Ocelot.Errors;
using Ocelot.Requester;
using Responder;
using Shouldly;
using Xunit;
public class HttpExeptionToErrorMapperTests
{
private HttpExeptionToErrorMapper _mapper;
private readonly ServiceCollection _services;
public HttpExeptionToErrorMapperTests()
{
_services = new ServiceCollection();
var provider = _services.BuildServiceProvider();
_mapper = new HttpExeptionToErrorMapper(provider);
}
[Fact]
public void should_return_default_error_because_mappers_are_null()
{
var error = _mapper.Map(new Exception());
error.ShouldBeOfType<UnableToCompleteRequestError>();
}
[Fact]
public void should_return_error_from_mapper()
{
var errorMapping = new Dictionary<Type, Func<Exception, Error>>
{
{typeof(TaskCanceledException), e => new AnyError()},
};
_services.AddSingleton(errorMapping);
var provider = _services.BuildServiceProvider();
_mapper = new HttpExeptionToErrorMapper(provider);
var error = _mapper.Map(new TaskCanceledException());
error.ShouldBeOfType<AnyError>();
}
}
}