mirror of https://github.com/abpframework/abp.git
14 changed files with 150 additions and 22 deletions
@ -0,0 +1,47 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Text; |
||||
|
using NSubstitute.ExceptionExtensions; |
||||
|
using Shouldly; |
||||
|
using Volo.Abp.Localization.Json; |
||||
|
using Volo.Abp.Testing; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Volo.Abp.Localization; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Testing edge cases for <see cref="JsonLocalizationDictionaryBuilder"/>
|
||||
|
/// </summary>
|
||||
|
public class JsonLocalizationDictionaryBuilder_Tests : AbpIntegratedTest<AbpLocalizationTestModule> |
||||
|
{ |
||||
|
[Fact] |
||||
|
public void JsonLocalizationDictionaryBuilder_Should_Handle_Duplicates() |
||||
|
{ |
||||
|
var localizationDictionary = JsonLocalizationDictionaryBuilder |
||||
|
.BuildFromJsonString("{\r\n \"culture\": \"en\",\r\n \"texts\": {\r\n \"ThisFieldIsRequired\": \"This field is required\",\r\n \"MaxLenghtErrorMessage\": \"This field can be maximum of '{0}' chars\",\r\n \"Enum:BookType.Undefined\": \"Undefined from ValidationResource\",\r\n \"Enum:BookType.0\": \"Undefined with value 0 from ValidationResource\",\r\n \"BookType.Adventure\": \"Adventure from ValidationResource\",\r\n \"BookType.1\": \"Adventure with value 1 from ValidationResource\",\r\n \"Biography\": \"Biography from ValidationResource\",\r\n \"ThisFieldIsRequired\": \"This field is required again\"\r\n }\r\n}"); |
||||
|
|
||||
|
var localizationString = localizationDictionary.GetOrNull("ThisFieldIsRequired"); |
||||
|
localizationString.ShouldNotBeNull(); |
||||
|
|
||||
|
localizationString.Value.ShouldBe("This field is required again"); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void JsonLocalizationDictionaryBuilder_Should_Handle_Deep_Duplicates() |
||||
|
{ |
||||
|
var input = @"{
|
||||
|
""culture"": ""en"", |
||||
|
""texts"": { |
||||
|
""ThisFieldIsRequired"": ""This field is required"", |
||||
|
""DeepLocaliaztionKey"": {""DeepKey"": ""DeepValue""}, |
||||
|
""DeepLocaliaztionKey__DeepKey"": ""Another translation"" |
||||
|
} |
||||
|
}";
|
||||
|
|
||||
|
var localizationDictionary = JsonLocalizationDictionaryBuilder.BuildFromJsonString(input); |
||||
|
localizationDictionary.ShouldNotBeNull(); |
||||
|
var localizationString = localizationDictionary.GetOrNull("DeepLocaliaztionKey__DeepKey"); |
||||
|
localizationString.ShouldNotBeNull(); |
||||
|
localizationString.Value.ShouldBe("Another translation"); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,6 @@ |
|||||
|
{ |
||||
|
"culture": "en", |
||||
|
"texts": { |
||||
|
"ThisIsRequiredValue": "This is required value" |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,7 @@ |
|||||
|
{ |
||||
|
"culture": "en", |
||||
|
"texts": { |
||||
|
"Base.Id": "Id", |
||||
|
"Base.Name": "Name" |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,7 @@ |
|||||
|
{ |
||||
|
"culture": "en", |
||||
|
"texts": { |
||||
|
"Book.Id": "ISBN", |
||||
|
"Book.Name": "Title" |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,6 @@ |
|||||
|
{ |
||||
|
"culture": "en", |
||||
|
"texts": { |
||||
|
"ThisIsRequiredValue": "This is required value (this will be used)" |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
{ |
||||
|
"culture": "de", |
||||
|
"texts": { |
||||
|
"Enum:BookType.Undefined": "Nicht definiert", |
||||
|
"Enum:BookType.0": "Undefiniert mit Wert 0", |
||||
|
"BookType.Adventure": "Abenteuer", |
||||
|
"BookType.1": "Abenteuer mit Wert 1", |
||||
|
"Biography": "Biografie" |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue