From e35718507bf1a02c95615ccfd5ac1b5b4ac7997a Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Sun, 25 Sep 2022 11:22:05 +0300 Subject: [PATCH 1/5] Refactor localization tests --- .../Localization/CultureDictionaryTests.cs | 4 +- .../Localization/CultureScopeTests.cs | 1 + .../Localization/LocalizationManagerTests.cs | 10 +++-- .../Localization/NullStringLocalizerTests.cs | 8 ++-- .../Localization/PoParserTests.cs | 4 +- .../PortableObjectStringLocalizerTests.cs | 45 ++++++++++++------- 6 files changed, 43 insertions(+), 29 deletions(-) diff --git a/test/OrchardCore.Tests/Localization/CultureDictionaryTests.cs b/test/OrchardCore.Tests/Localization/CultureDictionaryTests.cs index bc73b6adf3f..04d4490af44 100644 --- a/test/OrchardCore.Tests/Localization/CultureDictionaryTests.cs +++ b/test/OrchardCore.Tests/Localization/CultureDictionaryTests.cs @@ -7,8 +7,8 @@ namespace OrchardCore.Tests.Localization { public class CultureDictionaryTests { - private static PluralizationRuleDelegate _arPluralRule = n => (n == 0 ? 0 : n == 1 ? 1 : n == 2 ? 2 : n % 100 >= 3 && n % 100 <= 10 ? 3 : n % 100 >= 11 ? 4 : 5); - private static PluralizationRuleDelegate _csPluralRule = n => ((n == 1) ? 0 : (n >= 2 && n <= 4) ? 1 : 2); + private readonly static PluralizationRuleDelegate _arPluralRule = n => (n == 0 ? 0 : n == 1 ? 1 : n == 2 ? 2 : n % 100 >= 3 && n % 100 <= 10 ? 3 : n % 100 >= 11 ? 4 : 5); + private readonly static PluralizationRuleDelegate _csPluralRule = n => ((n == 1) ? 0 : (n >= 2 && n <= 4) ? 1 : 2); [Fact] public void MergeAddsRecordToEmptyDictionary() diff --git a/test/OrchardCore.Tests/Localization/CultureScopeTests.cs b/test/OrchardCore.Tests/Localization/CultureScopeTests.cs index 36844ed8432..49febe4b2ae 100644 --- a/test/OrchardCore.Tests/Localization/CultureScopeTests.cs +++ b/test/OrchardCore.Tests/Localization/CultureScopeTests.cs @@ -72,6 +72,7 @@ await Assert.ThrowsAsync(() => throw new Exception("Something goes wrong!!"); } }); + Assert.Equal(culture, CultureInfo.CurrentCulture); Assert.Equal(uiCulture, CultureInfo.CurrentUICulture); } diff --git a/test/OrchardCore.Tests/Localization/LocalizationManagerTests.cs b/test/OrchardCore.Tests/Localization/LocalizationManagerTests.cs index 0e259693921..b3ec447e5aa 100644 --- a/test/OrchardCore.Tests/Localization/LocalizationManagerTests.cs +++ b/test/OrchardCore.Tests/Localization/LocalizationManagerTests.cs @@ -8,10 +8,11 @@ namespace OrchardCore.Tests.Localization { public class LocalizationManagerTests { + private readonly Mock _pluralRuleProvider; + private readonly Mock _translationProvider; + private readonly IMemoryCache _memoryCache; + private PluralizationRuleDelegate _csPluralRule = n => ((n == 1) ? 0 : (n >= 2 && n <= 4) ? 1 : 2); - private Mock _pluralRuleProvider; - private Mock _translationProvider; - private IMemoryCache _memoryCache; public LocalizationManagerTests() { @@ -30,6 +31,7 @@ public void GetDictionaryReturnsDictionaryWithPluralRuleAndCultureIfNoTranslatio It.Is(culture => culture == "cs"), It.IsAny()) ); + var manager = new LocalizationManager(new[] { _pluralRuleProvider.Object }, new[] { _translationProvider.Object }, _memoryCache); var dictionary = manager.GetDictionary(new CultureInfo("cs")); @@ -45,6 +47,7 @@ public void GetDictionaryReturnsDictionaryWithTranslationsFromProvider() _translationProvider .Setup(o => o.LoadTranslations(It.Is(culture => culture == "cs"), It.IsAny())) .Callback((culture, dictioanry) => dictioanry.MergeTranslations(new[] { dictionaryRecord })); + var manager = new LocalizationManager(new[] { _pluralRuleProvider.Object }, new[] { _translationProvider.Object }, _memoryCache); var dictionary = manager.GetDictionary(new CultureInfo("cs")); @@ -68,6 +71,7 @@ public void GetDictionarySelectsPluralRuleFromProviderWithHigherPriority() It.Is(culture => culture == "cs"), It.IsAny()) ); + var manager = new LocalizationManager(new[] { _pluralRuleProvider.Object, highPriorityRuleProvider.Object }, new[] { _translationProvider.Object }, _memoryCache); var dictionary = manager.GetDictionary(new CultureInfo("cs")); diff --git a/test/OrchardCore.Tests/Localization/NullStringLocalizerTests.cs b/test/OrchardCore.Tests/Localization/NullStringLocalizerTests.cs index 3e85cf9f6b4..5e898fea9a0 100644 --- a/test/OrchardCore.Tests/Localization/NullStringLocalizerTests.cs +++ b/test/OrchardCore.Tests/Localization/NullStringLocalizerTests.cs @@ -24,11 +24,9 @@ public void HtmlNullLocalizerSupportsPlural(string expected, int count, string s { var localizer = new NullHtmlLocalizerFactory().Create(typeof(object)); - using (var writer = new StringWriter()) - { - localizer.Plural(count, singular, plural, arguments).WriteTo(writer, HtmlEncoder.Default); - Assert.Equal(expected, writer.ToString()); - } + using var writer = new StringWriter(); + localizer.Plural(count, singular, plural, arguments).WriteTo(writer, HtmlEncoder.Default); + Assert.Equal(expected, writer.ToString()); } [Theory] diff --git a/test/OrchardCore.Tests/Localization/PoParserTests.cs b/test/OrchardCore.Tests/Localization/PoParserTests.cs index 1467a17c5ea..51af7684b21 100644 --- a/test/OrchardCore.Tests/Localization/PoParserTests.cs +++ b/test/OrchardCore.Tests/Localization/PoParserTests.cs @@ -53,8 +53,8 @@ public void ParseIgnoresPoeditHeader() // msgstr "Error desconegut del sistema" var entries = ParseText("PoeditHeader"); - Assert.True(entries.Count() == 1); - Assert.True(entries[0].Translations.Count() == 1); + Assert.True(entries.Length == 1); + Assert.True(entries[0].Translations.Length == 1); } [Fact] diff --git a/test/OrchardCore.Tests/Localization/PortableObjectStringLocalizerTests.cs b/test/OrchardCore.Tests/Localization/PortableObjectStringLocalizerTests.cs index fbbd6583634..d9af3c56fc5 100644 --- a/test/OrchardCore.Tests/Localization/PortableObjectStringLocalizerTests.cs +++ b/test/OrchardCore.Tests/Localization/PortableObjectStringLocalizerTests.cs @@ -21,11 +21,12 @@ namespace OrchardCore.Tests.Localization { public class PortableObjectStringLocalizerTests { - private static PluralizationRuleDelegate _csPluralRule = n => ((n == 1) ? 0 : (n >= 2 && n <= 4) ? 1 : 2); - private static PluralizationRuleDelegate _enPluralRule = n => (n == 1) ? 0 : 1; - private static PluralizationRuleDelegate _arPluralRule = n => (n == 0 ? 0 : n == 1 ? 1 : n == 2 ? 2 : n % 100 >= 3 && n % 100 <= 10 ? 3 : n % 100 >= 11 ? 4 : 5); - private Mock _localizationManager; - private Mock _logger; + private static readonly PluralizationRuleDelegate _csPluralRule = n => ((n == 1) ? 0 : (n >= 2 && n <= 4) ? 1 : 2); + private static readonly PluralizationRuleDelegate _enPluralRule = n => (n == 1) ? 0 : 1; + private static readonly PluralizationRuleDelegate _arPluralRule = n => (n == 0 ? 0 : n == 1 ? 1 : n == 2 ? 2 : n % 100 >= 3 && n % 100 <= 10 ? 3 : n % 100 >= 11 ? 4 : 5); + + private readonly Mock _localizationManager; + private readonly Mock _logger; public PortableObjectStringLocalizerTests() { @@ -69,7 +70,7 @@ public void LocalizerReturnsOriginalTextIfTranslationsDoesntExistInProvidedDicti [Fact] public void LocalizerReturnsOriginalTextIfDictionaryIsEmpty() { - SetupDictionary("cs", new CultureDictionaryRecord[] { }); + SetupDictionary("cs", Array.Empty()); var localizer = new PortableObjectStringLocalizer(null, _localizationManager.Object, true, _logger.Object); using (CultureScope.Create("cs")) @@ -86,6 +87,7 @@ public void LocalizerFallbacksToParentCultureIfTranslationDoesntExistInSpecificC SetupDictionary("cs", new[] { new CultureDictionaryRecord("ball", "míč", "míče", "míčů") }); + SetupDictionary("cs-CZ", new[] { new CultureDictionaryRecord("car", "auto", "auta", "aut") }); @@ -105,9 +107,11 @@ public void LocalizerReturnsTranslationFromSpecificCultureIfItExists() SetupDictionary("cs", new[] { new CultureDictionaryRecord("ball", "míč", "míče", "míčů") }); + SetupDictionary("cs-CZ", new[] { new CultureDictionaryRecord("ball", "balón", "balóny", "balónů") }); + var localizer = new PortableObjectStringLocalizer(null, _localizationManager.Object, true, _logger.Object); using (CultureScope.Create("cs-CZ")) { @@ -141,6 +145,7 @@ public void LocalizerReturnsTranslationWithoutContextIfTranslationWithContextDoe new CultureDictionaryRecord("ball", "míč", "míče", "míčů"), new CultureDictionaryRecord("ball", "big", new [] { "míček", "míčky", "míčků" }) }); + var localizer = new PortableObjectStringLocalizer("small", _localizationManager.Object, true, _logger.Object); using (CultureScope.Create("cs")) { @@ -156,6 +161,7 @@ public void LocalizerReturnsFormattedTranslation() SetupDictionary("cs", new[] { new CultureDictionaryRecord("The page (ID:{0}) was deleted.", "Stránka (ID:{0}) byla smazána.") }); + var localizer = new PortableObjectStringLocalizer("small", _localizationManager.Object, true, _logger.Object); using (CultureScope.Create("cs")) { @@ -171,6 +177,7 @@ public void HtmlLocalizerDoesNotFormatTwiceIfFormattedTranslationContainsCurlyBr SetupDictionary("cs", new[] { new CultureDictionaryRecord("The page (ID:{0}) was deleted.", "Stránka (ID:{0}) byla smazána.") }); + var localizer = new PortableObjectStringLocalizer("small", _localizationManager.Object, true, _logger.Object); using (CultureScope.Create("cs")) { @@ -220,9 +227,11 @@ public void LocalizerReturnsCorrectTranslationForPluralIfNoPluralFormsSpecified( { // using DefaultPluralRuleProvider to test it returns correct rule TryGetRuleFromDefaultPluralRuleProvider(cultureScope.UICulture, out var rule); + Assert.NotNull(rule); SetupDictionary(culture, new[] { new CultureDictionaryRecord("ball", translations), }, rule); + var localizer = new PortableObjectStringLocalizer(null, _localizationManager.Object, true, _logger.Object); var translation = localizer.Plural(count, "ball", "{0} balls", count); @@ -255,7 +264,8 @@ public void LocalizerReturnsTranslationInCorrectPluralForm(string expected, int [InlineData("5 míčů", 5)] public void LocalizerReturnsOriginalValuesIfTranslationDoesntExistAndMultiplePluraflFormsAreSpecified(string expected, int count) { - SetupDictionary("en", new CultureDictionaryRecord[] { }); + SetupDictionary("en", Array.Empty()); + var localizer = new PortableObjectStringLocalizer(null, _localizationManager.Object, true, _logger.Object); using (CultureScope.Create("en")) { @@ -273,6 +283,7 @@ public void LocalizerReturnsCorrectPluralFormIfMultiplePluraflFormsAreSpecified( SetupDictionary("en", new CultureDictionaryRecord[] { new CultureDictionaryRecord("míč", "ball", "{0} balls") }, _enPluralRule); + var localizer = new PortableObjectStringLocalizer(null, _localizationManager.Object, true, _logger.Object); using (CultureScope.Create("en")) { @@ -290,7 +301,9 @@ public void LocalizerFallBackToParentCultureIfFallBackToParentUICulturesIsTrue(b SetupDictionary("ar", new CultureDictionaryRecord[] { new CultureDictionaryRecord("hello", "مرحبا") }, _arPluralRule); - SetupDictionary("ar-YE", new CultureDictionaryRecord[] { }, _arPluralRule); + + SetupDictionary("ar-YE", Array.Empty(), _arPluralRule); + var localizer = new PortableObjectStringLocalizer(null, _localizationManager.Object, fallBackToParentCulture, _logger.Object); using (CultureScope.Create("ar-YE")) { @@ -311,6 +324,7 @@ public void LocalizerReturnsGetAllStrings(bool includeParentCultures, string[] e new CultureDictionaryRecord("Page", "صفحة"), new CultureDictionaryRecord("Article", "مقالة") }, _arPluralRule); + SetupDictionary("ar-YE", new CultureDictionaryRecord[] { new CultureDictionaryRecord("Blog", "مدونة"), new CultureDictionaryRecord("Product", "منتج") @@ -321,7 +335,7 @@ public void LocalizerReturnsGetAllStrings(bool includeParentCultures, string[] e { var translations = localizer.GetAllStrings(includeParentCultures).Select(l => l.Value).ToArray(); - Assert.Equal(expected.Count(), translations.Count()); + Assert.Equal(expected.Length, translations.Length); } } @@ -347,13 +361,15 @@ public void LocalizerWithContextShouldCallGetDictionaryOncePerCulture(string cul // Assert _localizationManager.Verify(lm => lm.GetDictionary(It.IsAny()), Times.Exactly(expectedCalls)); + Assert.Equal("Hello", translation); } + private static bool TryGetRuleFromDefaultPluralRuleProvider(CultureInfo culture, out PluralizationRuleDelegate rule) + => ((IPluralRuleProvider)new DefaultPluralRuleProvider()).TryGetRule(culture, out rule); + private void SetupDictionary(string cultureName, IEnumerable records) - { - SetupDictionary(cultureName, records, _csPluralRule); - } + => SetupDictionary(cultureName, records, _csPluralRule); private void SetupDictionary(string cultureName, IEnumerable records, PluralizationRuleDelegate pluralRule) { @@ -363,11 +379,6 @@ private void SetupDictionary(string cultureName, IEnumerable o.GetDictionary(It.Is(c => c.Name == cultureName))).Returns(dictionary); } - private bool TryGetRuleFromDefaultPluralRuleProvider(CultureInfo culture, out PluralizationRuleDelegate rule) - { - return ((IPluralRuleProvider)new DefaultPluralRuleProvider()).TryGetRule(culture, out rule); - } - public class PortableObjectLocalizationStartup { public void ConfigureServices(IServiceCollection services) From 8d69b419f96247efa493e6630a0b174181d14cd6 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Sun, 25 Sep 2022 11:35:38 +0300 Subject: [PATCH 2/5] Add PluralizationRule --- .../Localization/CultureDictionaryTests.cs | 13 ++++----- .../Localization/PluralizationRule.cs | 12 ++++++++ .../PortableObjectStringLocalizerTests.cs | 28 +++++++++---------- 3 files changed, 31 insertions(+), 22 deletions(-) create mode 100644 test/OrchardCore.Tests/Localization/PluralizationRule.cs diff --git a/test/OrchardCore.Tests/Localization/CultureDictionaryTests.cs b/test/OrchardCore.Tests/Localization/CultureDictionaryTests.cs index 04d4490af44..1103cd082e7 100644 --- a/test/OrchardCore.Tests/Localization/CultureDictionaryTests.cs +++ b/test/OrchardCore.Tests/Localization/CultureDictionaryTests.cs @@ -7,13 +7,10 @@ namespace OrchardCore.Tests.Localization { public class CultureDictionaryTests { - private readonly static PluralizationRuleDelegate _arPluralRule = n => (n == 0 ? 0 : n == 1 ? 1 : n == 2 ? 2 : n % 100 >= 3 && n % 100 <= 10 ? 3 : n % 100 >= 11 ? 4 : 5); - private readonly static PluralizationRuleDelegate _csPluralRule = n => ((n == 1) ? 0 : (n >= 2 && n <= 4) ? 1 : 2); - [Fact] public void MergeAddsRecordToEmptyDictionary() { - var dictionary = new CultureDictionary("cs", _csPluralRule); + var dictionary = new CultureDictionary("cs", PluralizationRule.Czech); var record = new CultureDictionaryRecord("ball", "míč", "míče", "míčů"); dictionary.MergeTranslations(new[] { record }); @@ -24,7 +21,7 @@ public void MergeAddsRecordToEmptyDictionary() [Fact] public void MergeOverwritesTranslationsForSameKeys() { - var dictionary = new CultureDictionary("cs", _csPluralRule); + var dictionary = new CultureDictionary("cs", PluralizationRule.Czech); var record = new CultureDictionaryRecord("ball", "míč", "míče", "míčů"); var record2 = new CultureDictionaryRecord("ball", "balón", "balóny", "balónů"); @@ -37,7 +34,7 @@ public void MergeOverwritesTranslationsForSameKeys() [Fact] public void IndexerReturnNullIfKeyDoesntExist() { - var dictionary = new CultureDictionary("cs", _csPluralRule); + var dictionary = new CultureDictionary("cs", PluralizationRule.Czech); var key = new CultureDictionaryRecordKey("ball"); var translation = dictionary[key]; @@ -48,7 +45,7 @@ public void IndexerReturnNullIfKeyDoesntExist() public void IndexerThrowsPluralFormNotFoundExceptionIfSpecifiedPluralFormDoesntExist() { // Arrange - var dictionary = new CultureDictionary("cs", _csPluralRule); + var dictionary = new CultureDictionary("cs", PluralizationRule.Czech); var record = new CultureDictionaryRecord("ball", "míč", "míče"); dictionary.MergeTranslations(new[] { record }); @@ -64,7 +61,7 @@ public void IndexerThrowsPluralFormNotFoundExceptionIfSpecifiedPluralFormDoesntE public void EnumerateCultureDictionary() { // Arrange - var dictionary = new CultureDictionary("ar", _arPluralRule); + var dictionary = new CultureDictionary("ar", PluralizationRule.Arabic); dictionary.MergeTranslations(new List { new CultureDictionaryRecord("Hello", "مرحبا"), diff --git a/test/OrchardCore.Tests/Localization/PluralizationRule.cs b/test/OrchardCore.Tests/Localization/PluralizationRule.cs new file mode 100644 index 00000000000..e120ccd4e5b --- /dev/null +++ b/test/OrchardCore.Tests/Localization/PluralizationRule.cs @@ -0,0 +1,12 @@ +using OrchardCore.Localization; + +namespace OrchardCore.Tests.Localization; + +public class PluralizationRule +{ + public static readonly PluralizationRuleDelegate Czech = n => ((n == 1) ? 0 : (n >= 2 && n <= 4) ? 1 : 2); + + public static readonly PluralizationRuleDelegate English = n => (n == 1) ? 0 : 1; + + public static readonly PluralizationRuleDelegate Arabic = n => (n == 0 ? 0 : n == 1 ? 1 : n == 2 ? 2 : n % 100 >= 3 && n % 100 <= 10 ? 3 : n % 100 >= 11 ? 4 : 5); +} diff --git a/test/OrchardCore.Tests/Localization/PortableObjectStringLocalizerTests.cs b/test/OrchardCore.Tests/Localization/PortableObjectStringLocalizerTests.cs index d9af3c56fc5..6b3b30928b7 100644 --- a/test/OrchardCore.Tests/Localization/PortableObjectStringLocalizerTests.cs +++ b/test/OrchardCore.Tests/Localization/PortableObjectStringLocalizerTests.cs @@ -21,10 +21,6 @@ namespace OrchardCore.Tests.Localization { public class PortableObjectStringLocalizerTests { - private static readonly PluralizationRuleDelegate _csPluralRule = n => ((n == 1) ? 0 : (n >= 2 && n <= 4) ? 1 : 2); - private static readonly PluralizationRuleDelegate _enPluralRule = n => (n == 1) ? 0 : 1; - private static readonly PluralizationRuleDelegate _arPluralRule = n => (n == 0 ? 0 : n == 1 ? 1 : n == 2 ? 2 : n % 100 >= 3 && n % 100 <= 10 ? 3 : n % 100 >= 11 ? 4 : 5); - private readonly Mock _localizationManager; private readonly Mock _logger; @@ -280,9 +276,10 @@ public void LocalizerReturnsOriginalValuesIfTranslationDoesntExistAndMultiplePlu [InlineData("2 balls", 2)] public void LocalizerReturnsCorrectPluralFormIfMultiplePluraflFormsAreSpecified(string expected, int count) { - SetupDictionary("en", new CultureDictionaryRecord[] { + SetupDictionary("en", new CultureDictionaryRecord[] + { new CultureDictionaryRecord("míč", "ball", "{0} balls") - }, _enPluralRule); + }, PluralizationRule.English); var localizer = new PortableObjectStringLocalizer(null, _localizationManager.Object, true, _logger.Object); using (CultureScope.Create("en")) @@ -298,11 +295,12 @@ public void LocalizerReturnsCorrectPluralFormIfMultiplePluraflFormsAreSpecified( [InlineData(true, "hello", "مرحبا")] public void LocalizerFallBackToParentCultureIfFallBackToParentUICulturesIsTrue(bool fallBackToParentCulture, string resourceKey, string expected) { - SetupDictionary("ar", new CultureDictionaryRecord[] { + SetupDictionary("ar", new CultureDictionaryRecord[] + { new CultureDictionaryRecord("hello", "مرحبا") - }, _arPluralRule); + }, PluralizationRule.Arabic); - SetupDictionary("ar-YE", Array.Empty(), _arPluralRule); + SetupDictionary("ar-YE", Array.Empty(), PluralizationRule.Arabic); var localizer = new PortableObjectStringLocalizer(null, _localizationManager.Object, fallBackToParentCulture, _logger.Object); using (CultureScope.Create("ar-YE")) @@ -318,17 +316,19 @@ public void LocalizerFallBackToParentCultureIfFallBackToParentUICulturesIsTrue(b [InlineData(true, new[] { "مدونة", "منتج", "قائمة", "صفحة", "مقالة" })] public void LocalizerReturnsGetAllStrings(bool includeParentCultures, string[] expected) { - SetupDictionary("ar", new CultureDictionaryRecord[] { + SetupDictionary("ar", new CultureDictionaryRecord[] + { new CultureDictionaryRecord("Blog", "مدونة"), new CultureDictionaryRecord("Menu", "قائمة"), new CultureDictionaryRecord("Page", "صفحة"), new CultureDictionaryRecord("Article", "مقالة") - }, _arPluralRule); + }, PluralizationRule.Arabic); - SetupDictionary("ar-YE", new CultureDictionaryRecord[] { + SetupDictionary("ar-YE", new CultureDictionaryRecord[] + { new CultureDictionaryRecord("Blog", "مدونة"), new CultureDictionaryRecord("Product", "منتج") - }, _arPluralRule); + }, PluralizationRule.Arabic); var localizer = new PortableObjectStringLocalizer(null, _localizationManager.Object, false, _logger.Object); using (CultureScope.Create("ar-YE")) @@ -369,7 +369,7 @@ private static bool TryGetRuleFromDefaultPluralRuleProvider(CultureInfo culture, => ((IPluralRuleProvider)new DefaultPluralRuleProvider()).TryGetRule(culture, out rule); private void SetupDictionary(string cultureName, IEnumerable records) - => SetupDictionary(cultureName, records, _csPluralRule); + => SetupDictionary(cultureName, records, PluralizationRule.Czech); private void SetupDictionary(string cultureName, IEnumerable records, PluralizationRuleDelegate pluralRule) { From 3888e0b7bfd4dc4e22ecd6a4e96108d1ff8ade29 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Sun, 25 Sep 2022 11:45:59 +0300 Subject: [PATCH 3/5] Use PluralizationRule in LocalizationManagerTests --- .../Localization/LocalizationManagerTests.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/OrchardCore.Tests/Localization/LocalizationManagerTests.cs b/test/OrchardCore.Tests/Localization/LocalizationManagerTests.cs index b3ec447e5aa..8c51af02cf4 100644 --- a/test/OrchardCore.Tests/Localization/LocalizationManagerTests.cs +++ b/test/OrchardCore.Tests/Localization/LocalizationManagerTests.cs @@ -12,13 +12,13 @@ public class LocalizationManagerTests private readonly Mock _translationProvider; private readonly IMemoryCache _memoryCache; - private PluralizationRuleDelegate _csPluralRule = n => ((n == 1) ? 0 : (n >= 2 && n <= 4) ? 1 : 2); - public LocalizationManagerTests() { + PluralizationRuleDelegate pluralizationRule; + _pluralRuleProvider = new Mock(); _pluralRuleProvider.SetupGet(o => o.Order).Returns(0); - _pluralRuleProvider.Setup(o => o.TryGetRule(It.Is(culture => culture.Name == "cs"), out _csPluralRule)).Returns(true); + _pluralRuleProvider.Setup(o => o.TryGetRule(It.Is(culture => culture.Name == "cs"), out pluralizationRule)).Returns(true); _translationProvider = new Mock(); _memoryCache = new MemoryCache(new MemoryCacheOptions()); @@ -37,7 +37,7 @@ public void GetDictionaryReturnsDictionaryWithPluralRuleAndCultureIfNoTranslatio var dictionary = manager.GetDictionary(new CultureInfo("cs")); Assert.Equal("cs", dictionary.CultureName); - Assert.Equal(_csPluralRule, dictionary.PluralRule); + Assert.Equal(PluralizationRule.Czech, dictionary.PluralRule); } [Fact] From 0e1faefe90db87ed8b179766fdb0305acbec71f3 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Sun, 25 Sep 2022 12:10:17 +0300 Subject: [PATCH 4/5] Fix build --- .../Localization/LocalizationManagerTests.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/OrchardCore.Tests/Localization/LocalizationManagerTests.cs b/test/OrchardCore.Tests/Localization/LocalizationManagerTests.cs index 8c51af02cf4..519dfe34b09 100644 --- a/test/OrchardCore.Tests/Localization/LocalizationManagerTests.cs +++ b/test/OrchardCore.Tests/Localization/LocalizationManagerTests.cs @@ -14,11 +14,10 @@ public class LocalizationManagerTests public LocalizationManagerTests() { - PluralizationRuleDelegate pluralizationRule; - + var csPluralRule = PluralizationRule.Czech; _pluralRuleProvider = new Mock(); _pluralRuleProvider.SetupGet(o => o.Order).Returns(0); - _pluralRuleProvider.Setup(o => o.TryGetRule(It.Is(culture => culture.Name == "cs"), out pluralizationRule)).Returns(true); + _pluralRuleProvider.Setup(o => o.TryGetRule(It.Is(culture => culture.Name == "cs"), out csPluralRule)).Returns(true); _translationProvider = new Mock(); _memoryCache = new MemoryCache(new MemoryCacheOptions()); From c5e7a74e9bc672b9afaa8c489bbabb3c7c7b9647 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Sun, 25 Sep 2022 12:33:22 +0300 Subject: [PATCH 5/5] Use embedded resource for all po files --- .../OrchardCore.Tests.csproj | 23 +------------------ 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/test/OrchardCore.Tests/OrchardCore.Tests.csproj b/test/OrchardCore.Tests/OrchardCore.Tests.csproj index 0ed8c1e2e32..1fb053a61fd 100644 --- a/test/OrchardCore.Tests/OrchardCore.Tests.csproj +++ b/test/OrchardCore.Tests/OrchardCore.Tests.csproj @@ -19,17 +19,6 @@ - - - - - - - - - - - @@ -43,17 +32,7 @@ - - - - - - - - - - - +