first commit

This commit is contained in:
2025-09-08 14:15:45 +08:00
commit 0ecba9619f
622 changed files with 37941 additions and 0 deletions

View File

@ -0,0 +1,10 @@
using KonSoft.TenantManagement.Samples;
using Xunit;
namespace KonSoft.TenantManagement.EntityFrameworkCore.Applications;
[Collection(TenantManagementTestConsts.CollectionDefinitionName)]
public class EfCoreSampleAppServiceTests : SampleAppServiceTests<TenantManagementEntityFrameworkCoreTestModule>
{
}

View File

@ -0,0 +1,10 @@
using KonSoft.TenantManagement.Samples;
using Xunit;
namespace KonSoft.TenantManagement.EntityFrameworkCore.Domains;
[Collection(TenantManagementTestConsts.CollectionDefinitionName)]
public class EfCoreSampleDomainTests : SampleDomainTests<TenantManagementEntityFrameworkCoreTestModule>
{
}

View File

@ -0,0 +1,44 @@
using Microsoft.EntityFrameworkCore;
using Shouldly;
using System;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Identity;
using Xunit;
namespace KonSoft.TenantManagement.EntityFrameworkCore.Samples;
/* This is just an example test class.
* Normally, you don't test ABP framework code
* (like default AppUser repository IRepository<AppUser, Guid> here).
* Only test your custom repository methods.
*/
[Collection(TenantManagementTestConsts.CollectionDefinitionName)]
public class SampleRepositoryTests : TenantManagementEntityFrameworkCoreTestBase
{
private readonly IRepository<IdentityUser, Guid> _appUserRepository;
public SampleRepositoryTests()
{
_appUserRepository = GetRequiredService<IRepository<IdentityUser, Guid>>();
}
[Fact]
public async Task Should_Query_AppUser()
{
/* Need to manually start Unit Of Work because
* FirstOrDefaultAsync should be executed while db connection / context is available.
*/
await WithUnitOfWorkAsync(async () =>
{
//Act
var adminUser = await (await _appUserRepository.GetQueryableAsync())
.Where(u => u.UserName == "admin")
.FirstOrDefaultAsync();
//Assert
adminUser.ShouldNotBeNull();
});
}
}

View File

@ -0,0 +1,9 @@
using Xunit;
namespace KonSoft.TenantManagement.EntityFrameworkCore;
[CollectionDefinition(TenantManagementTestConsts.CollectionDefinitionName)]
public class TenantManagementEntityFrameworkCoreCollection : ICollectionFixture<TenantManagementEntityFrameworkCoreFixture>
{
}

View File

@ -0,0 +1,9 @@
using KonSoft.TenantManagement.EntityFrameworkCore;
using Xunit;
namespace KonSoft.TenantManagement.EntityFrameworkCore;
public class TenantManagementEntityFrameworkCoreCollectionFixtureBase : ICollectionFixture<TenantManagementEntityFrameworkCoreFixture>
{
}

View File

@ -0,0 +1,11 @@
using System;
namespace KonSoft.TenantManagement.EntityFrameworkCore;
public class TenantManagementEntityFrameworkCoreFixture : IDisposable
{
public void Dispose()
{
}
}

View File

@ -0,0 +1,8 @@
using Volo.Abp;
namespace KonSoft.TenantManagement.EntityFrameworkCore;
public abstract class TenantManagementEntityFrameworkCoreTestBase : TenantManagementTestBase<TenantManagementEntityFrameworkCoreTestModule>
{
}

View File

@ -0,0 +1,82 @@
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.Sqlite;
using Volo.Abp.FeatureManagement;
using Volo.Abp.Modularity;
using Volo.Abp.PermissionManagement;
using Volo.Abp.SettingManagement;
using Volo.Abp.Uow;
namespace KonSoft.TenantManagement.EntityFrameworkCore;
[DependsOn(
typeof(TenantManagementApplicationTestModule),
typeof(TenantManagementEntityFrameworkCoreModule),
typeof(AbpEntityFrameworkCoreSqliteModule)
)]
public class TenantManagementEntityFrameworkCoreTestModule : AbpModule
{
private SqliteConnection? _sqliteConnection;
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<FeatureManagementOptions>(options =>
{
options.SaveStaticFeaturesToDatabase = false;
options.IsDynamicFeatureStoreEnabled = false;
});
Configure<PermissionManagementOptions>(options =>
{
options.SaveStaticPermissionsToDatabase = false;
options.IsDynamicPermissionStoreEnabled = false;
});
Configure<SettingManagementOptions>(options =>
{
options.SaveStaticSettingsToDatabase = false;
options.IsDynamicSettingStoreEnabled = false;
});
context.Services.AddAlwaysDisableUnitOfWorkTransaction();
ConfigureInMemorySqlite(context.Services);
}
private void ConfigureInMemorySqlite(IServiceCollection services)
{
_sqliteConnection = CreateDatabaseAndGetConnection();
services.Configure<AbpDbContextOptions>(options =>
{
options.Configure(context =>
{
context.DbContextOptions.UseSqlite(_sqliteConnection);
});
});
}
public override void OnApplicationShutdown(ApplicationShutdownContext context)
{
_sqliteConnection?.Dispose();
}
private static SqliteConnection CreateDatabaseAndGetConnection()
{
var connection = new AbpUnitTestSqliteConnection("Data Source=:memory:");
connection.Open();
var options = new DbContextOptionsBuilder<TenantManagementDbContext>()
.UseSqlite(connection)
.Options;
using (var context = new TenantManagementDbContext(options))
{
context.GetService<IRelationalDatabaseCreator>().CreateTables();
}
return connection;
}
}

View File

@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\common.props" />
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<RootNamespace>KonSoft.TenantManagement</RootNamespace>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\KonSoft.TenantManagement.EntityFrameworkCore\KonSoft.TenantManagement.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\KonSoft.TenantManagement.Application.Tests\KonSoft.TenantManagement.Application.Tests.csproj" />
<PackageReference Include="Volo.Abp.EntityFrameworkCore.Sqlite" Version="8.3.4" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
</ItemGroup>
</Project>