mirror of https://github.com/abpframework/abp.git
16 changed files with 167 additions and 18 deletions
@ -0,0 +1,7 @@ |
|||||
|
namespace Volo.Abp.AspNetCore; |
||||
|
|
||||
|
public static class AbpAspNetCoreConsts |
||||
|
{ |
||||
|
public const string DefaultApiPrefix = "api"; |
||||
|
public const string DefaultIntegrationServiceApiPrefix = "integration-api"; |
||||
|
} |
||||
@ -1,6 +1,6 @@ |
|||||
using System; |
using System; |
||||
|
|
||||
namespace Volo.Abp.Application.Services; |
namespace Volo.Abp; |
||||
|
|
||||
[AttributeUsage(AttributeTargets.Class)] |
[AttributeUsage(AttributeTargets.Class)] |
||||
public class IntegrationServiceAttribute : Attribute |
public class IntegrationServiceAttribute : Attribute |
||||
@ -0,0 +1,14 @@ |
|||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.Auditing; |
||||
|
|
||||
|
[Route("integration-api/audit-test")] |
||||
|
[IntegrationService] |
||||
|
public class AuditIntegrationServiceTestController : AbpController |
||||
|
{ |
||||
|
[HttpGet] |
||||
|
public IActionResult Get() |
||||
|
{ |
||||
|
return Ok(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,58 @@ |
|||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.DependencyInjection.Extensions; |
||||
|
using Microsoft.Extensions.Hosting; |
||||
|
using Microsoft.Extensions.Options; |
||||
|
using NSubstitute; |
||||
|
using Shouldly; |
||||
|
using Volo.Abp.Auditing; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.Auditing; |
||||
|
|
||||
|
public class AuditIntegrationServiceTestController_Tests : AspNetCoreMvcTestBase |
||||
|
{ |
||||
|
private readonly AbpAuditingOptions _options; |
||||
|
private IAuditingStore _auditingStore; |
||||
|
|
||||
|
public AuditIntegrationServiceTestController_Tests() |
||||
|
{ |
||||
|
_options = ServiceProvider.GetRequiredService<IOptions<AbpAuditingOptions>>().Value; |
||||
|
_auditingStore = ServiceProvider.GetRequiredService<IAuditingStore>(); |
||||
|
} |
||||
|
|
||||
|
protected override void ConfigureServices(HostBuilderContext context, IServiceCollection services) |
||||
|
{ |
||||
|
_auditingStore = Substitute.For<IAuditingStore>(); |
||||
|
services.Replace(ServiceDescriptor.Singleton(_auditingStore)); |
||||
|
base.ConfigureServices(context, services); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task Should_Write_Audit_Log_For_Controllers_With_IntegrationService_Attribute_If_IsEnabledForIntegrationServices() |
||||
|
{ |
||||
|
_options.IsEnabledForGetRequests = true; |
||||
|
_options.IsEnabledForIntegrationServices = true; |
||||
|
await GetResponseAsync("/integration-api/audit-test/"); |
||||
|
await _auditingStore |
||||
|
.Received() |
||||
|
.SaveAsync( |
||||
|
Arg.Is<AuditLogInfo>( |
||||
|
x => x.Actions.Any( |
||||
|
a => |
||||
|
a.MethodName == nameof(AuditIntegrationServiceTestController.Get) && |
||||
|
a.ServiceName == typeof(AuditIntegrationServiceTestController).FullName |
||||
|
) |
||||
|
) |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task Should_Not_Write_Audit_Log_For_Controllers_With_IntegrationService_Attribute() |
||||
|
{ |
||||
|
_options.IsEnabledForGetRequests = true; |
||||
|
await GetResponseAsync("/integration-api/audit-test/"); |
||||
|
await _auditingStore.DidNotReceive().SaveAsync(Arg.Any<AuditLogInfo>()); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue