mirror of https://github.com/abpframework/abp.git
committed by
GitHub
5 changed files with 135 additions and 2 deletions
@ -0,0 +1,14 @@ |
|||||
|
using System; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Controllers; |
||||
|
|
||||
|
[AttributeUsage(AttributeTargets.Class)] |
||||
|
public class ReplaceControllersAttribute : Attribute |
||||
|
{ |
||||
|
public Type[] ControllerTypes { get; } |
||||
|
|
||||
|
public ReplaceControllersAttribute(params Type[] controllerTypes) |
||||
|
{ |
||||
|
ControllerTypes = controllerTypes ?? Type.EmptyTypes; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,50 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using Volo.Abp.AspNetCore.Controllers; |
||||
|
using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.Controllers; |
||||
|
|
||||
|
[Area("abp")] |
||||
|
[RemoteService(Name = "abp")] |
||||
|
[ReplaceControllers(typeof(AbpApplicationConfigurationController), typeof(AbpApplicationLocalizationController))] |
||||
|
public class ReplaceBuiltInController : AbpController |
||||
|
{ |
||||
|
[HttpGet("api/abp/application-configuration")] |
||||
|
public virtual Task<MyApplicationConfigurationDto> GetAsync(MyApplicationConfigurationRequestOptions options) |
||||
|
{ |
||||
|
return Task.FromResult(new MyApplicationConfigurationDto() |
||||
|
{ |
||||
|
Random = options.Random |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
[HttpGet("api/abp/application-localization")] |
||||
|
public virtual Task<MyApplicationLocalizationDto> GetAsync(MyApplicationLocalizationRequestDto input) |
||||
|
{ |
||||
|
return Task.FromResult(new MyApplicationLocalizationDto() |
||||
|
{ |
||||
|
Random = input.Random |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public class MyApplicationConfigurationRequestOptions : ApplicationConfigurationRequestOptions |
||||
|
{ |
||||
|
public string Random { get; set; } |
||||
|
} |
||||
|
|
||||
|
public class MyApplicationConfigurationDto : ApplicationConfigurationDto |
||||
|
{ |
||||
|
public string Random { get; set; } |
||||
|
} |
||||
|
|
||||
|
public class MyApplicationLocalizationRequestDto : ApplicationLocalizationRequestDto |
||||
|
{ |
||||
|
public string Random { get; set; } |
||||
|
} |
||||
|
|
||||
|
public class MyApplicationLocalizationDto : ApplicationLocalizationDto |
||||
|
{ |
||||
|
public string Random { get; set; } |
||||
|
} |
||||
@ -0,0 +1,32 @@ |
|||||
|
using System; |
||||
|
using System.Net; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.Hosting; |
||||
|
using Shouldly; |
||||
|
using Volo.Abp.AspNetCore.Mvc.Localization; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.Controllers; |
||||
|
|
||||
|
public class ReplaceBuiltInController_Tests : AspNetCoreMvcTestBase |
||||
|
{ |
||||
|
protected override void ConfigureServices(HostBuilderContext context, IServiceCollection services) |
||||
|
{ |
||||
|
services.Configure<AbpAspNetCoreMvcOptions>(options => |
||||
|
{ |
||||
|
options.ControllersToRemove.Add(typeof(AbpLanguagesController)); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task Test() |
||||
|
{ |
||||
|
var random = Guid.NewGuid().ToString("N"); |
||||
|
|
||||
|
(await GetResponseAsObjectAsync<MyApplicationConfigurationDto>("api/abp/application-configuration?random=" + random)).Random.ShouldBe(random); |
||||
|
(await GetResponseAsObjectAsync<MyApplicationLocalizationDto>("api/abp/application-localization?CultureName=en&random=" + random)).Random.ShouldBe(random); |
||||
|
|
||||
|
(await GetResponseAsync("Abp/Languages/Switch", HttpStatusCode.NotFound)).StatusCode.ShouldBe(HttpStatusCode.NotFound); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue