Browse Source

restore behavior test for duplicate JSON keys with clearer naming and comment

pull/25227/head
maliming 3 days ago
parent
commit
5f2d552ebd
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 23
      framework/test/Volo.Abp.Localization.Tests/Volo/Abp/Localization/JsonLocalizationDictionaryBuilder_Tests.cs

23
framework/test/Volo.Abp.Localization.Tests/Volo/Abp/Localization/JsonLocalizationDictionaryBuilder_Tests.cs

@ -9,6 +9,29 @@ namespace Volo.Abp.Localization;
/// </summary>
public class JsonLocalizationDictionaryBuilder_Tests
{
[Fact]
public void Should_Use_Last_Value_When_Json_Contains_Duplicate_Keys()
{
// This test locks the behavior of System.Text.Json when deserializing duplicate JSON property names.
// If STJ changes this behavior in a future version, this test will catch the regression.
var input = """
{
"culture": "en",
"texts": {
"ThisFieldIsRequired": "This field is required",
"MaxLengthErrorMessage": "This field can be maximum of '{0}' chars",
"ThisFieldIsRequired": "This field is required again"
}
}
""";
var localizationDictionary = JsonLocalizationDictionaryBuilder.BuildFromJsonString(input);
localizationDictionary.ShouldNotBeNull();
var localizationString = localizationDictionary.GetOrNull("ThisFieldIsRequired");
localizationString.ShouldNotBeNull();
localizationString.Value.ShouldBe("This field is required again");
}
[Fact]
public void Should_Use_Nested_Value_When_Flat_Key_Is_Defined_Before_Nested_Object()
{

Loading…
Cancel
Save