mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-05-02 22:42:50 +08:00

* Make rate-limiting client whitelist dynamic * Refactor `RateLimitOptions.ClientWhiteList` * Fix typo in variable `enbleRateLimiting` * Fix case in variable `clientIdheader` author Taiwo Otubamowo <totubamowo@deloitte.co.uk> * fix 1045 * #492 log 500 with error log level, acceptance test, unit test * #492 minor changes * initial commit for new feature #1077 allow to limit the number of concurrent tcp connection to a downstream service * protect code against value not in accurate range add unit test * Do not crash host on Dispose * Add test * Pin GitVersion.CommandLine package version * #683 validate if there are duplicated placeholders in UpstreamPathTemplate * Use registered scheme from Eureka (#1087) * extra test * very brief mention MaxConnectionsPerServer in docs * build develop like a PR * more docs * test Co-authored-by: Taiwo O. <44668623+totubamowo@users.noreply.github.com> Co-authored-by: Catcher Wong <catcher_hwq@outlook.com> Co-authored-by: jlukawska <56401969+jlukawska@users.noreply.github.com> Co-authored-by: buretjph <58700930+buretjph@users.noreply.github.com> Co-authored-by: Jonathan Mezach <jonathanmezach@gmail.com> Co-authored-by: 彭伟 <pengweiqhca@sina.com>
72 lines
2.0 KiB
C#
72 lines
2.0 KiB
C#
namespace Ocelot.UnitTests.Requester
|
|
{
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Ocelot.Errors;
|
|
using Ocelot.Requester;
|
|
using Responder;
|
|
using Shouldly;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
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_request_canceled()
|
|
{
|
|
var error = _mapper.Map(new OperationCanceledException());
|
|
|
|
error.ShouldBeOfType<RequestCanceledError>();
|
|
}
|
|
|
|
[Fact]
|
|
public void should_return_request_canceled_for_subtype()
|
|
{
|
|
var error = _mapper.Map(new SomeException());
|
|
|
|
error.ShouldBeOfType<RequestCanceledError>();
|
|
}
|
|
|
|
[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>();
|
|
}
|
|
|
|
private class SomeException : OperationCanceledException
|
|
{ }
|
|
}
|
|
}
|