|
|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
@ -24,15 +24,33 @@ namespace Volo.Abp.AspNetCore.Mvc.ExceptionHandling
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task Should_Return_RemoteServiceErrorResponse_For_UserFriendlyException_For_Void_Return_Value()
|
|
|
|
|
public async Task Should_Not_Handle_Exceptions_For_Void_Return_Values()
|
|
|
|
|
{
|
|
|
|
|
var result = await GetResponseAsObjectAsync<RemoteServiceErrorResponse>("/ExceptionHandling/ExceptionTestPage?handler=UserFriendlyException1", HttpStatusCode.Forbidden);
|
|
|
|
|
result.Error.ShouldNotBeNull();
|
|
|
|
|
result.Error.Message.ShouldBe("This is a sample exception!");
|
|
|
|
|
await Assert.ThrowsAsync<UserFriendlyException>(
|
|
|
|
|
async () => await GetResponseAsStringAsync(
|
|
|
|
|
"/ExceptionHandling/ExceptionTestPage?handler=UserFriendlyException_Void"
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
#pragma warning disable 4014
|
|
|
|
|
_fakeExceptionSubscriber
|
|
|
|
|
.Received()
|
|
|
|
|
.DidNotReceive()
|
|
|
|
|
.HandleAsync(Arg.Any<ExceptionNotificationContext>());
|
|
|
|
|
#pragma warning restore 4014
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task Should_Not_Handle_Exceptions_For_Task_Return_Values()
|
|
|
|
|
{
|
|
|
|
|
await Assert.ThrowsAsync<UserFriendlyException>(
|
|
|
|
|
async () => await GetResponseAsStringAsync(
|
|
|
|
|
"/ExceptionHandling/ExceptionTestPage?handler=UserFriendlyException_Task"
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
#pragma warning disable 4014
|
|
|
|
|
_fakeExceptionSubscriber
|
|
|
|
|
.DidNotReceive()
|
|
|
|
|
.HandleAsync(Arg.Any<ExceptionNotificationContext>());
|
|
|
|
|
#pragma warning restore 4014
|
|
|
|
|
}
|
|
|
|
|
@ -41,8 +59,8 @@ namespace Volo.Abp.AspNetCore.Mvc.ExceptionHandling
|
|
|
|
|
public async Task Should_Not_Handle_Exceptions_For_ActionResult_Return_Values()
|
|
|
|
|
{
|
|
|
|
|
await Assert.ThrowsAsync<UserFriendlyException>(
|
|
|
|
|
async () => await GetResponseAsObjectAsync<RemoteServiceErrorResponse>(
|
|
|
|
|
"/ExceptionHandling/ExceptionTestPage?handler=UserFriendlyException2"
|
|
|
|
|
async () => await GetResponseAsStringAsync(
|
|
|
|
|
"/ExceptionHandling/ExceptionTestPage?handler=UserFriendlyException_ActionResult"
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
@ -50,7 +68,35 @@ namespace Volo.Abp.AspNetCore.Mvc.ExceptionHandling
|
|
|
|
|
_fakeExceptionSubscriber
|
|
|
|
|
.DidNotReceive()
|
|
|
|
|
.HandleAsync(Arg.Any<ExceptionNotificationContext>());
|
|
|
|
|
#pragma warning restore 4014
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task Should_Return_RemoteServiceErrorResponse_For_UserFriendlyException_For_Object_Return_Value()
|
|
|
|
|
{
|
|
|
|
|
var result = await GetResponseAsObjectAsync<RemoteServiceErrorResponse>("/ExceptionHandling/ExceptionTestPage?handler=UserFriendlyException_JsonResult", HttpStatusCode.Forbidden);
|
|
|
|
|
result.Error.ShouldNotBeNull();
|
|
|
|
|
result.Error.Message.ShouldBe("This is a sample exception!");
|
|
|
|
|
|
|
|
|
|
#pragma warning disable 4014
|
|
|
|
|
_fakeExceptionSubscriber
|
|
|
|
|
.Received()
|
|
|
|
|
.HandleAsync(Arg.Any<ExceptionNotificationContext>());
|
|
|
|
|
#pragma warning restore 4014
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task Should_Return_RemoteServiceErrorResponse_For_UserFriendlyException_For_Task_Object_Return_Value()
|
|
|
|
|
{
|
|
|
|
|
var result = await GetResponseAsObjectAsync<RemoteServiceErrorResponse>("/ExceptionHandling/ExceptionTestPage?handler=UserFriendlyException_Task_JsonResult", HttpStatusCode.Forbidden);
|
|
|
|
|
result.Error.ShouldNotBeNull();
|
|
|
|
|
result.Error.Message.ShouldBe("This is a sample exception!");
|
|
|
|
|
|
|
|
|
|
#pragma warning disable 4014
|
|
|
|
|
_fakeExceptionSubscriber
|
|
|
|
|
.Received()
|
|
|
|
|
.HandleAsync(Arg.Any<ExceptionNotificationContext>());
|
|
|
|
|
#pragma warning restore 4014
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|