mirror of https://github.com/abpframework/abp.git
committed by
GitHub
10 changed files with 449 additions and 315 deletions
@ -1,35 +1,35 @@ |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Microsoft.Extensions.Options; |
|||
using Volo.Abp.Auditing; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.Auditing |
|||
{ |
|||
[Route("api/audit-test")] |
|||
[Audited] |
|||
public class AuditTestController : AbpController |
|||
{ |
|||
private readonly AbpAuditingOptions _options; |
|||
|
|||
public AuditTestController(IOptions<AbpAuditingOptions> options) |
|||
{ |
|||
_options = options.Value; |
|||
} |
|||
|
|||
[Route("audit-success")] |
|||
public IActionResult AuditSuccessForGetRequests() |
|||
{ |
|||
return Ok(); |
|||
} |
|||
|
|||
[Route("audit-fail")] |
|||
public IActionResult AuditFailForGetRequests() |
|||
{ |
|||
throw new UserFriendlyException("Exception occurred!"); |
|||
} |
|||
[Route("audit-fail-object")] |
|||
public object AuditFailForGetRequestsReturningObject() |
|||
{ |
|||
throw new UserFriendlyException("Exception occurred!"); |
|||
} |
|||
} |
|||
} |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Microsoft.Extensions.Options; |
|||
using Volo.Abp.Auditing; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.Auditing |
|||
{ |
|||
[Route("api/audit-test")] |
|||
[Audited] |
|||
public class AuditTestController : AbpController |
|||
{ |
|||
private readonly AbpAuditingOptions _options; |
|||
|
|||
public AuditTestController(IOptions<AbpAuditingOptions> options) |
|||
{ |
|||
_options = options.Value; |
|||
} |
|||
|
|||
[Route("audit-success")] |
|||
public IActionResult AuditSuccessForGetRequests() |
|||
{ |
|||
return Ok(); |
|||
} |
|||
|
|||
[Route("audit-fail")] |
|||
public IActionResult AuditFailForGetRequests() |
|||
{ |
|||
throw new UserFriendlyException("Exception occurred!"); |
|||
} |
|||
[Route("audit-fail-object")] |
|||
public object AuditFailForGetRequestsReturningObject() |
|||
{ |
|||
throw new UserFriendlyException("Exception occurred!"); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,65 +1,65 @@ |
|||
using System; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.DependencyInjection.Extensions; |
|||
using Microsoft.Extensions.Hosting; |
|||
using Microsoft.Extensions.Options; |
|||
using NSubstitute; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Auditing; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.Auditing |
|||
{ |
|||
public class AuditTestController_Tests : AspNetCoreMvcTestBase |
|||
{ |
|||
private readonly AbpAuditingOptions _options; |
|||
private IAuditingStore _auditingStore; |
|||
|
|||
public AuditTestController_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_Trigger_Middleware_And_AuditLog_Success_For_GetRequests() |
|||
{ |
|||
_options.IsEnabledForGetRequests = true; |
|||
_options.AlwaysLogOnException = false; |
|||
await GetResponseAsync("api/audit-test/audit-success"); |
|||
await _auditingStore.Received().SaveAsync(Arg.Any<AuditLogInfo>()); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Trigger_Middleware_And_AuditLog_Exception_Always() |
|||
{ |
|||
_options.IsEnabled = true; |
|||
_options.AlwaysLogOnException = true; |
|||
|
|||
try |
|||
{ |
|||
await GetResponseAsync("api/audit-test/audit-fail", System.Net.HttpStatusCode.Forbidden); |
|||
} |
|||
catch { } |
|||
|
|||
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>()); |
|||
} |
|||
} |
|||
} |
|||
using System; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.DependencyInjection.Extensions; |
|||
using Microsoft.Extensions.Hosting; |
|||
using Microsoft.Extensions.Options; |
|||
using NSubstitute; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Auditing; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.Auditing |
|||
{ |
|||
public class AuditTestController_Tests : AspNetCoreMvcTestBase |
|||
{ |
|||
private readonly AbpAuditingOptions _options; |
|||
private IAuditingStore _auditingStore; |
|||
|
|||
public AuditTestController_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_Trigger_Middleware_And_AuditLog_Success_For_GetRequests() |
|||
{ |
|||
_options.IsEnabledForGetRequests = true; |
|||
_options.AlwaysLogOnException = false; |
|||
await GetResponseAsync("api/audit-test/audit-success"); |
|||
await _auditingStore.Received().SaveAsync(Arg.Any<AuditLogInfo>()); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Trigger_Middleware_And_AuditLog_Exception_Always() |
|||
{ |
|||
_options.IsEnabled = true; |
|||
_options.AlwaysLogOnException = true; |
|||
|
|||
try |
|||
{ |
|||
await GetResponseAsync("api/audit-test/audit-fail", System.Net.HttpStatusCode.Forbidden); |
|||
} |
|||
catch { } |
|||
|
|||
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>()); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,53 @@ |
|||
@using Volo.Docs.Pages.Documents.Shared.DocumentNotFoundComponent |
|||
@model DocumentNotFoundPageModel |
|||
@{ |
|||
} |
|||
<div class="row position-relative vh-100" style="background: #e8e8e8;"> |
|||
<div class="center"> |
|||
<span class="notfound-404">404</span> |
|||
<h1> |
|||
<strong>"@Model.DocumentName"</strong> not found in <strong>@Model.ProjectName</strong> documents, with <strong>@Model.Version</strong> version and <strong>@Model.LanguageCode</strong> language. |
|||
</h1> |
|||
<br /> |
|||
<a href="@(Model.DocumentsUrlPrefix + Model.LanguageCode + "/" +Model.ProjectName + "/" + Model.Version)" class="btn btn-primary px-4"> |
|||
Go Back |
|||
</a> |
|||
</div> |
|||
</div> |
|||
|
|||
|
|||
<style> |
|||
h1 { |
|||
font-size: 1.75em; |
|||
line-height: 1.75; |
|||
color: #777; |
|||
font-weight: normal; |
|||
} |
|||
|
|||
h1 strong { |
|||
color: #222; |
|||
} |
|||
|
|||
.center { |
|||
position: absolute; |
|||
left: 50%; |
|||
top: 50%; |
|||
-webkit-transform: translate(-50%, -50%); |
|||
-ms-transform: translate(-50%, -50%); |
|||
transform: translate(-50%, -50%); |
|||
text-align: center; |
|||
} |
|||
|
|||
.notfound-404 { |
|||
font-size: 300px; |
|||
font-weight: 700; |
|||
line-height: 1.25; |
|||
margin: 0px; |
|||
color: #fff; |
|||
text-transform: uppercase; |
|||
display: block; |
|||
margin-bottom: -150px; |
|||
z-index: -1; |
|||
position: relative; |
|||
} |
|||
</style> |
|||
@ -0,0 +1,15 @@ |
|||
namespace Volo.Docs.Pages.Documents.Shared.DocumentNotFoundComponent |
|||
{ |
|||
public class DocumentNotFoundPageModel |
|||
{ |
|||
public string ProjectName { get; set; } |
|||
|
|||
public string LanguageCode { get; set; } |
|||
|
|||
public string Version { get; set; } |
|||
|
|||
public string DocumentName { get; set; } |
|||
|
|||
public string DocumentsUrlPrefix { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Microsoft.Extensions.Options; |
|||
using Volo.Abp.AspNetCore.Mvc; |
|||
|
|||
namespace Volo.Docs.Pages.Documents.Shared.DocumentNotFoundComponent |
|||
{ |
|||
public class DocumentNotFoundViewComponent : AbpViewComponent |
|||
{ |
|||
private readonly DocsUiOptions _options; |
|||
|
|||
public DocumentNotFoundViewComponent(IOptions<DocsUiOptions> options) |
|||
{ |
|||
_options = options.Value; |
|||
} |
|||
public IViewComponentResult Invoke(DocumentNotFoundPageModel model, string defaultErrorMessageKey) |
|||
{ |
|||
model.DocumentsUrlPrefix = _options.RoutePrefix; |
|||
|
|||
return View("~/Pages/Documents/Shared/DocumentNotFoundComponent/Default.cshtml", model); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue