mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-04-05 17:38:01 +08:00
优化单元测试;增加打印方案单元测试
This commit is contained in:
parent
87129c2725
commit
0fe060899b
@ -12,9 +12,7 @@
|
||||
// <summary>layui datatable数据返回</summary>
|
||||
// ***********************************************************************
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Infrastructure;
|
||||
using OpenAuth.Repository.Domain;
|
||||
|
||||
namespace OpenAuth.App.Response
|
||||
|
18
OpenAuth.App/SysPrinterPlanApp/Request/QueryReq.cs
Normal file
18
OpenAuth.App/SysPrinterPlanApp/Request/QueryReq.cs
Normal file
@ -0,0 +1,18 @@
|
||||
namespace OpenAuth.App.Request
|
||||
{
|
||||
/// <summary>
|
||||
/// 打印方案数据源请求参数
|
||||
/// </summary>
|
||||
public class QueryReq : PageReq
|
||||
{
|
||||
/// <summary>
|
||||
///数据源;打印方案对应的数据来源SQL
|
||||
/// </summary>
|
||||
public string SourceSql { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 入口参数JSON字符串
|
||||
/// </summary>
|
||||
public string ParamJsonStr { get; set; }
|
||||
}
|
||||
}
|
@ -74,5 +74,15 @@ namespace OpenAuth.App
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<TableData> Query(QueryReq request)
|
||||
{
|
||||
var result = new TableData();
|
||||
|
||||
var objs = await SugarClient.Ado.SqlQueryAsync<dynamic>(request.SourceSql);
|
||||
result.data = objs.Skip((request.page - 1) * request.limit)
|
||||
.Take(request.limit).ToList();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@ using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using OpenAuth.Repository;
|
||||
using SqlSugar;
|
||||
|
||||
namespace OpenAuth.App.Test
|
||||
{
|
||||
@ -66,8 +67,24 @@ namespace OpenAuth.App.Test
|
||||
var dbtypes = config.GetSection("AppSetting:DbTypes").GetChildren()
|
||||
.ToDictionary(x => x.Key, x => x.Value);
|
||||
|
||||
Console.WriteLine($"单元测试数据库信息:{dbtypes[httpContextAccessorMock.Object.GetTenantId()]}/{config.GetSection("ConnectionStrings")["OpenAuthDBContext"]}");
|
||||
var connectionString = config.GetSection("ConnectionStrings")["OpenAuthDBContext"];
|
||||
|
||||
Console.WriteLine($"单元测试数据库信息:{dbtypes[httpContextAccessorMock.Object.GetTenantId()]}/{connectionString}");
|
||||
|
||||
var sqlsugarTypes = UtilMethods.EnumToDictionary<SqlSugar.DbType>();
|
||||
var dbType = sqlsugarTypes.FirstOrDefault(it =>
|
||||
dbtypes.ToDictionary(u => u.Key, v => v.Value.ToLower()).ContainsValue(it.Key));
|
||||
|
||||
serviceCollection.AddScoped<ISqlSugarClient>(s =>
|
||||
{
|
||||
var sqlSugar = new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
DbType = dbType.Value,
|
||||
ConnectionString = connectionString,
|
||||
IsAutoCloseConnection = true,
|
||||
});
|
||||
return sqlSugar;
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
56
OpenAuth.App/Test/TestSysPrinterPlan.cs
Normal file
56
OpenAuth.App/Test/TestSysPrinterPlan.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Infrastructure;
|
||||
using Infrastructure.Cache;
|
||||
using Infrastructure.Extensions;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.App.SSO;
|
||||
using OpenAuth.Repository;
|
||||
using OpenAuth.Repository.Domain;
|
||||
using OpenAuth.Repository.Interface;
|
||||
|
||||
namespace OpenAuth.App.Test
|
||||
{
|
||||
public class TestSysPrinterPlan : TestBase
|
||||
{
|
||||
public override ServiceCollection GetService()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
|
||||
var cachemock = new Mock<ICacheContext>();
|
||||
cachemock.Setup(x => x.Get<UserAuthSession>("tokentest"))
|
||||
.Returns(new UserAuthSession { Account = Define.SYSTEM_USERNAME });
|
||||
services.AddScoped(x => cachemock.Object);
|
||||
|
||||
var httpContextAccessorMock = new Mock<IHttpContextAccessor>();
|
||||
httpContextAccessorMock.Setup(x => x.HttpContext.Request.Query[Define.TOKEN_NAME])
|
||||
.Returns("tokentest");
|
||||
|
||||
services.AddScoped(x => httpContextAccessorMock.Object);
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Query()
|
||||
{
|
||||
var app = _autofacServiceProvider.GetService<SysPrinterPlanApp>();
|
||||
|
||||
var result = await app.Query(new QueryReq()
|
||||
{
|
||||
SourceSql = "select * from user"
|
||||
});
|
||||
|
||||
Console.WriteLine(JsonHelper.Instance.Serialize(result));
|
||||
|
||||
//延长主线程,防止程序退出
|
||||
Thread.Sleep(3000);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -73,51 +73,20 @@ namespace OpenAuth.Repository.Test
|
||||
var connectionString = config.GetSection("ConnectionStrings")["OpenAuthDBContext"];
|
||||
Console.WriteLine($"单元测试数据库信息:{dbtypes[httpContextAccessorMock.Object.GetTenantId()]}/{connectionString}");
|
||||
|
||||
var sqlsugarTypes = UtilMethods.EnumToDictionary<SqlSugar.DbType>();
|
||||
var dbType = sqlsugarTypes.FirstOrDefault(it =>
|
||||
dbtypes.ToDictionary(u => u.Key, v => v.Value.ToLower()).ContainsValue(it.Key));
|
||||
|
||||
serviceCollection.AddScoped<ISqlSugarClient>(s =>
|
||||
{
|
||||
|
||||
SqlSugarClient sqlSugar;
|
||||
if(dbtypes.ContainsValue(Define.DBTYPE_SQLSERVER))
|
||||
var sqlSugar = new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
sqlSugar = new SqlSugarClient (new ConnectionConfig()
|
||||
{
|
||||
DbType = SqlSugar.DbType.SqlServer,
|
||||
ConnectionString = connectionString,
|
||||
IsAutoCloseConnection = true,
|
||||
});
|
||||
}
|
||||
else if(dbtypes.ContainsValue(Define.DBTYPE_MYSQL)) //mysql
|
||||
{
|
||||
sqlSugar = new SqlSugarClient (new ConnectionConfig()
|
||||
{
|
||||
DbType = SqlSugar.DbType.MySql,
|
||||
ConnectionString = connectionString,
|
||||
IsAutoCloseConnection = true,
|
||||
});
|
||||
}
|
||||
else if(dbtypes.ContainsValue(Define.DBTYPE_PostgreSQL)) //PostgreSQL
|
||||
{
|
||||
sqlSugar = new SqlSugarClient (new ConnectionConfig()
|
||||
{
|
||||
DbType = SqlSugar.DbType.PostgreSQL,
|
||||
ConnectionString = connectionString,
|
||||
IsAutoCloseConnection = true,
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
sqlSugar = new SqlSugarClient (new ConnectionConfig()
|
||||
{
|
||||
DbType = SqlSugar.DbType.Oracle,
|
||||
ConnectionString = connectionString,
|
||||
IsAutoCloseConnection = true,
|
||||
});
|
||||
}
|
||||
|
||||
DbType = dbType.Value,
|
||||
ConnectionString = connectionString,
|
||||
IsAutoCloseConnection = true,
|
||||
});
|
||||
return sqlSugar;
|
||||
});
|
||||
|
||||
|
||||
|
||||
var builder = new ContainerBuilder();
|
||||
|
||||
|
@ -83,6 +83,15 @@ namespace OpenAuth.WebApi.Controllers
|
||||
{
|
||||
return await _app.Load(request);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打印方案根据数据源获取打印数据
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
public async Task<TableData> Query(QueryReq request)
|
||||
{
|
||||
return await _app.Query(request);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量删除
|
||||
|
Loading…
Reference in New Issue
Block a user