-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trying to parse
datetime
using CurrentUICulture
.
- Loading branch information
Showing
5 changed files
with
129 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpDateTimeConverter_Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization.Metadata; | ||
using Shouldly; | ||
using Volo.Abp.Json.SystemTextJson.Modifiers; | ||
using Volo.Abp.Localization; | ||
using Xunit; | ||
|
||
namespace Volo.Abp.Json; | ||
|
||
public class AbpDatetimeToEnum_Tests : AbpJsonSystemTextJsonTestBase | ||
{ | ||
[Theory] | ||
[InlineData("tr", "14.02.2024")] | ||
[InlineData("en-US", "2/14/2024")] | ||
[InlineData("en-GB", "14/02/2024")] | ||
public void Test_Read(string culture, string datetime) | ||
{ | ||
var options = new JsonSerializerOptions() | ||
{ | ||
TypeInfoResolver = new DefaultJsonTypeInfoResolver() | ||
{ | ||
Modifiers = { new AbpDateTimeConverterModifier().CreateModifyAction(ServiceProvider) } | ||
} | ||
}; | ||
|
||
using(CultureHelper.Use(culture)) | ||
{ | ||
var testClass = JsonSerializer.Deserialize<TestClass>($"{{\"DateTime\": \"{datetime}\", \"NullableDateTime\": \"{datetime}\"}}", options); | ||
testClass.ShouldNotBeNull(); | ||
testClass.DateTime.ToString(CultureInfo.CurrentCulture).ShouldStartWith(datetime); | ||
testClass.NullableDateTime.ShouldNotBeNull(); | ||
testClass.NullableDateTime.Value.ToString(CultureInfo.CurrentCulture).ShouldStartWith(datetime); | ||
} | ||
|
||
using(CultureHelper.Use(culture)) | ||
{ | ||
var testClass = JsonSerializer.Deserialize<TestClass>($"{{\"DateTime\": \"{datetime}\", \"NullableDateTime\": null}}", options); | ||
testClass.ShouldNotBeNull(); | ||
testClass.DateTime.ToString(CultureInfo.CurrentCulture).ShouldStartWith(datetime); | ||
testClass.NullableDateTime.ShouldBeNull(); | ||
} | ||
} | ||
|
||
class TestClass | ||
{ | ||
public DateTime DateTime { get; set; } | ||
|
||
public DateTime? NullableDateTime { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters