From b7f1b4ac05db570f2446ce02c3351ad5b514ba11 Mon Sep 17 00:00:00 2001 From: Mahmut Gundogdu Date: Tue, 21 Mar 2023 16:18:26 +0300 Subject: [PATCH 1/5] Commit message: Add Optional and use !! to include localization resources in ConfigStateService --- .../core/src/lib/services/config-state.service.ts | 15 +++++++++------ .../core/testing/src/lib/core-testing.module.ts | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/npm/ng-packs/packages/core/src/lib/services/config-state.service.ts b/npm/ng-packs/packages/core/src/lib/services/config-state.service.ts index e4475cd462..c245005ff7 100644 --- a/npm/ng-packs/packages/core/src/lib/services/config-state.service.ts +++ b/npm/ng-packs/packages/core/src/lib/services/config-state.service.ts @@ -1,4 +1,4 @@ -import { inject, Injectable } from '@angular/core'; +import { Inject, Injectable, Optional } from '@angular/core'; import { Observable, Subject } from 'rxjs'; import { map, switchMap, take, tap } from 'rxjs/operators'; import { AbpApplicationConfigurationService } from '../proxy/volo/abp/asp-net-core/mvc/application-configurations/abp-application-configuration.service'; @@ -15,9 +15,6 @@ import { InternalStore } from '../utils/internal-store-utils'; }) export class ConfigStateService { private readonly store = new InternalStore({} as ApplicationConfigurationDto); - private readonly includeLocalizationResources = inject(INCUDE_LOCALIZATION_RESOURCES_TOKEN); - private abpConfigService = inject(AbpApplicationConfigurationService); - private abpApplicationLocalizationService = inject(AbpApplicationLocalizationService); get createOnUpdateStream() { return this.store.sliceUpdate; @@ -25,7 +22,13 @@ export class ConfigStateService { private updateSubject = new Subject(); - constructor() { + constructor( + private abpConfigService: AbpApplicationConfigurationService, + private abpApplicationLocalizationService: AbpApplicationLocalizationService, + @Optional() + @Inject(INCUDE_LOCALIZATION_RESOURCES_TOKEN) + private readonly includeLocalizationResources: boolean | null, + ) { this.initUpdateStream(); } @@ -34,7 +37,7 @@ export class ConfigStateService { .pipe( switchMap(() => this.abpConfigService.get({ - includeLocalizationResources: this.includeLocalizationResources, + includeLocalizationResources: !!this.includeLocalizationResources, }), ), ) diff --git a/npm/ng-packs/packages/core/testing/src/lib/core-testing.module.ts b/npm/ng-packs/packages/core/testing/src/lib/core-testing.module.ts index 8aab44d44b..7ffeba2a9e 100644 --- a/npm/ng-packs/packages/core/testing/src/lib/core-testing.module.ts +++ b/npm/ng-packs/packages/core/testing/src/lib/core-testing.module.ts @@ -63,7 +63,7 @@ export class CoreTestingModule { }, { provide: INCUDE_LOCALIZATION_RESOURCES_TOKEN, - useValue: false, + useValue: true, }, provideRoutes(routes), ], From a6006a1135eb880ecfb620dcf5bc9796d0b35690 Mon Sep 17 00:00:00 2001 From: Mahmut Gundogdu Date: Tue, 21 Mar 2023 17:21:57 +0300 Subject: [PATCH 2/5] Update core-testing.module.ts --- .../packages/core/testing/src/lib/core-testing.module.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/npm/ng-packs/packages/core/testing/src/lib/core-testing.module.ts b/npm/ng-packs/packages/core/testing/src/lib/core-testing.module.ts index 7ffeba2a9e..8aab44d44b 100644 --- a/npm/ng-packs/packages/core/testing/src/lib/core-testing.module.ts +++ b/npm/ng-packs/packages/core/testing/src/lib/core-testing.module.ts @@ -63,7 +63,7 @@ export class CoreTestingModule { }, { provide: INCUDE_LOCALIZATION_RESOURCES_TOKEN, - useValue: true, + useValue: false, }, provideRoutes(routes), ], From 182a1ade0303f443c07889ff5f46a384bf105e53 Mon Sep 17 00:00:00 2001 From: maliming Date: Wed, 22 Mar 2023 08:56:39 +0800 Subject: [PATCH 3/5] Add `InputAndOutputDateTimeFormat_Tests`. --- .../Json/Newtonsoft/AbpDateTimeConverter.cs | 13 +- .../Volo.Abp.Json.Tests.csproj | 3 +- .../AbpIgnorePropertiesModifiers_Tests.cs | 2 +- ...cludeNonPublicPropertiesModifiers_Tests.cs | 2 +- .../Abp/Json/AbpJsonNewtonsoftTestModule.cs | 26 ++++ .../Abp/Json/AbpJsonSystemTextJsonTestBase.cs | 19 +++ .../Volo/Abp/Json/AbpJsonTestBase.cs | 11 -- .../Volo/Abp/Json/AbpJsonTestModule.cs | 14 --- ...pSystemTextJsonSerializerProvider_Tests.cs | 16 +-- .../Json/ExtensibleObjectModifiers_Tests.cs | 2 +- .../Volo/Abp/Json/ExtensibleObject_Tests.cs | 2 +- .../InputAndOutputDateTimeFormat_Tests.cs | 112 ++++++++++++++++++ 12 files changed, 176 insertions(+), 46 deletions(-) create mode 100644 framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpJsonNewtonsoftTestModule.cs create mode 100644 framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpJsonSystemTextJsonTestBase.cs delete mode 100644 framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpJsonTestBase.cs delete mode 100644 framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpJsonTestModule.cs create mode 100644 framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/InputAndOutputDateTimeFormat_Tests.cs diff --git a/framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpDateTimeConverter.cs b/framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpDateTimeConverter.cs index 5e698956b3..8487321988 100644 --- a/framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpDateTimeConverter.cs +++ b/framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpDateTimeConverter.cs @@ -12,9 +12,9 @@ using Volo.Abp.Timing; namespace Volo.Abp.Json.Newtonsoft; -public class AbpDateTimeConverter : DateTimeConverterBase, ITransientDependency +public class AbpDateTimeConverter : DateTimeConverterBase, ITransientDependency, IsoDateTimeConverter { - private readonly string _dateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFFFK"; + private const string DefaultDateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFFFK"; private readonly DateTimeStyles _dateTimeStyles = DateTimeStyles.RoundtripKind; private readonly CultureInfo _culture = CultureInfo.InvariantCulture; private readonly IClock _clock; @@ -72,10 +72,7 @@ public class AbpDateTimeConverter : DateTimeConverterBase, ITransientDependency } } - var date = !_dateTimeFormat.IsNullOrEmpty() ? - DateTime.ParseExact(dateText, _dateTimeFormat, _culture, _dateTimeStyles) : - DateTime.Parse(dateText, _culture, _dateTimeStyles); - + var date = DateTime.Parse(dateText, _culture, _dateTimeStyles); return _clock.Normalize(date); } @@ -95,7 +92,7 @@ public class AbpDateTimeConverter : DateTimeConverterBase, ITransientDependency } writer.WriteValue(_options.OutputDateTimeFormat.IsNullOrWhiteSpace() - ? dateTime.ToString(_dateTimeFormat, _culture) + ? dateTime.ToString(DefaultDateTimeFormat, _culture) : dateTime.ToString(_options.OutputDateTimeFormat, _culture)); } else @@ -104,7 +101,7 @@ public class AbpDateTimeConverter : DateTimeConverterBase, ITransientDependency } } - internal static bool ShouldNormalize(MemberInfo member, JsonProperty property) + static internal bool ShouldNormalize(MemberInfo member, JsonProperty property) { if (property.PropertyType != typeof(DateTime) && property.PropertyType != typeof(DateTime?)) diff --git a/framework/test/Volo.Abp.Json.Tests/Volo.Abp.Json.Tests.csproj b/framework/test/Volo.Abp.Json.Tests/Volo.Abp.Json.Tests.csproj index 9d1bad51f2..f5ceee7c40 100644 --- a/framework/test/Volo.Abp.Json.Tests/Volo.Abp.Json.Tests.csproj +++ b/framework/test/Volo.Abp.Json.Tests/Volo.Abp.Json.Tests.csproj @@ -9,7 +9,8 @@ - + + diff --git a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpIgnorePropertiesModifiers_Tests.cs b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpIgnorePropertiesModifiers_Tests.cs index 138ffd46a7..7be045874a 100644 --- a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpIgnorePropertiesModifiers_Tests.cs +++ b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpIgnorePropertiesModifiers_Tests.cs @@ -7,7 +7,7 @@ using Xunit; namespace Volo.Abp.Json; -public class AbpIgnorePropertiesModifiers_Tests : AbpJsonTestBase +public class AbpIgnorePropertiesModifiers_Tests : AbpJsonSystemTextJsonTestBase { private readonly IJsonSerializer _jsonSerializer; diff --git a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpIncludeNonPublicPropertiesModifiers_Tests.cs b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpIncludeNonPublicPropertiesModifiers_Tests.cs index 38d733a3d8..c6d961d2b7 100644 --- a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpIncludeNonPublicPropertiesModifiers_Tests.cs +++ b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpIncludeNonPublicPropertiesModifiers_Tests.cs @@ -6,7 +6,7 @@ using Xunit; namespace Volo.Abp.Json; -public class AbpIncludeNonPublicPropertiesModifiers_Tests : AbpJsonTestBase +public class AbpIncludeNonPublicPropertiesModifiers_Tests : AbpJsonSystemTextJsonTestBase { private readonly IJsonSerializer _jsonSerializer; diff --git a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpJsonNewtonsoftTestModule.cs b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpJsonNewtonsoftTestModule.cs new file mode 100644 index 0000000000..42559397da --- /dev/null +++ b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpJsonNewtonsoftTestModule.cs @@ -0,0 +1,26 @@ +using Volo.Abp.Autofac; +using Volo.Abp.Json.Newtonsoft; +using Volo.Abp.Json.SystemTextJson; +using Volo.Abp.Modularity; + +namespace Volo.Abp.Json; + +[DependsOn( + typeof(AbpAutofacModule), + typeof(AbpJsonSystemTextJsonModule), + typeof(AbpTestBaseModule) +)] +public class AbpJsonSystemTextJsonTestModule : AbpModule +{ + +} + +[DependsOn( + typeof(AbpAutofacModule), + typeof(AbpJsonNewtonsoftModule), + typeof(AbpTestBaseModule) +)] +public class AbpJsonNewtonsoftTestModule : AbpModule +{ + +} diff --git a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpJsonSystemTextJsonTestBase.cs b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpJsonSystemTextJsonTestBase.cs new file mode 100644 index 0000000000..ebae706aca --- /dev/null +++ b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpJsonSystemTextJsonTestBase.cs @@ -0,0 +1,19 @@ +using Volo.Abp.Testing; + +namespace Volo.Abp.Json; + +public abstract class AbpJsonSystemTextJsonTestBase : AbpIntegratedTest +{ + protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) + { + options.UseAutofac(); + } +} + +public abstract class AbpJsonNewtonsoftJsonTestBase : AbpIntegratedTest +{ + protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) + { + options.UseAutofac(); + } +} diff --git a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpJsonTestBase.cs b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpJsonTestBase.cs deleted file mode 100644 index ef31c7516f..0000000000 --- a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpJsonTestBase.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Volo.Abp.Testing; - -namespace Volo.Abp.Json; - -public abstract class AbpJsonTestBase : AbpIntegratedTest -{ - protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) - { - options.UseAutofac(); - } -} diff --git a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpJsonTestModule.cs b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpJsonTestModule.cs deleted file mode 100644 index 0fd3cbd1cf..0000000000 --- a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpJsonTestModule.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Volo.Abp.Autofac; -using Volo.Abp.Modularity; - -namespace Volo.Abp.Json; - -[DependsOn( - typeof(AbpAutofacModule), - typeof(AbpJsonModule), - typeof(AbpTestBaseModule) -)] -public class AbpJsonTestModule : AbpModule -{ - -} 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 f605914d6e..e32df85d7f 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 @@ -9,11 +9,11 @@ using Xunit; namespace Volo.Abp.Json; -public abstract class AbpSystemTextJsonSerializerProvider_TestBase : AbpJsonTestBase +public abstract class AbpSystemTextJsonSerializerProviderTestBase : AbpJsonSystemTextJsonTestBase { protected AbpSystemTextJsonSerializer JsonSerializer; - public AbpSystemTextJsonSerializerProvider_TestBase() + public AbpSystemTextJsonSerializerProviderTestBase() { JsonSerializer = GetRequiredService(); } @@ -72,7 +72,7 @@ public abstract class AbpSystemTextJsonSerializerProvider_TestBase : AbpJsonTest } } -public class AbpSystemTextJsonSerializerProvider_Tests : AbpSystemTextJsonSerializerProvider_TestBase +public class AbpSystemTextJsonSerializerProviderTests : AbpSystemTextJsonSerializerProviderTestBase { [Fact] public void Serialize_Deserialize_With_Boolean() @@ -214,7 +214,7 @@ public class AbpSystemTextJsonSerializerProvider_Tests : AbpSystemTextJsonSerial } } -public class AbpSystemTextJsonSerializerProvider_DateTimeFormat_Tests : AbpSystemTextJsonSerializerProvider_TestBase +public class AbpSystemTextJsonSerializerProviderDateTimeFormatTests : AbpSystemTextJsonSerializerProviderTestBase { protected override void AfterAddApplication(IServiceCollection services) { @@ -270,7 +270,7 @@ public class AbpSystemTextJsonSerializerProvider_DateTimeFormat_Tests : AbpSyste } } -public abstract class AbpSystemTextJsonSerializerProvider_Datetime_Kind_Tests : AbpSystemTextJsonSerializerProvider_TestBase +public abstract class AbpSystemTextJsonSerializerProviderDatetimeKindTests : AbpSystemTextJsonSerializerProviderTestBase { protected DateTimeKind Kind { get; set; } = DateTimeKind.Unspecified; @@ -283,7 +283,7 @@ public abstract class AbpSystemTextJsonSerializerProvider_Datetime_Kind_Tests : } } -public class AbpSystemTextJsonSerializerProvider_Datetime_Kind_UTC_Tests : AbpSystemTextJsonSerializerProvider_Datetime_Kind_Tests +public class AbpSystemTextJsonSerializerProviderDatetimeKindUtcTests : AbpSystemTextJsonSerializerProviderDatetimeKindTests { protected override void AfterAddApplication(IServiceCollection services) { @@ -292,7 +292,7 @@ public class AbpSystemTextJsonSerializerProvider_Datetime_Kind_UTC_Tests : AbpSy } } -public class AbpSystemTextJsonSerializerProvider_Datetime_Kind_Local_Tests : AbpSystemTextJsonSerializerProvider_Datetime_Kind_Tests +public class AbpSystemTextJsonSerializerProviderDatetimeKindLocalTests : AbpSystemTextJsonSerializerProviderDatetimeKindTests { protected override void AfterAddApplication(IServiceCollection services) { @@ -301,7 +301,7 @@ public class AbpSystemTextJsonSerializerProvider_Datetime_Kind_Local_Tests : Abp } } -public class AbpSystemTextJsonSerializerProvider_Datetime_Kind_Unspecified_Tests : AbpSystemTextJsonSerializerProvider_Datetime_Kind_Tests +public class AbpSystemTextJsonSerializerProviderDatetimeKindUnspecifiedTests : AbpSystemTextJsonSerializerProviderDatetimeKindTests { } diff --git a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/ExtensibleObjectModifiers_Tests.cs b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/ExtensibleObjectModifiers_Tests.cs index 0bb538f9d1..d0337b2d9d 100644 --- a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/ExtensibleObjectModifiers_Tests.cs +++ b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/ExtensibleObjectModifiers_Tests.cs @@ -6,7 +6,7 @@ using Xunit; namespace Volo.Abp.Json; -public class ExtensibleObjectModifiers_Tests : AbpJsonTestBase +public class ExtensibleObjectModifiers_Tests : AbpJsonSystemTextJsonTestBase { [Fact] public void Should_Modify_Object() diff --git a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/ExtensibleObject_Tests.cs b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/ExtensibleObject_Tests.cs index a5bcb723db..91aafccb81 100644 --- a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/ExtensibleObject_Tests.cs +++ b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/ExtensibleObject_Tests.cs @@ -7,7 +7,7 @@ using Xunit; namespace Volo.Abp.Json; -public class ExtensibleObject_Tests : AbpJsonTestBase +public class ExtensibleObject_Tests : AbpJsonSystemTextJsonTestBase { private readonly IJsonSerializer _jsonSerializer; diff --git a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/InputAndOutputDateTimeFormat_Tests.cs b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/InputAndOutputDateTimeFormat_Tests.cs new file mode 100644 index 0000000000..cf6356477d --- /dev/null +++ b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/InputAndOutputDateTimeFormat_Tests.cs @@ -0,0 +1,112 @@ +using System; +using System.Collections.Generic; +using Microsoft.Extensions.DependencyInjection; +using Shouldly; +using Volo.Abp.Timing; +using Xunit; + +namespace Volo.Abp.Json; + +public class InputAndOutputDateTimeFormatSystemTextJsonTests : AbpJsonSystemTextJsonTestBase +{ + private readonly IJsonSerializer _jsonSerializer; + + public InputAndOutputDateTimeFormatSystemTextJsonTests() + { + _jsonSerializer = GetRequiredService(); + } + + protected override void AfterAddApplication(IServiceCollection services) + { + services.Configure(options => + { + options.InputDateTimeFormats = new List() + { + "yyyy*MM*dd", + "yyyy-MM-dd HH:mm:ss" + }; + options.OutputDateTimeFormat = "yyyy*MM-dd HH:mm:ss"; + }); + services.Configure(options => + { + options.Kind = DateTimeKind.Utc; + }); + } + + [Fact] + public void InputAndOutputDateTimeFormat_Test() + { + var resultDate = new DateTime(2016, 04, 13, 08, 58, 10, DateTimeKind.Utc); + var json = _jsonSerializer.Serialize(new DateTimeDto() + { + DateTime1 = resultDate, + DateTime2 = resultDate + }); + json.ShouldContain("\"DateTime1\":\"2016*04-13 08:58:10\""); + json.ShouldContain("\"DateTime2\":\"2016*04-13 08:58:10\""); + + var dto = _jsonSerializer.Deserialize("{\"DateTime1\":\"" + resultDate.ToString("yyyy*MM*dd") + "\",\"DateTime2\":\"" + resultDate.ToString("yyyy-MM-dd HH:mm:ss") + "\"}"); + dto.DateTime1.ShouldBe(resultDate.Date); + dto.DateTime1.Kind.ShouldBe(DateTimeKind.Utc); + dto.DateTime2.ShouldBe(resultDate); + dto.DateTime2.Value.Kind.ShouldBe(DateTimeKind.Utc); + } + + public class DateTimeDto + { + public DateTime DateTime1 { get; set; } + public DateTime? DateTime2 { get; set; } + } +} + +public class InputAndOutputDateTimeFormatNewtonsoftTests : AbpJsonNewtonsoftJsonTestBase +{ + private readonly IJsonSerializer _jsonSerializer; + + public InputAndOutputDateTimeFormatNewtonsoftTests() + { + _jsonSerializer = GetRequiredService(); + } + + protected override void AfterAddApplication(IServiceCollection services) + { + services.Configure(options => + { + options.InputDateTimeFormats = new List() + { + "yyyy*MM*dd", + "yyyy-MM-dd HH:mm:ss" + }; + options.OutputDateTimeFormat = "yyyy*MM-dd HH:mm:ss"; + }); + services.Configure(options => + { + options.Kind = DateTimeKind.Utc; + }); + } + + [Fact] + public void InputAndOutputDateTimeFormat_Test() + { + var resultDate = new DateTime(2016, 04, 13, 08, 58, 10, DateTimeKind.Utc); + var json = _jsonSerializer.Serialize(new DateTimeDto() + { + DateTime1 = resultDate, + DateTime2 = resultDate + }); + json.ShouldContain("\"DateTime1\":\"2016*04-13 08:58:10\""); + json.ShouldContain("\"DateTime2\":\"2016*04-13 08:58:10\""); + + var dto = _jsonSerializer.Deserialize("{\"DateTime1\":\"" + resultDate.ToString("yyyy*MM*dd") + "\",\"DateTime2\":\"" + resultDate.ToString("yyyy-MM-dd HH:mm:ss") + "\"}"); + dto.DateTime1.ShouldBe(resultDate.Date); + dto.DateTime1.Kind.ShouldBe(DateTimeKind.Utc); + dto.DateTime2.ShouldBe(resultDate); + dto.DateTime2.Value.Kind.ShouldBe(DateTimeKind.Utc); + } + + public class DateTimeDto + { + public DateTime DateTime1 { get; set; } + public DateTime? DateTime2 { get; set; } + } +} From 3485ca44a4fde0b7f1290ebe573478952d85ffc0 Mon Sep 17 00:00:00 2001 From: maliming Date: Wed, 22 Mar 2023 09:21:21 +0800 Subject: [PATCH 4/5] Update AbpDateTimeConverter.cs --- .../Volo/Abp/Json/Newtonsoft/AbpDateTimeConverter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpDateTimeConverter.cs b/framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpDateTimeConverter.cs index 8487321988..408f38e772 100644 --- a/framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpDateTimeConverter.cs +++ b/framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpDateTimeConverter.cs @@ -12,7 +12,7 @@ using Volo.Abp.Timing; namespace Volo.Abp.Json.Newtonsoft; -public class AbpDateTimeConverter : DateTimeConverterBase, ITransientDependency, IsoDateTimeConverter +public class AbpDateTimeConverter : DateTimeConverterBase, ITransientDependency { private const string DefaultDateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFFFK"; private readonly DateTimeStyles _dateTimeStyles = DateTimeStyles.RoundtripKind; From c523301d406580908d22580906287e8b5e7d210a Mon Sep 17 00:00:00 2001 From: maliming Date: Wed, 22 Mar 2023 15:03:21 +0800 Subject: [PATCH 5/5] Add `AbpValidateAuthorizedParty`. Resolve #15888 --- .../AbpOpenIddictAspNetCoreModule.cs | 3 ++ .../AbpOpenIddictWildcardDomainBase.cs | 9 ++--- .../AbpValidateAuthorizedParty.cs | 37 +++++++++++++++++++ .../AbpValidateClientPostLogoutRedirectUri.cs | 2 +- .../AbpValidateClientRedirectUri.cs | 2 +- ...pValidatePostLogoutRedirectUriParameter.cs | 2 +- .../AbpValidateRedirectUriParameter.cs | 2 +- 7 files changed, 47 insertions(+), 10 deletions(-) create mode 100644 modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/WildcardDomains/AbpValidateAuthorizedParty.cs diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/AbpOpenIddictAspNetCoreModule.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/AbpOpenIddictAspNetCoreModule.cs index d7eacfa498..8a664da5c1 100644 --- a/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/AbpOpenIddictAspNetCoreModule.cs +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/AbpOpenIddictAspNetCoreModule.cs @@ -127,6 +127,9 @@ public class AbpOpenIddictAspNetCoreModule : AbpModule builder.RemoveEventHandler(OpenIddictServerHandlers.Session.ValidatePostLogoutRedirectUriParameter.Descriptor); builder.AddEventHandler(AbpValidatePostLogoutRedirectUriParameter.Descriptor); + + builder.RemoveEventHandler(OpenIddictServerHandlers.Session.ValidateAuthorizedParty.Descriptor); + builder.AddEventHandler(AbpValidateAuthorizedParty.Descriptor); } builder.AddEventHandler(RemoveClaimsFromClientCredentialsGrantType.Descriptor); diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/WildcardDomains/AbpOpenIddictWildcardDomainBase.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/WildcardDomains/AbpOpenIddictWildcardDomainBase.cs index 2a603b8f44..8839871832 100644 --- a/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/WildcardDomains/AbpOpenIddictWildcardDomainBase.cs +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/WildcardDomains/AbpOpenIddictWildcardDomainBase.cs @@ -7,19 +7,16 @@ using Volo.Abp.Text.Formatting; namespace Volo.Abp.OpenIddict.WildcardDomains; public abstract class AbpOpenIddictWildcardDomainBase : IOpenIddictServerHandler - where THandler : class, new() + where THandler : class where TContext : OpenIddictServerEvents.BaseContext { protected THandler Handler { get; set; } protected AbpOpenIddictWildcardDomainOptions WildcardDomainOptions { get; } - protected AbpOpenIddictWildcardDomainBase(IOptions wildcardDomainOptions, bool initHandler = true) + protected AbpOpenIddictWildcardDomainBase(IOptions wildcardDomainOptions, THandler handler) { WildcardDomainOptions = wildcardDomainOptions.Value; - if (initHandler) - { - Handler = new THandler(); - } + Handler = handler; } public abstract ValueTask HandleAsync(TContext context); diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/WildcardDomains/AbpValidateAuthorizedParty.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/WildcardDomains/AbpValidateAuthorizedParty.cs new file mode 100644 index 0000000000..81c7d66788 --- /dev/null +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/WildcardDomains/AbpValidateAuthorizedParty.cs @@ -0,0 +1,37 @@ +using System.Threading.Tasks; +using Microsoft.Extensions.Options; +using OpenIddict.Abstractions; +using OpenIddict.Server; + +namespace Volo.Abp.OpenIddict.WildcardDomains; + +public class AbpValidateAuthorizedParty : AbpOpenIddictWildcardDomainBase +{ + public static OpenIddictServerHandlerDescriptor Descriptor { get; } + = OpenIddictServerHandlerDescriptor.CreateBuilder() + .UseScopedHandler() + .SetOrder(OpenIddictServerHandlers.Session.ValidateToken.Descriptor.Order + 1_000) + .SetType(OpenIddictServerHandlerType.BuiltIn) + .Build(); + + public AbpValidateAuthorizedParty( + IOptions wildcardDomainsOptions, + IOpenIddictApplicationManager applicationManager) + : base(wildcardDomainsOptions, new OpenIddictServerHandlers.Session.ValidateAuthorizedParty(applicationManager)) + { + Handler = new OpenIddictServerHandlers.Session.ValidateAuthorizedParty(applicationManager); + } + + public async override ValueTask HandleAsync(OpenIddictServerEvents.ValidateLogoutRequestContext context) + { + Check.NotNull(context, nameof(context)); + Check.NotNull(context.IdentityTokenHintPrincipal, nameof(context.IdentityTokenHintPrincipal)); + + if (await CheckWildcardDomainAsync(context.PostLogoutRedirectUri)) + { + return; + } + + await Handler.HandleAsync(context); + } +} diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/WildcardDomains/AbpValidateClientPostLogoutRedirectUri.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/WildcardDomains/AbpValidateClientPostLogoutRedirectUri.cs index 527eb05eb0..e1fe8b94f8 100644 --- a/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/WildcardDomains/AbpValidateClientPostLogoutRedirectUri.cs +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/WildcardDomains/AbpValidateClientPostLogoutRedirectUri.cs @@ -19,7 +19,7 @@ public class AbpValidateClientPostLogoutRedirectUri : AbpOpenIddictWildcardDomai public AbpValidateClientPostLogoutRedirectUri( IOptions wildcardDomainsOptions, IOpenIddictApplicationManager applicationManager) - : base(wildcardDomainsOptions, false) + : base(wildcardDomainsOptions, new OpenIddictServerHandlers.Session.ValidateClientPostLogoutRedirectUri(applicationManager)) { Handler = new OpenIddictServerHandlers.Session.ValidateClientPostLogoutRedirectUri(applicationManager); } diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/WildcardDomains/AbpValidateClientRedirectUri.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/WildcardDomains/AbpValidateClientRedirectUri.cs index 85d82a95ab..d2871a57cc 100644 --- a/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/WildcardDomains/AbpValidateClientRedirectUri.cs +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/WildcardDomains/AbpValidateClientRedirectUri.cs @@ -18,7 +18,7 @@ public class AbpValidateClientRedirectUri : AbpOpenIddictWildcardDomainBase wildcardDomainsOptions, IOpenIddictApplicationManager applicationManager) - : base(wildcardDomainsOptions, false) + : base(wildcardDomainsOptions, new OpenIddictServerHandlers.Authentication.ValidateClientRedirectUri()) { Handler = new OpenIddictServerHandlers.Authentication.ValidateClientRedirectUri(applicationManager); } diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/WildcardDomains/AbpValidatePostLogoutRedirectUriParameter.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/WildcardDomains/AbpValidatePostLogoutRedirectUriParameter.cs index 83f33d015c..c6bfc155b5 100644 --- a/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/WildcardDomains/AbpValidatePostLogoutRedirectUriParameter.cs +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/WildcardDomains/AbpValidatePostLogoutRedirectUriParameter.cs @@ -14,7 +14,7 @@ public class AbpValidatePostLogoutRedirectUriParameter : AbpOpenIddictWildcardDo .Build(); public AbpValidatePostLogoutRedirectUriParameter(IOptions wildcardDomainsOptions) - : base(wildcardDomainsOptions) + : base(wildcardDomainsOptions, new OpenIddictServerHandlers.Session.ValidatePostLogoutRedirectUriParameter()) { } diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/WildcardDomains/AbpValidateRedirectUriParameter.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/WildcardDomains/AbpValidateRedirectUriParameter.cs index 5354646b56..3bac84e2c4 100644 --- a/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/WildcardDomains/AbpValidateRedirectUriParameter.cs +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/WildcardDomains/AbpValidateRedirectUriParameter.cs @@ -14,7 +14,7 @@ public class AbpValidateRedirectUriParameter : AbpOpenIddictWildcardDomainBase wildcardDomainsOptions) - : base(wildcardDomainsOptions) + : base(wildcardDomainsOptions, new OpenIddictServerHandlers.Authentication.ValidateRedirectUriParameter()) { }