Browse Source
Merge pull request #20130 from abpframework/AbpIntegratedTest
Dispose `RootServiceProvider ` after unit testing.
pull/20141/head
Engincan VESKE
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with
40 additions and
13 deletions
-
framework/src/Volo.Abp.Autofac/Autofac/Builder/AbpRegistrationBuilderExtensions.cs
-
framework/src/Volo.Abp.Json.SystemTextJson/Volo/Abp/Json/SystemTextJson/AbpJsonSystemTextJsonModule.cs
-
framework/src/Volo.Abp.Json.SystemTextJson/Volo/Abp/Json/SystemTextJson/Modifiers/AbpDateTimeConverterModifier.cs
-
framework/src/Volo.Abp.TestBase/Volo/Abp/Testing/AbpAsyncIntegratedTest.cs
-
framework/src/Volo.Abp.TestBase/Volo/Abp/Testing/AbpIntegratedTest.cs
-
framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpDateTimeConverter_Tests.cs
|
|
|
@ -50,14 +50,18 @@ public static class AbpRegistrationBuilderExtensions |
|
|
|
ServiceDescriptor serviceDescriptor) |
|
|
|
where TActivatorData : ReflectionActivatorData |
|
|
|
{ |
|
|
|
registrationBuilder.OnActivated(context => |
|
|
|
var actions = activatedActionList.GetActions(serviceDescriptor); |
|
|
|
if (actions.Any()) |
|
|
|
{ |
|
|
|
var serviceActivatedContext = new OnServiceActivatedContext(context.Instance!); |
|
|
|
foreach (var action in activatedActionList.GetActions(serviceDescriptor)) |
|
|
|
registrationBuilder.OnActivated(context => |
|
|
|
{ |
|
|
|
action.Invoke(serviceActivatedContext); |
|
|
|
} |
|
|
|
}); |
|
|
|
var serviceActivatedContext = new OnServiceActivatedContext(context.Instance!); |
|
|
|
foreach (var action in actions) |
|
|
|
{ |
|
|
|
action.Invoke(serviceActivatedContext); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
return registrationBuilder; |
|
|
|
} |
|
|
|
|
|
|
|
@ -34,7 +34,9 @@ public class AbpJsonSystemTextJsonModule : AbpModule |
|
|
|
context.Services.AddOptions<AbpSystemTextJsonSerializerModifiersOptions>() |
|
|
|
.Configure<IServiceProvider>((options, rootServiceProvider) => |
|
|
|
{ |
|
|
|
options.Modifiers.Add(new AbpDateTimeConverterModifier().CreateModifyAction(rootServiceProvider)); |
|
|
|
options.Modifiers.Add(new AbpDateTimeConverterModifier( |
|
|
|
rootServiceProvider.GetRequiredService<AbpDateTimeConverter>(), |
|
|
|
rootServiceProvider.GetRequiredService<AbpNullableDateTimeConverter>()).CreateModifyAction()); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -10,11 +10,17 @@ namespace Volo.Abp.Json.SystemTextJson.Modifiers; |
|
|
|
|
|
|
|
public class AbpDateTimeConverterModifier |
|
|
|
{ |
|
|
|
private IServiceProvider _serviceProvider = default!; |
|
|
|
private readonly AbpDateTimeConverter _abpDateTimeConverter; |
|
|
|
private readonly AbpNullableDateTimeConverter _abpNullableDateTimeConverter; |
|
|
|
|
|
|
|
public Action<JsonTypeInfo> CreateModifyAction(IServiceProvider serviceProvider) |
|
|
|
public AbpDateTimeConverterModifier(AbpDateTimeConverter abpDateTimeConverter, AbpNullableDateTimeConverter abpNullableDateTimeConverter) |
|
|
|
{ |
|
|
|
_abpDateTimeConverter = abpDateTimeConverter; |
|
|
|
_abpNullableDateTimeConverter = abpNullableDateTimeConverter; |
|
|
|
} |
|
|
|
|
|
|
|
public Action<JsonTypeInfo> CreateModifyAction() |
|
|
|
{ |
|
|
|
_serviceProvider = serviceProvider; |
|
|
|
return Modify; |
|
|
|
} |
|
|
|
|
|
|
|
@ -31,8 +37,8 @@ public class AbpDateTimeConverterModifier |
|
|
|
!property.AttributeProvider.GetCustomAttributes(typeof(DisableDateTimeNormalizationAttribute), false).Any()) |
|
|
|
{ |
|
|
|
property.CustomConverter = property.PropertyType == typeof(DateTime) |
|
|
|
? _serviceProvider.GetRequiredService<AbpDateTimeConverter>() |
|
|
|
: _serviceProvider.GetRequiredService<AbpNullableDateTimeConverter>(); |
|
|
|
? _abpDateTimeConverter |
|
|
|
: _abpNullableDateTimeConverter; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -34,6 +34,10 @@ public class AbpAsyncIntegratedTest<TStartupModule> : AbpTestBaseWithServiceProv |
|
|
|
public virtual async Task DisposeAsync() |
|
|
|
{ |
|
|
|
await Application.ShutdownAsync(); |
|
|
|
if (RootServiceProvider is IDisposable disposable) |
|
|
|
{ |
|
|
|
disposable.Dispose(); |
|
|
|
} |
|
|
|
TestServiceScope.Dispose(); |
|
|
|
Application.Dispose(); |
|
|
|
} |
|
|
|
|
|
|
|
@ -60,6 +60,10 @@ public abstract class AbpIntegratedTest<TStartupModule> : AbpTestBaseWithService |
|
|
|
{ |
|
|
|
Application.Shutdown(); |
|
|
|
TestServiceScope.Dispose(); |
|
|
|
if (RootServiceProvider is IDisposable disposable) |
|
|
|
{ |
|
|
|
disposable.Dispose(); |
|
|
|
} |
|
|
|
Application.Dispose(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -3,6 +3,7 @@ using System.Globalization; |
|
|
|
using System.Text.Json; |
|
|
|
using System.Text.Json.Serialization.Metadata; |
|
|
|
using Shouldly; |
|
|
|
using Volo.Abp.Json.SystemTextJson.JsonConverters; |
|
|
|
using Volo.Abp.Json.SystemTextJson.Modifiers; |
|
|
|
using Volo.Abp.Localization; |
|
|
|
using Xunit; |
|
|
|
@ -21,7 +22,13 @@ public class AbpDatetimeToEnum_Tests : AbpJsonSystemTextJsonTestBase |
|
|
|
{ |
|
|
|
TypeInfoResolver = new DefaultJsonTypeInfoResolver() |
|
|
|
{ |
|
|
|
Modifiers = { new AbpDateTimeConverterModifier().CreateModifyAction(ServiceProvider) } |
|
|
|
Modifiers = |
|
|
|
{ |
|
|
|
new AbpDateTimeConverterModifier( |
|
|
|
GetRequiredService<AbpDateTimeConverter>(), |
|
|
|
GetRequiredService<AbpNullableDateTimeConverter>()) |
|
|
|
.CreateModifyAction() |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
|