Browse Source

Merge pull request #16046 from abpframework/auto-merge/rel-7-1/1821

Merge branch dev with rel-7.1
pull/16053/head
maliming 3 years ago
committed by GitHub
parent
commit
f4e66e8070
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpDateTimeConverter.cs
  2. 3
      framework/test/Volo.Abp.Json.Tests/Volo.Abp.Json.Tests.csproj
  3. 2
      framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpIgnorePropertiesModifiers_Tests.cs
  4. 2
      framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpIncludeNonPublicPropertiesModifiers_Tests.cs
  5. 26
      framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpJsonNewtonsoftTestModule.cs
  6. 19
      framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpJsonSystemTextJsonTestBase.cs
  7. 11
      framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpJsonTestBase.cs
  8. 14
      framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpJsonTestModule.cs
  9. 16
      framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpSystemTextJsonSerializerProvider_Tests.cs
  10. 2
      framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/ExtensibleObjectModifiers_Tests.cs
  11. 2
      framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/ExtensibleObject_Tests.cs
  12. 112
      framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/InputAndOutputDateTimeFormat_Tests.cs
  13. 15
      npm/ng-packs/packages/core/src/lib/services/config-state.service.ts

11
framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpDateTimeConverter.cs

@ -14,7 +14,7 @@ namespace Volo.Abp.Json.Newtonsoft;
public class AbpDateTimeConverter : DateTimeConverterBase, ITransientDependency public class AbpDateTimeConverter : DateTimeConverterBase, ITransientDependency
{ {
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 DateTimeStyles _dateTimeStyles = DateTimeStyles.RoundtripKind;
private readonly CultureInfo _culture = CultureInfo.InvariantCulture; private readonly CultureInfo _culture = CultureInfo.InvariantCulture;
private readonly IClock _clock; private readonly IClock _clock;
@ -72,10 +72,7 @@ public class AbpDateTimeConverter : DateTimeConverterBase, ITransientDependency
} }
} }
var date = !_dateTimeFormat.IsNullOrEmpty() ? var date = DateTime.Parse(dateText, _culture, _dateTimeStyles);
DateTime.ParseExact(dateText, _dateTimeFormat, _culture, _dateTimeStyles) :
DateTime.Parse(dateText, _culture, _dateTimeStyles);
return _clock.Normalize(date); return _clock.Normalize(date);
} }
@ -95,7 +92,7 @@ public class AbpDateTimeConverter : DateTimeConverterBase, ITransientDependency
} }
writer.WriteValue(_options.OutputDateTimeFormat.IsNullOrWhiteSpace() writer.WriteValue(_options.OutputDateTimeFormat.IsNullOrWhiteSpace()
? dateTime.ToString(_dateTimeFormat, _culture) ? dateTime.ToString(DefaultDateTimeFormat, _culture)
: dateTime.ToString(_options.OutputDateTimeFormat, _culture)); : dateTime.ToString(_options.OutputDateTimeFormat, _culture));
} }
else 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) && if (property.PropertyType != typeof(DateTime) &&
property.PropertyType != typeof(DateTime?)) property.PropertyType != typeof(DateTime?))

3
framework/test/Volo.Abp.Json.Tests/Volo.Abp.Json.Tests.csproj

@ -9,7 +9,8 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNETTestSdkPackageVersion)" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNETTestSdkPackageVersion)" />
<ProjectReference Include="..\..\src\Volo.Abp.Json\Volo.Abp.Json.csproj" /> <ProjectReference Include="..\..\src\Volo.Abp.Json.Newtonsoft\Volo.Abp.Json.Newtonsoft.csproj" />
<ProjectReference Include="..\..\src\Volo.Abp.Json.SystemTextJson\Volo.Abp.Json.SystemTextJson.csproj" />
<ProjectReference Include="..\..\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" /> <ProjectReference Include="..\..\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" />
<ProjectReference Include="..\AbpTestBase\AbpTestBase.csproj" /> <ProjectReference Include="..\AbpTestBase\AbpTestBase.csproj" />
</ItemGroup> </ItemGroup>

2
framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpIgnorePropertiesModifiers_Tests.cs

