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

@@ -88,6 +88,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Acme.BookStore.Application"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Acme.BookStore.SqlSugarCore", "sample\Acme.BookStore.SqlSugarCore\Acme.BookStore.SqlSugarCore.csproj", "{70CCBD89-C0A1-4AC8-9AFA-C86C356DFDD7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Abp.Test", "test\Yi.Abp.Test\Yi.Abp.Test.csproj", "{68627BC2-F049-4C69-AD17-81DF9478E8CE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -218,6 +220,10 @@ Global
{70CCBD89-C0A1-4AC8-9AFA-C86C356DFDD7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{70CCBD89-C0A1-4AC8-9AFA-C86C356DFDD7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{70CCBD89-C0A1-4AC8-9AFA-C86C356DFDD7}.Release|Any CPU.Build.0 = Release|Any CPU
{68627BC2-F049-4C69-AD17-81DF9478E8CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{68627BC2-F049-4C69-AD17-81DF9478E8CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{68627BC2-F049-4C69-AD17-81DF9478E8CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{68627BC2-F049-4C69-AD17-81DF9478E8CE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -257,6 +263,7 @@ Global
{20827DB5-5CDE-491A-82E8-3CAB82618C1E} = {01300F0F-686E-47B3-821D-12424177867B}
{320273B6-7AE3-42DA-9675-D9AD4928A289} = {01300F0F-686E-47B3-821D-12424177867B}
{70CCBD89-C0A1-4AC8-9AFA-C86C356DFDD7} = {01300F0F-686E-47B3-821D-12424177867B}
{68627BC2-F049-4C69-AD17-81DF9478E8CE} = {0D10EEF2-FBAE-4C72-B816-A52823FC299B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {23D6FBC9-C970-4641-BC1E-2AEA59F51C18}

View File

@@ -1,9 +1,11 @@
using Yi.Framework.Rbac.Domain.Shared.Dtos;
using Yi.Framework.Rbac.Application.Contracts.Dtos.Account;
using Yi.Framework.Rbac.Domain.Shared.Dtos;
namespace Yi.Framework.Rbac.Application.Contracts.IServices
{
public interface IAccountService
{
Task<UserRoleMenuDto> Get();
Task<object> PostLoginAsync(LoginInputVo input);
}
}

View File

@@ -21,7 +21,7 @@ namespace Yi.Framework.Rbac.Application.Services.System
/// <summary>
/// User服务实现
/// </summary>
public class UserService : YiCrudAppService<UserEntity, UserGetOutputDto, UserGetListOutputDto, Guid, UserGetListInputVo, UserCreateInputVo, UserUpdateInputVo>
public class UserService : YiCrudAppService<UserEntity, UserGetOutputDto, UserGetListOutputDto, Guid, UserGetListInputVo, UserCreateInputVo, UserUpdateInputVo>,IUserService
//IUserService
{
public UserService(ISqlSugarRepository<UserEntity, Guid> repository, UserManager userManager, IUserRepository userRepository, ICurrentUser currentUser, IDeptService deptService, ILocalEventBus localEventBus) : base(repository)

View File

@@ -1,15 +1,24 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
{
"profiles": {
"Yi.Abp.Web": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:19001",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"dotnetRunMessages": true,
"applicationUrl": "http://localhost:19001"
},
"Docker": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
"environmentVariables": {
"ASPNETCORE_HTTP_PORTS": "19001"
},
"publishAllPorts": true
}
}
}
},
"$schema": "https://json.schemastore.org/launchsettings.json"
}

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
}
}