工具生成版本
This commit is contained in:
+10
@@ -0,0 +1,10 @@
|
||||
using Hua.Abp.Demo.Books;
|
||||
using Xunit;
|
||||
|
||||
namespace Hua.Abp.Demo.EntityFrameworkCore.Applications.Books;
|
||||
|
||||
[Collection(DemoTestConsts.CollectionDefinitionName)]
|
||||
public class EfCoreBookAppService_Tests : BookAppService_Tests<DemoEntityFrameworkCoreTestModule>
|
||||
{
|
||||
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
using Hua.Abp.Demo.Samples;
|
||||
using Xunit;
|
||||
|
||||
namespace Hua.Abp.Demo.EntityFrameworkCore.Applications;
|
||||
|
||||
[Collection(DemoTestConsts.CollectionDefinitionName)]
|
||||
public class EfCoreSampleAppServiceTests : SampleAppServiceTests<DemoEntityFrameworkCoreTestModule>
|
||||
{
|
||||
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
using Xunit;
|
||||
|
||||
namespace Hua.Abp.Demo.EntityFrameworkCore;
|
||||
|
||||
[CollectionDefinition(DemoTestConsts.CollectionDefinitionName)]
|
||||
public class DemoEntityFrameworkCoreCollection : ICollectionFixture<DemoEntityFrameworkCoreFixture>
|
||||
{
|
||||
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
using Hua.Abp.Demo.EntityFrameworkCore;
|
||||
using Xunit;
|
||||
|
||||
namespace Hua.Abp.Demo.EntityFrameworkCore;
|
||||
|
||||
public class DemoEntityFrameworkCoreCollectionFixtureBase : ICollectionFixture<DemoEntityFrameworkCoreFixture>
|
||||
{
|
||||
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace Hua.Abp.Demo.EntityFrameworkCore;
|
||||
|
||||
public class DemoEntityFrameworkCoreFixture : IDisposable
|
||||
{
|
||||
public void Dispose()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
using Volo.Abp;
|
||||
|
||||
namespace Hua.Abp.Demo.EntityFrameworkCore;
|
||||
|
||||
public abstract class DemoEntityFrameworkCoreTestBase : DemoTestBase<DemoEntityFrameworkCoreTestModule>
|
||||
{
|
||||
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
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.Uow;
|
||||
|
||||
namespace Hua.Abp.Demo.EntityFrameworkCore;
|
||||
|
||||
[DependsOn(
|
||||
typeof(DemoApplicationTestModule),
|
||||
typeof(DemoEntityFrameworkCoreModule),
|
||||
typeof(AbpEntityFrameworkCoreSqliteModule)
|
||||
)]
|
||||
public class DemoEntityFrameworkCoreTestModule : 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;
|
||||
});
|
||||
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 SqliteConnection("Data Source=:memory:");
|
||||
connection.Open();
|
||||
|
||||
var options = new DbContextOptionsBuilder<DemoDbContext>()
|
||||
.UseSqlite(connection)
|
||||
.Options;
|
||||
|
||||
using (var context = new DemoDbContext(options))
|
||||
{
|
||||
context.GetService<IRelationalDatabaseCreator>().CreateTables();
|
||||
}
|
||||
|
||||
return connection;
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
using Hua.Abp.Demo.Samples;
|
||||
using Xunit;
|
||||
|
||||
namespace Hua.Abp.Demo.EntityFrameworkCore.Domains;
|
||||
|
||||
[Collection(DemoTestConsts.CollectionDefinitionName)]
|
||||
public class EfCoreSampleDomainTests : SampleDomainTests<DemoEntityFrameworkCoreTestModule>
|
||||
{
|
||||
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Shouldly;
|
||||
using Volo.Abp.Domain.Repositories;
|
||||
using Volo.Abp.Identity;
|
||||
using Xunit;
|
||||
|
||||
namespace Hua.Abp.Demo.EntityFrameworkCore.Samples;
|
||||
|
||||
/* This is just an example test class.
|
||||
* Normally, you don't test ABP framework code
|
||||
* Only test your custom repository methods.
|
||||
*/
|
||||
[Collection(DemoTestConsts.CollectionDefinitionName)]
|
||||
public class SampleRepositoryTests : DemoEntityFrameworkCoreTestBase
|
||||
{
|
||||
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 _appUserRepository
|
||||
.FirstOrDefaultAsync(u => u.UserName == "admin");
|
||||
|
||||
//Assert
|
||||
adminUser.ShouldNotBeNull();
|
||||
});
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"role": "lib.test"
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="..\..\common.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>Hua.Abp.Demo</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Hua.Abp.Demo.EntityFrameworkCore\Hua.Abp.Demo.EntityFrameworkCore.csproj" />
|
||||
<ProjectReference Include="..\Hua.Abp.Demo.Application.Tests\Hua.Abp.Demo.Application.Tests.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Volo.Abp.EntityFrameworkCore.Sqlite" Version="10.0.1" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user