From d34a04adfd2aa45f9c4658e910640a75badaeb40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sun, 15 Oct 2017 16:14:51 +0300 Subject: [PATCH] Add unit test for view localization. --- .../AspNetCore/App/LocalizationTestController.cs | 13 +++++++++++++ .../App/Views/LocalizationTest/Index1.cshtml | 3 +++ .../App/Views/Simple/ExceptionOnRazor.cshtml | 5 ----- .../AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs | 2 +- .../Mvc/Localization/MvcLocalization_Tests.cs | 12 ++++++++++-- 5 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/LocalizationTestController.cs create mode 100644 test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/Views/LocalizationTest/Index1.cshtml delete mode 100644 test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/Views/Simple/ExceptionOnRazor.cshtml diff --git a/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/LocalizationTestController.cs b/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/LocalizationTestController.cs new file mode 100644 index 0000000000..5404746dc5 --- /dev/null +++ b/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/LocalizationTestController.cs @@ -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(); + } + } +} diff --git a/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/Views/LocalizationTest/Index1.cshtml b/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/Views/LocalizationTest/Index1.cshtml new file mode 100644 index 0000000000..ae2122e4f3 --- /dev/null +++ b/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/Views/LocalizationTest/Index1.cshtml @@ -0,0 +1,3 @@ +@using Microsoft.AspNetCore.Mvc.Localization +@inject IViewLocalizer Localizer +@Localizer["Hello {0}.", "John"] \ No newline at end of file diff --git a/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/Views/Simple/ExceptionOnRazor.cshtml b/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/Views/Simple/ExceptionOnRazor.cshtml deleted file mode 100644 index 3a529fbf1f..0000000000 --- a/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/Views/Simple/ExceptionOnRazor.cshtml +++ /dev/null @@ -1,5 +0,0 @@ -@using Volo.Abp.Ui -

Exception test

-@{ - throw new UserFriendlyException("test exception!"); -} \ No newline at end of file diff --git a/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs b/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs index 4f8bc25beb..6e3bc29da5 100644 --- a/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs +++ b/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs @@ -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(options => { diff --git a/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Localization/MvcLocalization_Tests.cs b/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Localization/MvcLocalization_Tests.cs index 59d9bcbac4..8b16cfe8ed 100644 --- a/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Localization/MvcLocalization_Tests.cs +++ b/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Localization/MvcLocalization_Tests.cs @@ -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 John."); + } } }