26 lines
1.0 KiB
C#
26 lines
1.0 KiB
C#
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
using NSubstitute;
|
|
using ZB.MOM.WW.ScadaBridge.CentralUI.Services;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Services;
|
|
|
|
namespace Microsoft.Extensions.DependencyInjection;
|
|
|
|
internal static class ConfigurationMutationTestExtensions
|
|
{
|
|
public static IServiceCollection AddTestConfigurationMutations(this IServiceCollection services)
|
|
{
|
|
services.TryAddScoped<ConfigurationCommandService>();
|
|
services.TryAddSingleton<IAuditService>(_ => Substitute.For<IAuditService>());
|
|
services.TryAddSingleton<IConfigurationCommandTransaction, RepositoryTransaction>();
|
|
return services;
|
|
}
|
|
private sealed class RepositoryTransaction(IServiceScopeFactory scopes) : IConfigurationCommandTransaction
|
|
{
|
|
public async Task<object?> ExecuteAsync(Func<IServiceProvider, Task<object?>> operation)
|
|
{
|
|
using var scope = scopes.CreateScope();
|
|
return await operation(scope.ServiceProvider);
|
|
}
|
|
}
|
|
}
|