Add unit test for view localization.

pull/138/head
Halil İbrahim Kalkan 7 years ago
parent aedc1d63c6
commit d34a04adfd

@ -0,0 +1,13 @@
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;
namespace Volo.Abp.AspNetCore.App
{
public class LocalizationTestController : AbpController
{
public IActionResult Index1()
{
return View();
}
}
}

@ -0,0 +1,3 @@
@using Microsoft.AspNetCore.Mvc.Localization
@inject IViewLocalizer Localizer
@Localizer["Hello <b>{0}</b>.", "John"]

@ -1,5 +0,0 @@
@using Volo.Abp.Ui
<h2>Exception test</h2>
@{
throw new UserFriendlyException("test exception!");
}

@ -21,7 +21,7 @@ namespace Volo.Abp.AspNetCore.Mvc
public override void ConfigureServices(IServiceCollection services)
{
services.AddLocalization(); //TODO: Move to AbpAspNetCoreMvcModule
services.AddMvc(); //TODO: Move to AbpAspNetCoreMvcModule
services.AddMvc().AddViewLocalization(); //TODO: Move to AbpAspNetCoreMvcModule
services.Configure<AbpAspNetCoreMvcOptions>(options =>
{

@ -1,4 +1,5 @@
using Microsoft.Extensions.DependencyInjection;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;
using Shouldly;
using Xunit;
@ -15,11 +16,18 @@ namespace Volo.Abp.AspNetCore.Mvc.Localization
}
[Fact]
public void Should_Get_Same_Text_If_Not_Defined()
public void Should_Get_Same_Text_If_Not_Defined_From_StringLocalizer()
{
const string text = "A string that is not defined!";
_localizer[text].Value.ShouldBe(text);
}
[Fact]
public async Task Should_Get_Same_Text_If_Not_Defined_In_Razor_View()
{
var result = await GetResponseAsStringAsync("/LocalizationTest/Index1");
result.ShouldBe("Hello <b>John</b>.");
}
}
}

Loading…
Cancel
Save