mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 17:08:15 +08:00
[WIP] use HttpContext.RequestAborted to support cancel a request (#902)
* use HttpContext.RequestAborted to support cancel a request * register context.HttpContext.RequestAborted.ThrowIfCancellationRequested() in ExceptionHandlerMiddleware * add LangVersion * add default number to OcelotErrorCode fix unit test * revert back to one line
This commit is contained in:

committed by
Thiago Loureiro

parent
fe3cf44c45
commit
4476f8273e
@ -30,6 +30,14 @@
|
||||
error.ShouldBeOfType<UnableToCompleteRequestError>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_return_request_canceled()
|
||||
{
|
||||
var error = _mapper.Map(new OperationCanceledException());
|
||||
|
||||
error.ShouldBeOfType<RequestCanceledError>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_return_error_from_mapper()
|
||||
{
|
||||
|
@ -1,9 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using Ocelot.Errors;
|
||||
using Ocelot.Errors;
|
||||
using Ocelot.Responder;
|
||||
using Shouldly;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
@ -32,7 +32,7 @@ namespace Ocelot.UnitTests.Responder
|
||||
[InlineData(OcelotErrorCode.ClaimValueNotAuthorisedError)]
|
||||
[InlineData(OcelotErrorCode.ScopeNotAuthorisedError)]
|
||||
[InlineData(OcelotErrorCode.UnauthorizedError)]
|
||||
[InlineData(OcelotErrorCode.UserDoesNotHaveClaimError)]
|
||||
[InlineData(OcelotErrorCode.UserDoesNotHaveClaimError)]
|
||||
public void should_return_forbidden(OcelotErrorCode errorCode)
|
||||
{
|
||||
ShouldMapErrorToStatusCode(errorCode, HttpStatusCode.Forbidden);
|
||||
@ -125,7 +125,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(37, "Looks like the number of error codes has changed. Do you need to modify ErrorsToHttpStatusCodeMapper?");
|
||||
Enum.GetNames(typeof(OcelotErrorCode)).Length.ShouldBe(38, "Looks like the number of error codes has changed. Do you need to modify ErrorsToHttpStatusCodeMapper?");
|
||||
}
|
||||
|
||||
private void ShouldMapErrorToStatusCode(OcelotErrorCode errorCode, HttpStatusCode expectedHttpStatusCode)
|
||||
@ -137,7 +137,7 @@ namespace Ocelot.UnitTests.Responder
|
||||
{
|
||||
var errors = new List<Error>();
|
||||
|
||||
foreach(var errorCode in errorCodes)
|
||||
foreach (var errorCode in errorCodes)
|
||||
{
|
||||
errors.Add(new AnyError(errorCode));
|
||||
}
|
||||
@ -168,4 +168,4 @@ namespace Ocelot.UnitTests.Responder
|
||||
_result.ShouldBe((int)expectedCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user