@ -7,7 +7,7 @@ using Xunit;
namespace Volo.Abp.Json; namespace Volo.Abp.Json;
public class AbpIgnorePropertiesModifiers_Tests : AbpJsonTestBase public class AbpIgnorePropertiesModifiers_Tests : AbpJsonSystemTextJsonTestBase
{ {
private readonly IJsonSerializer _jsonSerializer; private readonly IJsonSerializer _jsonSerializer;

2
framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpIncludeNonPublicPropertiesModifiers_Tests.cs

@ -6,7 +6,7 @@ using Xunit;
namespace Volo.Abp.Json; namespace Volo.Abp.Json;
public class AbpIncludeNonPublicPropertiesModifiers_Tests : AbpJsonTestBase public class AbpIncludeNonPublicPropertiesModifiers_Tests : AbpJsonSystemTextJsonTestBase
{ {
private readonly IJsonSerializer _jsonSerializer; private readonly IJsonSerializer _jsonSerializer;

26
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
{
}

19
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<AbpJsonSystemTextJsonTestModule>
{
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options)
{
options.UseAutofac();
}
}
public abstract class AbpJsonNewtonsoftJsonTestBase : AbpIntegratedTest<AbpJsonNewtonsoftTestModule>
{
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options)
{
options.UseAutofac();
}
}

11
framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpJsonTestBase.cs

@ -1,11 +0,0 @@
using Volo.Abp.Testing;
namespace Volo.Abp.Json;
public abstract class AbpJsonTestBase : AbpIntegratedTest<AbpJsonTestModule>
{
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options)
{
options.UseAutofac();
}
}

14
framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpJsonTestModule.cs

@ -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
{
}

16
framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpSystemTextJsonSerializerProvider_Tests.cs

@ -9,11 +9,11 @@ using Xunit;
namespace Volo.Abp.Json; namespace Volo.Abp.Json;
public abstract class AbpSystemTextJsonSerializerProvider_TestBase : AbpJsonTestBase public abstract class AbpSystemTextJsonSerializerProviderTestBase : AbpJsonSystemTextJsonTestBase
{ {
protected AbpSystemTextJsonSerializer JsonSerializer; protected AbpSystemTextJsonSerializer JsonSerializer;
public AbpSystemTextJsonSerializerProvider_TestBase() public AbpSystemTextJsonSerializerProviderTestBase()
{ {
JsonSerializer = GetRequiredService<AbpSystemTextJsonSerializer>(); JsonSerializer = GetRequiredService<AbpSystemTextJsonSerializer>();
} }
@ -72,7 +72,7 @@ public abstract class AbpSystemTextJsonSerializerProvider_TestBase : AbpJsonTest
} }
} }
public class AbpSystemTextJsonSerializerProvider_Tests : AbpSystemTextJsonSerializerProvider_TestBase public class AbpSystemTextJsonSerializerProviderTests : AbpSystemTextJsonSerializerProviderTestBase
{ {
[Fact] [Fact]
public void Serialize_Deserialize_With_Boolean() 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) 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; 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) 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) 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
{ {
} }

2
framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/ExtensibleObjectModifiers_Tests.cs

@ -6,7 +6,7 @@ using Xunit;
namespace Volo.Abp.Json; namespace Volo.Abp.Json;
public class ExtensibleObjectModifiers_Tests : AbpJsonTestBase public class ExtensibleObjectModifiers_Tests : AbpJsonSystemTextJsonTestBase
{ {
[Fact] [Fact]
public void Should_Modify_Object() public void Should_Modify_Object()

2
framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/ExtensibleObject_Tests.cs

@ -7,7 +7,7 @@ using Xunit;
namespace Volo.Abp.Json; namespace Volo.Abp.Json;
public class ExtensibleObject_Tests : AbpJsonTestBase public class ExtensibleObject_Tests : AbpJsonSystemTextJsonTestBase
{ {
private readonly IJsonSerializer _jsonSerializer; private readonly IJsonSerializer _jsonSerializer;

112
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<IJsonSerializer>();
}
protected override void AfterAddApplication(IServiceCollection services)
{
services.Configure<AbpJsonOptions>(options =>
{
options.InputDateTimeFormats = new List<string>()
{
"yyyy*MM*dd",
"yyyy-MM-dd HH:mm:ss"
};
options.OutputDateTimeFormat = "yyyy*MM-dd HH:mm:ss";
});
services.Configure<AbpClockOptions>(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<DateTimeDto>("{\"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<IJsonSerializer>();
}
protected override void AfterAddApplication(IServiceCollection services)
{
services.Configure<AbpJsonOptions>(options =>
{
options.InputDateTimeFormats = new List<string>()
{
"yyyy*MM*dd",
"yyyy-MM-dd HH:mm:ss"
};
options.OutputDateTimeFormat = "yyyy*MM-dd HH:mm:ss";
});
services.Configure<AbpClockOptions>(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<DateTimeDto>("{\"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; }
}
}

15
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 { Observable, Subject } from 'rxjs';
import { map, switchMap, take, tap } from 'rxjs/operators'; import { map, switchMap, take, tap } from 'rxjs/operators';
import { AbpApplicationConfigurationService } from '../proxy/volo/abp/asp-net-core/mvc/application-configurations/abp-application-configuration.service'; 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 { export class ConfigStateService {
private readonly store = new InternalStore({} as ApplicationConfigurationDto); 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() { get createOnUpdateStream() {
return this.store.sliceUpdate; return this.store.sliceUpdate;
@ -25,7 +22,13 @@ export class ConfigStateService {
private updateSubject = new Subject<void>(); private updateSubject = new Subject<void>();
constructor() { constructor(
private abpConfigService: AbpApplicationConfigurationService,
private abpApplicationLocalizationService: AbpApplicationLocalizationService,
@Optional()
@Inject(INCUDE_LOCALIZATION_RESOURCES_TOKEN)
private readonly includeLocalizationResources: boolean | null,
) {
this.initUpdateStream(); this.initUpdateStream();
} }
@ -34,7 +37,7 @@ export class ConfigStateService {
.pipe( .pipe(
switchMap(() => switchMap(() =>
this.abpConfigService.get({ this.abpConfigService.get({
includeLocalizationResources: this.includeLocalizationResources, includeLocalizationResources: !!this.includeLocalizationResources,
}), }),
), ),
) )

Loading…
Cancel
Save