From 0768f34776bc91855e68508fadc3b56a8d348d7c Mon Sep 17 00:00:00 2001 From: maliming Date: Sat, 14 Nov 2020 13:49:37 +0800 Subject: [PATCH] Add more datetime unit tests. --- ...pSystemTextJsonSerializerProvider_Tests.cs | 51 ++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpSystemTextJsonSerializerProvider_Tests.cs b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpSystemTextJsonSerializerProvider_Tests.cs index 9e166aa146..06e858c7c0 100644 --- a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpSystemTextJsonSerializerProvider_Tests.cs +++ b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpSystemTextJsonSerializerProvider_Tests.cs @@ -4,6 +4,7 @@ using Shouldly; using Volo.Abp.Data; using Volo.Abp.Json.SystemTextJson; using Volo.Abp.ObjectExtending; +using Volo.Abp.Timing; using Xunit; namespace Volo.Abp.Json @@ -167,6 +168,9 @@ namespace Volo.Abp.Json file.CreationTime.Year.ShouldBe(2020); file.CreationTime.Month.ShouldBe(11); file.CreationTime.Day.ShouldBe(20); + + var newJson = JsonSerializer.Serialize(file); + newJson.ShouldBe(json); } [Fact] @@ -187,10 +191,13 @@ namespace Volo.Abp.Json file.CreationTime.Value.Year.ShouldBe(2020); file.CreationTime.Value.Month.ShouldBe(11); file.CreationTime.Value.Day.ShouldBe(20); + + var newJson = JsonSerializer.Serialize(file); + newJson.ShouldBe(json); } } - public class AbpSystemTextJsonSerializerProviderDefaultDateTimeFormat_Tests : AbpSystemTextJsonSerializerProvider_TestBase + public class AbpSystemTextJsonSerializerProvider_DateTimeFormat_Tests : AbpSystemTextJsonSerializerProvider_TestBase { protected override void AfterAddApplication(IServiceCollection services) { @@ -208,6 +215,9 @@ namespace Volo.Abp.Json file.CreationTime.Year.ShouldBe(2020); file.CreationTime.Month.ShouldBe(11); file.CreationTime.Day.ShouldBe(20); + + var newJson = JsonSerializer.Serialize(file); + newJson.ShouldBe(json); } [Fact] @@ -228,6 +238,45 @@ namespace Volo.Abp.Json file.CreationTime.Value.Year.ShouldBe(2020); file.CreationTime.Value.Month.ShouldBe(11); file.CreationTime.Value.Day.ShouldBe(20); + + var newJson = JsonSerializer.Serialize(file); + newJson.ShouldBe(json); } } + + public abstract class AbpSystemTextJsonSerializerProvider_Datetime_Kind_Tests : AbpSystemTextJsonSerializerProvider_TestBase + { + protected DateTimeKind Kind { get; set; } = DateTimeKind.Unspecified; + + [Fact] + public void Serialize_Deserialize() + { + var json = "{\"name\":\"abp\",\"creationTime\":\"2020-11-20T00:00:00\"}"; + var file = JsonSerializer.Deserialize(json); + file.CreationTime.Kind.ShouldBe(Kind); + } + } + + public class AbpSystemTextJsonSerializerProvider_Datetime_Kind_UTC_Tests : AbpSystemTextJsonSerializerProvider_Datetime_Kind_Tests + { + protected override void AfterAddApplication(IServiceCollection services) + { + Kind = DateTimeKind.Utc; + services.Configure(x => x.Kind = Kind); + } + } + + public class AbpSystemTextJsonSerializerProvider_Datetime_Kind_Local_Tests : AbpSystemTextJsonSerializerProvider_Datetime_Kind_Tests + { + protected override void AfterAddApplication(IServiceCollection services) + { + Kind = DateTimeKind.Local; + services.Configure(x => x.Kind = Kind); + } + } + + public class AbpSystemTextJsonSerializerProvider_Datetime_Kind_Unspecified_Tests : AbpSystemTextJsonSerializerProvider_Datetime_Kind_Tests + { + + } }