using System; using System.Threading.Tasks; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Volo.Abp; using Volo.Abp.Modularity; using Volo.Abp.Uow; using Volo.Abp.Testing; namespace Skcks.Study.AbpProject; public abstract class AbpProjectTestBase : AbpIntegratedTest where TStartupModule : IAbpModule { protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) { options.UseAutofac(); } protected override void BeforeAddApplication(IServiceCollection services) { var builder = new ConfigurationBuilder(); builder.AddJsonFile("appsettings.json", false); builder.AddJsonFile("appsettings.secrets.json", true); services.ReplaceConfiguration(builder.Build()); } protected virtual Task WithUnitOfWorkAsync(Func func) { return WithUnitOfWorkAsync(new AbpUnitOfWorkOptions(), func); } protected virtual async Task WithUnitOfWorkAsync(AbpUnitOfWorkOptions options, Func action) { using (var scope = ServiceProvider.CreateScope()) { var uowManager = scope.ServiceProvider.GetRequiredService(); using (var uow = uowManager.Begin(options)) { await action(); await uow.CompleteAsync(); } } } protected virtual Task WithUnitOfWorkAsync(Func> func) { return WithUnitOfWorkAsync(new AbpUnitOfWorkOptions(), func); } protected virtual async Task WithUnitOfWorkAsync(AbpUnitOfWorkOptions options, Func> func) { using (var scope = ServiceProvider.CreateScope()) { var uowManager = scope.ServiceProvider.GetRequiredService(); using (var uow = uowManager.Begin(options)) { var result = await func(); await uow.CompleteAsync(); return result; } } } }