mirror of https://github.com/abpframework/abp.git
committed by
GitHub
5 changed files with 129 additions and 61 deletions
@ -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; } |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue