feat: 完成测试框架搭建

This commit is contained in:
陈淳
2024-01-19 17:45:11 +08:00
parent d604e9c3f3
commit 7e895403a9
10 changed files with 288 additions and 9 deletions

View File

@@ -0,0 +1,18 @@
using Shouldly;
using Xunit;
using Yi.Framework.Rbac.Application.Contracts.IServices;
using Yi.Framework.Rbac.Domain.Shared.Consts;
namespace Yi.Abp.Test.Application
{
public class User_Test : YiAbpTestBase
{
[Fact]
public async Task Get_User_List_Test()
{
var service = GetRequiredService<IUserService>();
var user = await service.GetListAsync(new Framework.Rbac.Application.Contracts.Dtos.User.UserGetListInputVo { UserName = UserConst.Admin });
user.ShouldNotBeNull();
}
}
}

View File

@@ -0,0 +1,46 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\common.props" />
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<None Remove="appsettings.Development.json" />
<None Remove="appsettings.json" />
</ItemGroup>
<ItemGroup>
<Content Include="appsettings.Development.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<Content Include="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Volo.Abp.Autofac" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="NSubstitute" Version="4.3.0" />
<PackageReference Include="NSubstitute.Analyzers.CSharp" Version="1.0.15">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Shouldly" Version="4.1.0" />
<PackageReference Include="Volo.Abp.TestBase" Version="8.0.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.extensibility.execution" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Yi.Abp.Application\Yi.Abp.Application.csproj" />
<ProjectReference Include="..\..\src\Yi.Abp.SqlSugarCore\Yi.Abp.SqlSugarCore.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,56 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Volo.Abp;
using Yi.Framework.Rbac.Domain.Repositories;
using Yi.Framework.Rbac.SqlSugarCore.Repositories;
namespace Yi.Abp.Test
{
public class YiAbpTestBase :AbpTestBaseWithServiceProvider
{
public ILogger Logger { get; private set; }
protected IServiceScope TestServiceScope { get; }
public YiAbpTestBase()
{
IAbpApplicationWithExternalServiceProvider application = null;
IHost host = Host.CreateDefaultBuilder()
.UseAutofac()
.ConfigureServices((host, service) =>
{
service.AddLogging(builder => builder.ClearProviders().AddConsole().AddDebug());
/*application= */
service.AddApplicationAsync<YiAbpTestModule>().Wait();
this.ConfigureServices(host, service);
})
.ConfigureAppConfiguration(this.ConfigureAppConfiguration)
.Build();
this.ServiceProvider = host.Services;
this.TestServiceScope = ServiceProvider.CreateScope();
this.Logger = (ILogger)this.ServiceProvider.GetRequiredService(typeof(ILogger<>).MakeGenericType(this.GetType()));
//host.InitializeAsync().Wait();
this.Configure();
}
protected virtual void ConfigureServices(HostBuilderContext context, IServiceCollection services)
{
services.AddTransient<IUserRepository, UserRepository>();
}
protected virtual void ConfigureAppConfiguration(IConfigurationBuilder configurationBuilder)
{
configurationBuilder.AddJsonFile("appsettings.json");
//configurationBuilder.AddJsonFile("appsettings.Development.json");
}
protected virtual void Configure()
{
}
}
}

View File

@@ -0,0 +1,28 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
using Volo.Abp.Auditing;
using Volo.Abp.Authorization;
using Volo.Abp.Autofac;
using Volo.Abp.Modularity;
using Yi.Abp.Application;
using Yi.Abp.SqlsugarCore;
using Yi.Framework.Rbac.SqlSugarCore;
using Yi.Framework.SqlSugarCore;
namespace Yi.Abp.Test
{
[DependsOn(
typeof(YiAbpSqlSugarCoreModule),
typeof(YiAbpApplicationModule),
typeof(AbpAutofacModule),
typeof(AbpAuditingModule)
)]
public class YiAbpTestModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.GetConfiguration();
}
}
}

View File

@@ -0,0 +1,42 @@
{
//Rbac模块
"RbacOptions": {
//超级管理员种子数据默认密码
"AdminPassword": "cc2016cc",
//是否开启验证码验证
"EnableCaptcha": false,
//是否开启注册功能
"EnableRegister": true,
//开启定时数据库备份
"EnableDataBaseBackup": true
},
"DbConnOptions": {
"Url": "server=106.52.94.217;port=3306;database=yi-abp-pro;user id=root;password=Qz52013142020.",
//"Url": "server=localhost;port=3306;database=yi-abp-pro;user id=root;password=root",
"DbType": "Mysql",
"EnabledReadWrite": false,
"EnabledCodeFirst": false,
"EnabledSqlLog": true,
"EnabledDbSeed": false
//读写分离地址
//"ReadUrl": [
// "DataSource=[xxxx]", //Sqlite
// "server=[xxxx];port=3306;database=[xxxx];user id=[xxxx];password=[xxxx]", //Mysql
// "Data Source=[xxxx];Initial Catalog=[xxxx];User ID=[xxxx];password=[xxxx]" //Sqlserver
//]
},
//阿里云配置
"AliyunOptions": {
"AccessKeyId": "LTAI5tGdhAvUMzJtgcAz1yrZ",
"AccessKeySecret": "NuqdEs3Jf0lAs30JP7d4T7jvI1AFgr",
"Sms": {
"SignName": "ccnetcore",
"TemplateCode": "SMS_275415076"
}
}
}

View File

@@ -0,0 +1,71 @@
{
"Logging": {
"LogLevel": {
//"Default": "Information",
"Default": "Debug",
"Microsoft.AspNetCore": "Warning"
}
},
//应用启动
"App": {
"SelfUrl": "http://*:19001",
"CorsOrigins": "http://localhost:19001;http://localhost:18000"
},
//数据库类型列表
"DbList": [ "Sqlite", "Mysql", "Sqlserver", "Oracle" ],
"DbConnOptions": {
"Url": "DataSource=yi-abp-dev.db",
"DbType": "Sqlite",
"EnabledReadWrite": false,
"EnabledCodeFirst": true,
"EnabledSqlLog": true,
"EnabledDbSeed": true
//读写分离地址
//"ReadUrl": [
// "DataSource=[xxxx]", //Sqlite
// "server=[xxxx];port=3306;database=[xxxx];user id=[xxxx];password=[xxxx]", //Mysql
// "Data Source=[xxxx];Initial Catalog=[xxxx];User ID=[xxxx];password=[xxxx]" //Sqlserver
//]
},
//鉴权
"JwtOptions": {
"Issuer": "https://ccnetcore.com",
"Audience": "https://ccnetcore.com",
"SecurityKey": "zqxwcevrbtnymu312412ihe9rfwhe78rh23djoi32hrui3ryf9e8wfh34iuj54y0934uti4h97fgw7hf97wyh8yy69520",
"ExpiresMinuteTime": 86400
},
//第三方登录
"OAuth": {
//QQ
"QQ": {
"ClientId": "",
"ClientSecret": "",
"RedirectUri": ""
},
//码云
"Gitee": {
"ClientId": "",
"ClientSecret": "",
"RedirectUri": ""
}
},
//Rbac模块
"RbacOptions": {
//超级管理员种子数据默认密码
"AdminPassword": "123456",
//是否开启验证码验证
"EnableCaptcha": true,
//是否开启注册功能
"EnableRegister": false,
//开启定时数据库备份
"EnableDataBaseBackup": false
}
}