mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 21:08:17 +08:00
tests to handle some error cases and docs
This commit is contained in:
@ -69,7 +69,24 @@ namespace Ocelot.UnitTests.LoadBalancer
|
||||
.Then(x => x.ThenTheLoadBalancerIsReturned<FakeLoadBalancerTwo>())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void should_return_error_response_if_cannot_find_load_balancer_creator()
|
||||
{
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithLoadBalancerOptions(new LoadBalancerOptions("DoesntExistLoadBalancer", "", 0))
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.Build();
|
||||
|
||||
this.Given(x => x.GivenAReRoute(reRoute))
|
||||
.And(x => GivenAServiceProviderConfig(new ServiceProviderConfigurationBuilder().Build()))
|
||||
.And(x => x.GivenTheServiceProviderFactoryReturns())
|
||||
.When(x => x.WhenIGetTheLoadBalancer())
|
||||
.Then(x => x.ThenAnErrorResponseIsReturned())
|
||||
.And(x => x.ThenTheErrorMessageIsCorrect())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_call_service_provider()
|
||||
{
|
||||
@ -147,6 +164,11 @@ namespace Ocelot.UnitTests.LoadBalancer
|
||||
_result.IsError.ShouldBeTrue();
|
||||
}
|
||||
|
||||
private void ThenTheErrorMessageIsCorrect()
|
||||
{
|
||||
_result.Errors[0].Message.ShouldBe("Could not find load balancer creator for Type: DoesntExistLoadBalancer, please check your config specified the correct load balancer and that you have registered a class with the same name.");
|
||||
}
|
||||
|
||||
private class FakeLoadBalancerCreator<T> : ILoadBalancerCreator
|
||||
where T : ILoadBalancer, new()
|
||||
{
|
||||
|
@ -47,6 +47,7 @@ namespace Ocelot.UnitTests.Responder
|
||||
|
||||
[Theory]
|
||||
[InlineData(OcelotErrorCode.UnableToCompleteRequestError)]
|
||||
[InlineData(OcelotErrorCode.CouldNotFindLoadBalancerCreator)]
|
||||
public void should_return_internal_server_error(OcelotErrorCode errorCode)
|
||||
{
|
||||
ShouldMapErrorToStatusCode(errorCode, HttpStatusCode.InternalServerError);
|
||||
@ -120,7 +121,7 @@ namespace Ocelot.UnitTests.Responder
|
||||
var errors = new List<OcelotErrorCode>
|
||||
{
|
||||
OcelotErrorCode.CannotAddDataError,
|
||||
OcelotErrorCode.RequestTimedOutError
|
||||
OcelotErrorCode.RequestTimedOutError,
|
||||
};
|
||||
|
||||
ShouldMapErrorsToStatusCode(errors, HttpStatusCode.ServiceUnavailable);
|
||||
@ -132,7 +133,7 @@ namespace Ocelot.UnitTests.Responder
|
||||
// If this test fails then it's because the number of error codes has changed.
|
||||
// You should make the appropriate changes to the test cases here to ensure
|
||||
// they cover all the error codes, and then modify this assertion.
|
||||
Enum.GetNames(typeof(OcelotErrorCode)).Length.ShouldBe(39, "Looks like the number of error codes has changed. Do you need to modify ErrorsToHttpStatusCodeMapper?");
|
||||
Enum.GetNames(typeof(OcelotErrorCode)).Length.ShouldBe(40, "Looks like the number of error codes has changed. Do you need to modify ErrorsToHttpStatusCodeMapper?");
|
||||
}
|
||||
|
||||
private void ShouldMapErrorToStatusCode(OcelotErrorCode errorCode, HttpStatusCode expectedHttpStatusCode)
|
||||
|
Reference in New Issue
Block a user