mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 00:38:16 +08:00
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:
@ -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>();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user