first commit
This commit is contained in:
@ -0,0 +1,31 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="..\..\common.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>KonSoft.TenantManagement</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Volo.Abp.TestBase" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.Autofac" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.Authorization" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.BackgroundJobs.Abstractions" Version="8.3.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||
<PackageReference Include="NSubstitute" Version="5.1.0" />
|
||||
<PackageReference Include="NSubstitute.Analyzers.CSharp" Version="1.0.16">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Shouldly" Version="4.2.1" />
|
||||
<PackageReference Include="xunit" Version="2.6.1" />
|
||||
<PackageReference Include="xunit.extensibility.execution" Version="2.6.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@ -0,0 +1,25 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Claims;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
using Volo.Abp.Security.Claims;
|
||||
|
||||
namespace KonSoft.TenantManagement.Security;
|
||||
|
||||
[Dependency(ReplaceServices = true)]
|
||||
public class FakeCurrentPrincipalAccessor : ThreadCurrentPrincipalAccessor
|
||||
{
|
||||
protected override ClaimsPrincipal GetClaimsPrincipal()
|
||||
{
|
||||
return GetPrincipal();
|
||||
}
|
||||
|
||||
private ClaimsPrincipal GetPrincipal()
|
||||
{
|
||||
return new ClaimsPrincipal(new ClaimsIdentity(new List<Claim>
|
||||
{
|
||||
new Claim(AbpClaimTypes.UserId, "2e701e62-0953-4dd3-910b-dc6cc93ccb0d"),
|
||||
new Claim(AbpClaimTypes.UserName, "admin"),
|
||||
new Claim(AbpClaimTypes.Email, "admin@abp.io")
|
||||
}));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Volo.Abp;
|
||||
using Volo.Abp.Modularity;
|
||||
using Volo.Abp.Uow;
|
||||
using Volo.Abp.Testing;
|
||||
|
||||
namespace KonSoft.TenantManagement;
|
||||
|
||||
/* All test classes are derived from this class, directly or indirectly.
|
||||
*/
|
||||
public abstract class TenantManagementTestBase<TStartupModule> : AbpIntegratedTest<TStartupModule>
|
||||
where TStartupModule : IAbpModule
|
||||
{
|
||||
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options)
|
||||
{
|
||||
options.UseAutofac();
|
||||
}
|
||||
|
||||
protected virtual Task WithUnitOfWorkAsync(Func<Task> func)
|
||||
{
|
||||
return WithUnitOfWorkAsync(new AbpUnitOfWorkOptions(), func);
|
||||
}
|
||||
|
||||
protected virtual async Task WithUnitOfWorkAsync(AbpUnitOfWorkOptions options, Func<Task> action)
|
||||
{
|
||||
using (var scope = ServiceProvider.CreateScope())
|
||||
{
|
||||
var uowManager = scope.ServiceProvider.GetRequiredService<IUnitOfWorkManager>();
|
||||
|
||||
using (var uow = uowManager.Begin(options))
|
||||
{
|
||||
await action();
|
||||
|
||||
await uow.CompleteAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual Task<TResult> WithUnitOfWorkAsync<TResult>(Func<Task<TResult>> func)
|
||||
{
|
||||
return WithUnitOfWorkAsync(new AbpUnitOfWorkOptions(), func);
|
||||
}
|
||||
|
||||
protected virtual async Task<TResult> WithUnitOfWorkAsync<TResult>(AbpUnitOfWorkOptions options, Func<Task<TResult>> func)
|
||||
{
|
||||
using (var scope = ServiceProvider.CreateScope())
|
||||
{
|
||||
var uowManager = scope.ServiceProvider.GetRequiredService<IUnitOfWorkManager>();
|
||||
|
||||
using (var uow = uowManager.Begin(options))
|
||||
{
|
||||
var result = await func();
|
||||
await uow.CompleteAsync();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,47 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Volo.Abp;
|
||||
using Volo.Abp.Authorization;
|
||||
using Volo.Abp.Autofac;
|
||||
using Volo.Abp.BackgroundJobs;
|
||||
using Volo.Abp.Data;
|
||||
using Volo.Abp.Modularity;
|
||||
using Volo.Abp.Threading;
|
||||
|
||||
namespace KonSoft.TenantManagement;
|
||||
|
||||
[DependsOn(
|
||||
typeof(AbpAutofacModule),
|
||||
typeof(AbpTestBaseModule),
|
||||
typeof(AbpAuthorizationModule),
|
||||
typeof(AbpBackgroundJobsAbstractionsModule)
|
||||
)]
|
||||
public class TenantManagementTestBaseModule : AbpModule
|
||||
{
|
||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
Configure<AbpBackgroundJobOptions>(options =>
|
||||
{
|
||||
options.IsJobExecutionEnabled = false;
|
||||
});
|
||||
|
||||
context.Services.AddAlwaysAllowAuthorization();
|
||||
}
|
||||
|
||||
public override void OnApplicationInitialization(ApplicationInitializationContext context)
|
||||
{
|
||||
SeedTestData(context);
|
||||
}
|
||||
|
||||
private static void SeedTestData(ApplicationInitializationContext context)
|
||||
{
|
||||
AsyncHelper.RunSync(async () =>
|
||||
{
|
||||
using (var scope = context.ServiceProvider.CreateScope())
|
||||
{
|
||||
await scope.ServiceProvider
|
||||
.GetRequiredService<IDataSeeder>()
|
||||
.SeedAsync();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,6 @@
|
||||
namespace KonSoft.TenantManagement;
|
||||
|
||||
public static class TenantManagementTestConsts
|
||||
{
|
||||
public const string CollectionDefinitionName = "TenantManagement collection";
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
using System.Threading.Tasks;
|
||||
using Volo.Abp.Data;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
|
||||
namespace KonSoft.TenantManagement;
|
||||
|
||||
public class TenantManagementTestDataSeedContributor : IDataSeedContributor, ITransientDependency
|
||||
{
|
||||
public Task SeedAsync(DataSeedContext context)
|
||||
{
|
||||
/* Seed additional test data... */
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user