mirror of https://github.com/abpframework/abp.git
committed by
GitHub
3 changed files with 83 additions and 6 deletions
@ -1,12 +1,26 @@ |
|||||
using System; |
using System; |
||||
using System.Threading.Tasks; |
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Uow; |
||||
|
|
||||
namespace Volo.Abp.Data; |
namespace Volo.Abp.Data; |
||||
|
|
||||
public static class DataSeederExtensions |
public static class DataSeederExtensions |
||||
{ |
{ |
||||
|
public const string SeedInSeparateUow = "__SeedInSeparateUow"; |
||||
|
public const string SeedInSeparateUowOptions = "__SeedInSeparateUowOptions"; |
||||
|
public const string SeedInSeparateUowRequiresNew = "__SeedInSeparateUowRequiresNew"; |
||||
|
|
||||
public static Task SeedAsync(this IDataSeeder seeder, Guid? tenantId = null) |
public static Task SeedAsync(this IDataSeeder seeder, Guid? tenantId = null) |
||||
{ |
{ |
||||
return seeder.SeedAsync(new DataSeedContext(tenantId)); |
return seeder.SeedAsync(new DataSeedContext(tenantId)); |
||||
} |
} |
||||
|
|
||||
|
public static Task SeedInSeparateUowAsync(this IDataSeeder seeder, Guid? tenantId = null, AbpUnitOfWorkOptions options = null, bool requiresNew = false) |
||||
|
{ |
||||
|
var context = new DataSeedContext(tenantId); |
||||
|
context.WithProperty(SeedInSeparateUow, true); |
||||
|
context.WithProperty(SeedInSeparateUowOptions, options); |
||||
|
context.WithProperty(SeedInSeparateUowRequiresNew, requiresNew); |
||||
|
return seeder.SeedAsync(context); |
||||
|
} |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,43 @@ |
|||||
|
using System; |
||||
|
using System.Data; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.DependencyInjection.Extensions; |
||||
|
using NSubstitute; |
||||
|
using Volo.Abp.Modularity; |
||||
|
using Volo.Abp.Testing; |
||||
|
using Volo.Abp.Uow; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Volo.Abp.Data; |
||||
|
|
||||
|
public class DataSeederExtensions_Tests : AbpIntegratedTest<DataSeederExtensions_Tests.TestModule> |
||||
|
{ |
||||
|
private IDataSeeder _dataSeeder; |
||||
|
|
||||
|
protected override void AfterAddApplication(IServiceCollection services) |
||||
|
{ |
||||
|
_dataSeeder = Substitute.For<IDataSeeder>(); |
||||
|
services.Replace(ServiceDescriptor.Singleton(_dataSeeder)); |
||||
|
base.AfterAddApplication(services); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void SeedInSeparateUowAsync() |
||||
|
{ |
||||
|
var tenantId = Guid.NewGuid(); |
||||
|
_dataSeeder.SeedInSeparateUowAsync(tenantId, new AbpUnitOfWorkOptions(true, IsolationLevel.Serializable, 888), true); |
||||
|
|
||||
|
_dataSeeder.Received().SeedAsync(Arg.Is<DataSeedContext>(x => x.TenantId == tenantId && |
||||
|
x.Properties[DataSeederExtensions.SeedInSeparateUow].To<bool>() == true && |
||||
|
x.Properties[DataSeederExtensions.SeedInSeparateUowOptions].As<AbpUnitOfWorkOptions>().IsTransactional == true && |
||||
|
x.Properties[DataSeederExtensions.SeedInSeparateUowOptions].As<AbpUnitOfWorkOptions>().IsolationLevel == IsolationLevel.Serializable && |
||||
|
x.Properties[DataSeederExtensions.SeedInSeparateUowOptions].As<AbpUnitOfWorkOptions>().Timeout == 888 && |
||||
|
x.Properties[DataSeederExtensions.SeedInSeparateUowRequiresNew].To<bool>() == true)); |
||||
|
} |
||||
|
|
||||
|
[DependsOn(typeof(AbpDataModule))] |
||||
|
public class TestModule : AbpModule |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue