Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get the correct type of page model. #8107

Merged
merged 1 commit into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private bool ShouldSaveAudit(PageHandlerExecutingContext context, out AuditLogIn
auditLog = auditLogScope.Log;
auditLogAction = auditingHelper.CreateAuditLogAction(
auditLog,
context.HandlerMethod.GetType(),
context.HandlerMethod.MethodInfo.DeclaringType,
context.HandlerMethod.MethodInfo,
context.HandlerArguments
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ public AuditTestController(IOptions<AbpAuditingOptions> options)
_options = options.Value;
}

[HttpGet]
public IActionResult Get()
{
return Ok();
}

[Route("audit-success")]
public IActionResult AuditSuccessForGetRequests()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
Expand Down Expand Up @@ -28,6 +29,17 @@ protected override void ConfigureServices(HostBuilderContext context, IServiceCo
base.ConfigureServices(context, services);
}

[Fact]
public async Task Should_Get_Correct_ServiceName_And_MethodName()
{
_options.IsEnabledForGetRequests = true;
_options.AlwaysLogOnException = false;
await GetResponseAsync("/api/audit-test/");
await _auditingStore.Received().SaveAsync(Arg.Is<AuditLogInfo>(x =>
x.Actions.Any(a => a.ServiceName == typeof(AuditTestController).FullName) &&
x.Actions.Any(a => a.MethodName == nameof(AuditTestController.Get))));
}

[Fact]
public async Task Should_Trigger_Middleware_And_AuditLog_Success_For_GetRequests()
{
Expand All @@ -51,7 +63,7 @@ public async Task Should_Trigger_Middleware_And_AuditLog_Exception_Always()

await _auditingStore.Received().SaveAsync(Arg.Any<AuditLogInfo>());
}

[Fact]
public async Task Should_Trigger_Middleware_And_AuditLog_Exception_When_Returns_Object()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public AuditTestPage(IOptions<AbpAuditingOptions> options)
_options = options.Value;
}

public void OnGet()
{

}

public IActionResult OnGetAuditSuccessForGetRequests()
{
return new OkResult();
Expand All @@ -30,4 +35,4 @@ public ObjectResult OnGetAuditFailForGetRequestsReturningObject()
throw new UserFriendlyException("Exception occurred!");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
Expand Down Expand Up @@ -27,6 +28,17 @@ protected override void ConfigureServices(HostBuilderContext context, IServiceCo
base.ConfigureServices(context, services);
}

[Fact]
public async Task Should_Get_Correct_ServiceName_And_MethodName()
{
_options.IsEnabledForGetRequests = true;
_options.AlwaysLogOnException = false;
await GetResponseAsync("/Auditing/AuditTestPage");
await _auditingStore.Received().SaveAsync(Arg.Is<AuditLogInfo>(x =>
x.Actions.Any(a => a.ServiceName == typeof(AuditTestPage).FullName) &&
x.Actions.Any(a => a.MethodName == nameof(AuditTestPage.OnGet))));
}

[Fact]
public async Task Should_Trigger_Middleware_And_AuditLog_Success_For_GetRequests()
{
Expand All @@ -50,7 +62,7 @@ public async Task Should_Trigger_Middleware_And_AuditLog_Exception_Always()

await _auditingStore.Received().SaveAsync(Arg.Any<AuditLogInfo>());
}

[Fact]
public async Task Should_Trigger_Middleware_And_AuditLog_Exception_When_Returns_Object()
{
Expand All @@ -62,4 +74,4 @@ public async Task Should_Trigger_Middleware_And_AuditLog_Exception_When_Returns_
await _auditingStore.Received().SaveAsync(Arg.Any<AuditLogInfo>());
}
}
}
}