|
| 1 | +using System.Globalization; |
| 2 | +using Abp.Configuration.Startup; |
| 3 | +using Abp.Dependency; |
| 4 | +using Abp.Localization.Sources.Resource; |
| 5 | +using Abp.Tests.Localization.TestResourceFiles; |
| 6 | +using Shouldly; |
| 7 | +using Xunit; |
| 8 | + |
| 9 | +namespace Abp.Tests.Localization |
| 10 | +{ |
| 11 | + public class HumanizerOfUndefinedLocalizationSource_Tests |
| 12 | + { |
| 13 | + private readonly ResourceFileLocalizationSource _resourceFileLocalizationSource; |
| 14 | + private LocalizationConfiguration _localizationConfiguration; |
| 15 | + |
| 16 | + public HumanizerOfUndefinedLocalizationSource_Tests() |
| 17 | + { |
| 18 | + _localizationConfiguration = new LocalizationConfiguration{ WrapGivenTextIfNotFound = false }; |
| 19 | + _resourceFileLocalizationSource = new ResourceFileLocalizationSource("MyTestResource", MyTestResource.ResourceManager); |
| 20 | + _resourceFileLocalizationSource.Initialize(_localizationConfiguration, new IocManager()); |
| 21 | + } |
| 22 | + |
| 23 | + [Fact] |
| 24 | + public void Undefined_Localization_Source_Should_Be_Humanized() |
| 25 | + { |
| 26 | + // Default configuration |
| 27 | + _localizationConfiguration = new LocalizationConfiguration(); |
| 28 | + |
| 29 | + // Fallback to the same text as It's already in sentence case |
| 30 | + _resourceFileLocalizationSource |
| 31 | + .GetString("Lorem ipsum dolor sit amet", new CultureInfo("en-US")) |
| 32 | + .ShouldBe("Lorem ipsum dolor sit amet"); |
| 33 | + |
| 34 | + // Text in PascalCase should be converted properly |
| 35 | + _resourceFileLocalizationSource |
| 36 | + .GetString("LoremIpsumDolorSitAmet", new CultureInfo("en-US")) |
| 37 | + .ShouldBe("Lorem ipsum dolor sit amet"); |
| 38 | + |
| 39 | + // Text with mixed cases should be converted properly |
| 40 | + _resourceFileLocalizationSource |
| 41 | + .GetString("LoremIpsum dolor sit amet", new CultureInfo("en-US")) |
| 42 | + .ShouldBe("Lorem ipsum dolor sit amet"); |
| 43 | + } |
| 44 | + } |
| 45 | +} |
0 commit comments