Updated AuditingMidware exception check and new test

pull/2844/head
Galip Tolga Erdem 6 years ago
parent 398146bb47
commit a341528aa6

@ -1,4 +1,5 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Options;
@ -34,6 +35,10 @@ namespace Volo.Abp.AspNetCore.Auditing
try
{
await next(context);
if (_auditingManager.Current.Log.Exceptions.Any())
{
hasError = true;
}
}
catch (Exception)
{

@ -26,5 +26,10 @@ namespace Volo.Abp.AspNetCore.Mvc.Auditing
{
throw new UserFriendlyException("Exception occurred!");
}
[Route("audit-fail-object")]
public object AuditFailForGetRequestsReturningObject()
{
throw new UserFriendlyException("Exception occurred!");
}
}
}

@ -34,7 +34,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Auditing
_options.IsEnabledForGetRequests = true;
_options.AlwaysLogOnException = false;
await GetResponseAsync("api/audit-test/audit-success");
await _auditingStore.Received().SaveAsync(Arg.Any<AuditLogInfo>()); //Won't work, save happens out of scope
await _auditingStore.Received().SaveAsync(Arg.Any<AuditLogInfo>());
}
[Fact]
@ -49,7 +49,17 @@ namespace Volo.Abp.AspNetCore.Mvc.Auditing
}
catch { }
await _auditingStore.Received().SaveAsync(Arg.Any<AuditLogInfo>()); //Won't work, save happens out of scope
await _auditingStore.Received().SaveAsync(Arg.Any<AuditLogInfo>());
}
[Fact]
public async Task Should_Trigger_Middleware_And_AuditLog_Exception_When_Returns_Object()
{
_options.IsEnabled = true;
_options.AlwaysLogOnException = true;
await GetResponseAsync("api/audit-test/audit-fail-object", System.Net.HttpStatusCode.Forbidden);
await _auditingStore.Received().SaveAsync(Arg.Any<AuditLogInfo>());
}
}
}

Loading…
Cancel
Save