Browse Source

添加Freesql单元测试和日志中间件

pull/43/head
WangJunZzz 4 years ago
parent
commit
762b95a7ee
  1. 9
      aspnet-core/Lion.AbpPro.sln
  2. 2
      aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostConst.cs
  3. 61
      aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.cs
  4. 2
      aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Hangfire/AutoDeleteAfterSuccessAttributer.cs
  5. 2
      aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Hangfire/CronType.cs
  6. 2
      aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Hangfire/CustomHangfireAuthorizeFilter.cs
  7. 2
      aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Hangfire/JobRetryLastFilter.cs
  8. 21
      aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/MVC/Filters/ResultExceptionFilter.cs
  9. 15
      aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Middlewares/AbpProApplicationBuilderExtensionsExtensions.cs
  10. 84
      aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Middlewares/RequestLogMiddleware.cs
  11. 4
      aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/RecurringJobsExtensions.cs
  12. 2
      aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/System/WrapResultAttribute.cs
  13. 2
      aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Pages/Login.cshtml.cs
  14. 20
      aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Pages/Monitor.cshtml
  15. 2
      aspnet-core/services/src/Lion.AbpPro.Application/AbpProApplicationModule.cs
  16. 2
      aspnet-core/services/src/Lion.AbpPro.Application/Lion.AbpPro.Application.csproj
  17. 13
      aspnet-core/services/src/Lion.AbpPro.Domain.Shared/Users/Dto/UserOutput.cs
  18. 14
      aspnet-core/services/src/Lion.AbpPro.Domain/Users/IUserFreeSqlBasicRepository.cs
  19. 4
      aspnet-core/services/src/Lion.AbpPro.FreeSqlRepository/AbpProFreeSqlModule.cs
  20. 2
      aspnet-core/services/src/Lion.AbpPro.FreeSqlRepository/FreeSqlBasicRepository.cs
  21. 0
      aspnet-core/services/src/Lion.AbpPro.FreeSqlRepository/Lion.AbpPro.FreeSqlRepository.csproj
  22. 17
      aspnet-core/services/src/Lion.AbpPro.FreeSqlRepository/UserFreeSqlBasicRepository.cs
  23. 13
      aspnet-core/services/test/Lion.AbpPro.FreeSqlRepository.Tests/AbpProFreeSqlRepositoryTestBase.cs
  24. 78
      aspnet-core/services/test/Lion.AbpPro.FreeSqlRepository.Tests/AbpProFreeSqlRepositoryTestModule.cs
  25. 24
      aspnet-core/services/test/Lion.AbpPro.FreeSqlRepository.Tests/Lion.AbpPro.FreeSqlRepository.Tests.csproj
  26. 26
      aspnet-core/services/test/Lion.AbpPro.FreeSqlRepository.Tests/Users/UserFreeSqlBasicRepository_Tests.cs
  27. 18
      aspnet-core/services/test/Lion.AbpPro.FreeSqlReppsitory.Tests1/AbpProFreeSqlRepositoryTestBase.cs
  28. 30
      aspnet-core/services/test/Lion.AbpPro.FreeSqlReppsitory.Tests1/AbpProFreeSqlRepositoryTestModule.cs
  29. 13
      aspnet-core/services/test/Lion.AbpPro.FreeSqlReppsitory.Tests1/Lion.AbpPro.FreeSqlReppsitory.Tests.csproj
  30. 29
      aspnet-core/services/test/Lion.AbpPro.FreeSqlReppsitory.Tests1/Users/UserFreeSqlBasicRepository_Tests.cs
  31. 2
      aspnet-core/services/test/Lion.AbpPro.TestBase/AbpProTestBaseModule.cs

9
aspnet-core/Lion.AbpPro.sln

@ -168,7 +168,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lion.AbpPro.FileManagement.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lion.AbpPro.FileManagement.HttpApi.Host", "modules\FileManagement\host\Lion.AbpPro.FileManagement.HttpApi.Host\Lion.AbpPro.FileManagement.HttpApi.Host.csproj", "{831CD22A-AC6E-4515-AB24-8C96B34C717F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lion.AbpPro.FreeSqlReppsitory", "services\src\Lion.AbpPro.FreeSqlReppsitory\Lion.AbpPro.FreeSqlReppsitory.csproj", "{27C7A0E6-4C2E-4AFF-9DE7-1F526DDC0D18}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lion.AbpPro.FreeSqlRepository", "services\src\Lion.AbpPro.FreeSqlRepository\Lion.AbpPro.FreeSqlRepository.csproj", "{27C7A0E6-4C2E-4AFF-9DE7-1F526DDC0D18}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lion.AbpPro.FreeSqlRepository.Tests", "services\test\Lion.AbpPro.FreeSqlRepository.Tests\Lion.AbpPro.FreeSqlRepository.Tests.csproj", "{7971DF5A-B001-4751-8F40-D7752C612BF1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -404,6 +406,10 @@ Global
{27C7A0E6-4C2E-4AFF-9DE7-1F526DDC0D18}.Debug|Any CPU.Build.0 = Debug|Any CPU
{27C7A0E6-4C2E-4AFF-9DE7-1F526DDC0D18}.Release|Any CPU.ActiveCfg = Release|Any CPU
{27C7A0E6-4C2E-4AFF-9DE7-1F526DDC0D18}.Release|Any CPU.Build.0 = Release|Any CPU
{7971DF5A-B001-4751-8F40-D7752C612BF1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7971DF5A-B001-4751-8F40-D7752C612BF1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7971DF5A-B001-4751-8F40-D7752C612BF1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7971DF5A-B001-4751-8F40-D7752C612BF1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -484,6 +490,7 @@ Global
{78589964-923E-4803-9B74-183487C3ED0F} = {40BF21CB-4520-45A6-A588-5FFB95BAC87C}
{831CD22A-AC6E-4515-AB24-8C96B34C717F} = {C188A1F4-9601-42E5-9A0A-B282E13EAC41}
{27C7A0E6-4C2E-4AFF-9DE7-1F526DDC0D18} = {CA9AC87F-097E-4F15-8393-4BC07735A5B0}
{7971DF5A-B001-4751-8F40-D7752C612BF1} = {04DBDB01-70F4-4E06-B468-8F87850B22BE}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {28315BFD-90E7-4E14-A2EA-F3D23AF4126F}

2
aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostConsts.cs → aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostConst.cs

@ -1,6 +1,6 @@
namespace Lion.AbpPro
{
public class AbpProHttpApiHostConsts
public static class AbpProHttpApiHostConst
{
/// <summary>
/// 跨域策略名

61
aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.cs

@ -21,9 +21,8 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Lion.AbpPro.CAP;
using Lion.AbpPro.Extensions.Filters;
using Lion.AbpPro.Extensions;
using Lion.AbpPro.Extensions.Hangfire;
using Lion.AbpPro.Jobs;
using Lion.AbpPro.Shared.Hosting.Microservices;
using Lion.AbpPro.Shared.Hosting.Microservices.Microsoft.AspNetCore.Builder;
using Lion.AbpPro.Shared.Hosting.Microservices.Microsoft.AspNetCore.MVC.Filters;
@ -31,7 +30,6 @@ using Lion.AbpPro.Shared.Hosting.Microservices.Swaggers;
using Volo.Abp;
using Volo.Abp.Account.Web;
using Volo.Abp.AspNetCore.Authentication.JwtBearer;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic;
using Volo.Abp.AspNetCore.Serilog;
@ -75,13 +73,13 @@ namespace Lion.AbpPro
{
var configuration = context.Services.GetConfiguration();
ConfigureCache(context);
ConfigureSwaggerServices(context, configuration);
ConfigureSwaggerServices(context);
ConfigureOptions(context);
ConfigureJwtAuthentication(context, configuration);
ConfigureHangfireMysql(context);
ConfigurationCap(context);
ConfigurationStsHttpClient(context);
ConfigurationMiniProfiler(context);
ConfigureCap(context);
ConfigureHttpClient(context);
ConfigureMiniProfiler(context);
ConfigureMagicodes(context);
ConfigureAbpExceptions(context);
ConfigureIdentity(context);
@ -91,12 +89,13 @@ namespace Lion.AbpPro
{
var app = context.GetApplicationBuilder();
var configuration = context.GetConfiguration();
app.UseRequestLog();
app.UseAbpRequestLocalization();
app.UseCorrelationId();
app.UseStaticFiles();
app.UseMiniProfiler();
app.UseRouting();
app.UseCors(AbpProHttpApiHostConsts.DefaultCorsPolicyName);
app.UseCors(AbpProHttpApiHostConst.DefaultCorsPolicyName);
app.UseAuthentication();
if (MultiTenancyConsts.IsEnabled)
@ -124,7 +123,7 @@ namespace Lion.AbpPro
IgnoreAntiforgeryToken = true
});
if (configuration.GetValue<bool>("Consul:Enabled", false))
if (configuration.GetValue("Consul:Enabled", false))
{
app.UseConsul();
}
@ -146,7 +145,6 @@ namespace Lion.AbpPro
/// 配置Magicodes.IE
/// Excel导入导出
/// </summary>
/// <param name="context"></param>
private void ConfigureMagicodes(ServiceConfigurationContext context)
{
context.Services.AddTransient<IExporter, ExcelExporter>();
@ -170,8 +168,8 @@ namespace Lion.AbpPro
JobExpirationCheckInterval = TimeSpan.FromMinutes(30),
TablesPrefix = "Hangfire_"
}));
var delaysInSeconds = new int[] { 10, 60, 60 * 3 }; // 重试时间间隔
var Attempts = 3; // 重试次数
var delaysInSeconds = new[] { 10, 60, 60 * 3 }; // 重试时间间隔
const int Attempts = 3; // 重试次数
config.UseFilter(new AutomaticRetryAttribute() { Attempts = Attempts, DelaysInSeconds = delaysInSeconds });
config.UseFilter(new AutoDeleteAfterSuccessAttributer(TimeSpan.FromDays(7)));
config.UseFilter(new JobRetryLastFilter(Attempts));
@ -182,7 +180,7 @@ namespace Lion.AbpPro
/// 配置MiniProfiler
/// </summary>
/// <param name="context"></param>
private void ConfigurationMiniProfiler(ServiceConfigurationContext context)
private void ConfigureMiniProfiler(ServiceConfigurationContext context)
{
context.Services.AddMiniProfiler(options => options.RouteBasePath = "/profiler")
.AddEntityFramework();
@ -204,7 +202,7 @@ namespace Lion.AbpPro
.AddJwtBearer(options =>
{
options.TokenValidationParameters =
new Microsoft.IdentityModel.Tokens.TokenValidationParameters()
new TokenValidationParameters()
{
// 是否开启签名认证
ValidateIssuerSigningKey = true,
@ -232,7 +230,7 @@ namespace Lion.AbpPro
var accessToken =
currentContext.Request.Query["access_token"].FirstOrDefault() ??
currentContext.Request.Cookies[
AbpProHttpApiHostConsts.DefaultCookieName];
AbpProHttpApiHostConst.DefaultCookieName];
if (accessToken.IsNullOrWhiteSpace())
{
@ -289,7 +287,7 @@ namespace Lion.AbpPro
}
private void ConfigurationStsHttpClient(ServiceConfigurationContext context)
private void ConfigureHttpClient(ServiceConfigurationContext context)
{
context.Services.AddHttpClient(context.Services.GetConfiguration().GetSection("HttpClient:Sts:Name").Value,
options =>
@ -322,17 +320,16 @@ namespace Lion.AbpPro
{
context.Services.Configure<IdentityOptions>(options => { options.Lockout = new LockoutOptions() { AllowedForNewUsers = false }; });
}
private void ConfigureConventionalControllers()
{
Configure<AbpAspNetCoreMvcOptions>(options =>
{
options.ConventionalControllers.Create(typeof(AbpProApplicationModule)
.Assembly);
});
}
private static void ConfigureSwaggerServices(ServiceConfigurationContext context,
IConfiguration configuration)
// private void ConfigureConventionalControllers()
// {
// Configure<AbpAspNetCoreMvcOptions>(options =>
// {
// options.ConventionalControllers.Create(typeof(AbpProApplicationModule).Assembly);
// });
// }
private static void ConfigureSwaggerServices(ServiceConfigurationContext context)
{
context.Services.AddSwaggerGen(
options =>
@ -347,8 +344,8 @@ namespace Lion.AbpPro
options.DocumentFilter<HiddenAbpDefaultApiFilter>();
options.SchemaFilter<EnumSchemaFilter>();
// 加载所有xml注释,这里会导致swagger加载有点缓慢
var xmls = Directory.GetFiles(AppContext.BaseDirectory, "*.xml");
foreach (var xml in xmls)
var xmlPaths = Directory.GetFiles(AppContext.BaseDirectory, "*.xml");
foreach (var xml in xmlPaths)
{
options.IncludeXmlComments(xml, true);
}
@ -382,7 +379,7 @@ namespace Lion.AbpPro
Type = SecuritySchemeType.ApiKey,
In = ParameterLocation.Header,
Name = "Accept-Language",
Description = "多语言设置,系统预设语言有zh-Hans、en,默认为zh-Hans"
Description = "多语言设置,系统预设语言有zh-Hans、en,默认为zh-Hans",
});
options.AddSecurityRequirement(new OpenApiSecurityRequirement
@ -393,17 +390,17 @@ namespace Lion.AbpPro
Reference = new OpenApiReference
{ Type = ReferenceType.SecurityScheme, Id = "ApiKey" }
},
new string[] { }
Array.Empty<string>()
}
});
});
}
private void ConfigurationCap(ServiceConfigurationContext context)
private void ConfigureCap(ServiceConfigurationContext context)
{
var configuration = context.Services.GetConfiguration();
var enabled = configuration.GetValue<bool>("Cap:Enabled", false);
var enabled = configuration.GetValue("Cap:Enabled", false);
if (enabled)
{
context.AddAbpCap(capOptions =>

2
aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Hangfire/AutoDeleteAfterSuccessAttributer.cs

@ -3,7 +3,7 @@ using Hangfire.Common;
using Hangfire.States;
using Hangfire.Storage;
namespace Lion.AbpPro.Extensions.Filters;
namespace Lion.AbpPro.Extensions.Hangfire;
public class AutoDeleteAfterSuccessAttributer : JobFilterAttribute, IApplyStateFilter
{

2
aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Hangfire/CronType.cs

@ -1,7 +1,7 @@
using System;
using Hangfire;
namespace Lion.AbpPro.Jobs
namespace Lion.AbpPro.Extensions.Hangfire
{
/// <summary>
/// Cron类型

2
aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Hangfire/CustomHangfireAuthorizeFilter.cs

@ -2,7 +2,7 @@ using Hangfire.Dashboard;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Users;
namespace Lion.AbpPro.Extensions.Filters
namespace Lion.AbpPro.Extensions.Hangfire
{
public class CustomHangfireAuthorizeFilter : IDashboardAuthorizationFilter
{

2
aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Hangfire/JobRetryLastFilter.cs

@ -19,7 +19,7 @@ public class JobRetryLastFilter : JobFilterAttribute, IElectStateFilter
public void OnStateElection(ElectStateContext context)
{
int retryAttempt = context.GetJobParameter<int>("RetryCount");
var retryAttempt = context.GetJobParameter<int>("RetryCount");
if (RetryCount == retryAttempt)
{
Log.Error("最后一次重试");

21
aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/MVC/Filters/ResultExceptionFilter.cs

@ -3,7 +3,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Lion.AbpPro.Extension.Customs.Dtos;
using Lion.AbpPro.Shared.Hosting.Microservices.System;
using Lion.AbpPro.Extensions.System;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.Filters;
@ -23,7 +23,7 @@ using Volo.Abp.Validation;
namespace Lion.AbpPro.Shared.Hosting.Microservices.Microsoft.AspNetCore.MVC.Filters
{
public class ResultExceptionFilter : IFilterMetadata, IAsyncExceptionFilter, ITransientDependency
public sealed class ResultExceptionFilter : IFilterMetadata, IAsyncExceptionFilter, ITransientDependency
{
private ILogger<ResultExceptionFilter> Logger { get; set; }
@ -56,7 +56,7 @@ namespace Lion.AbpPro.Shared.Hosting.Microservices.Microsoft.AspNetCore.MVC.Filt
await HandleAndWrapException(context);
}
protected virtual bool ShouldHandleException(ExceptionContext context)
private bool ShouldHandleException(ExceptionContext context)
{
if (context.ActionDescriptor.AsControllerActionDescriptor().ControllerTypeInfo.GetCustomAttributes(typeof(WrapResultAttribute), true).Any())
{
@ -71,7 +71,7 @@ namespace Lion.AbpPro.Shared.Hosting.Microservices.Microsoft.AspNetCore.MVC.Filt
return false;
}
protected virtual async Task HandleAndWrapException(ExceptionContext context)
private async Task HandleAndWrapException(ExceptionContext context)
{
//TODO: Trigger an AbpExceptionHandled event or something like that.
@ -108,21 +108,20 @@ namespace Lion.AbpPro.Shared.Hosting.Microservices.Microsoft.AspNetCore.MVC.Filt
private string SimplifyMessage(Exception error)
{
string message = string.Empty;
switch (error)
{
case AbpAuthorizationException e:
return message = "Authenticate failure!";
return "Authenticate failure!";
case AbpValidationException e:
return message = "Request param validate failure!";
return "Request param validate failure!";
case EntityNotFoundException e:
return message = "not found the entity!";
return "not found the entity!";
case BusinessException e:
return message = $"{e.Message}";
return $"{e.Message}";
case NotImplementedException e:
return message = "not implement!";
return "not implement!";
default:
return message = "server internal error!";
return "server internal error!";
}
}
}

15
aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Middlewares/AbpProApplicationBuilderExtensionsExtensions.cs

@ -0,0 +1,15 @@
using Lion.AbpPro.Extensions.Middlewares;
namespace Microsoft.AspNetCore.Builder;
public static class AbpProApplicationBuilderExtensionsExtensions
{
/// <summary>
/// 记录请求响应日志
/// </summary>
/// <returns></returns>
public static IApplicationBuilder UseRequestLog(this IApplicationBuilder app)
{
return app.UseMiddleware<RequestLogMiddleware>();
}
}

84
aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Middlewares/RequestLogMiddleware.cs

@ -0,0 +1,84 @@
using System;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
namespace Lion.AbpPro.Extensions.Middlewares;
public class RequestLogMiddleware
{
private readonly RequestDelegate _next;
private readonly ILogger<RequestLogMiddleware> _logger;
public RequestLogMiddleware(RequestDelegate next,
ILogger<RequestLogMiddleware> logger)
{
_next = next;
_logger = logger;
}
public async Task InvokeAsync(HttpContext context)
{
context.Request.EnableBuffering();
var originalBody = context.Response.Body;
if (context.Request.Path.ToString().ToLower().Contains("swagger")
|| context.Request.Path.ToString().ToLower().Contains("login")
|| context.Request.Path.ToString().ToLower().Contains("monitor")
|| context.Request.Path.ToString().ToLower().Contains("cap")
|| context.Request.Path.ToString().ToLower().Contains("hangfire")
|| context.Request.Path.ToString() == "/"
)
{
await _next(context);
}
else
{
try
{
var logRequestId = Guid.NewGuid().ToString();
await RequestDataLog(context, logRequestId);
using (var ms = new MemoryStream())
{
context.Response.Body = ms;
await _next(context);
ResponseDataLog(ms, logRequestId);
ms.Position = 0;
await ms.CopyToAsync(originalBody);
}
}
catch (Exception ex)
{
// 记录异常
_logger.LogError(ex.Message + "" + ex.InnerException);
}
finally
{
context.Response.Body = originalBody;
}
}
}
private async Task RequestDataLog(HttpContext context,
string requestId)
{
var request = context.Request;
var body = new StreamReader(request.Body);
var requestData = $" 请求路径:{request.Path}\r\n 请求Body参数:{await body.ReadToEndAsync()}";
_logger.LogInformation($"日志中间件[Request],LogRequestId:{requestId}:请求接口信息:{requestData}");
request.Body.Position = 0;
}
private void ResponseDataLog(MemoryStream ms, string requestId)
{
ms.Position = 0;
var responseBody = new StreamReader(ms).ReadToEnd();
// 去除 Html
var isHtml = Regex.IsMatch(responseBody, "<[^>]+>");
if (!isHtml && !string.IsNullOrEmpty(responseBody))
{
_logger.LogInformation($"日志中间件[Response],LogRequestId:{requestId}:响应接口信息:{responseBody}");
}
}
}

4
aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/RecurringJobsExtensions.cs

@ -1,8 +1,10 @@
using Hangfire;
using Lion.AbpPro.Extensions.Hangfire;
using Lion.AbpPro.Jobs;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
namespace Lion.AbpPro.Jobs
namespace Lion.AbpPro.Extensions
{
public static class RecurringJobsExtensions
{

2
aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/System/WrapResultAttribute.cs

@ -1,6 +1,6 @@
using System;
namespace Lion.AbpPro.Shared.Hosting.Microservices.System
namespace Lion.AbpPro.Extensions.System
{
public class WrapResultAttribute : Attribute
{

2
aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Pages/Login.cshtml.cs

@ -58,7 +58,7 @@ namespace Lion.AbpPro.Pages
var result = await _accountAppService.LoginAsync(new LoginInput()
{ Name = userName, Password = password });
Response.Cookies.Append(AbpProHttpApiHostConsts.DefaultCookieName,
Response.Cookies.Append(AbpProHttpApiHostConst.DefaultCookieName,
result.Token, options);
}
catch (Exception e)

20
aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Pages/Monitor.cshtml

@ -27,12 +27,12 @@
<div class="row">
<div class="col-sm-6 col-md-4 col-lg-3">
<div class="thumbnail" style="height: 180px">
<a href="@AbpProHttpApiHostConsts.SwaggerUiEndPoint" target="_blank">
<a href="@AbpProHttpApiHostConst.SwaggerUiEndPoint" target="_blank">
<img class="lazy" src="/images/swagger.png" width="300" height="150"/>
</a>
<div class="caption">
<h3>
<a href="@AbpProHttpApiHostConsts.SwaggerUiEndPoint" target="_blank">SwaggerUI</a>
<a href="@AbpProHttpApiHostConst.SwaggerUiEndPoint" target="_blank">SwaggerUI</a>
</h3>
</div>
</div>
@ -40,12 +40,12 @@
<div class="col-sm-6 col-md-4 col-lg-3">
<div class="thumbnail" style="height: 180px">
<a href="@AbpProHttpApiHostConsts.CapDashboardEndPoint" target="_blank">
<a href="@AbpProHttpApiHostConst.CapDashboardEndPoint" target="_blank">
<img class="lazy" src="/images/cap.png" width="300" height="150"/>
</a>
<div class="caption">
<h3>
<a href="@AbpProHttpApiHostConsts.CapDashboardEndPoint" target="_blank">CAP面板</a>
<a href="@AbpProHttpApiHostConst.CapDashboardEndPoint" target="_blank">CAP面板</a>
</h3>
</div>
</div>
@ -53,36 +53,36 @@
<div class="col-sm-6 col-md-4 col-lg-3">
<div class="thumbnail" style="height: 180px">
<a href="@AbpProHttpApiHostConsts.HangfireDashboardEndPoint" target="_blank">
<a href="@AbpProHttpApiHostConst.HangfireDashboardEndPoint" target="_blank">
<img class="lazy" src="/images/hangfire.png" width="300" height="150"/>
</a>
<div class="caption">
<h3>
<a href="@AbpProHttpApiHostConsts.HangfireDashboardEndPoint" target="_blank">Hangfire面板</a>
<a href="@AbpProHttpApiHostConst.HangfireDashboardEndPoint" target="_blank">Hangfire面板</a>
</h3>
</div>
</div>
</div>
<div class="col-sm-6 col-md-4 col-lg-3">
<div class="thumbnail" style="height: 180px">
<a href="@AbpProHttpApiHostConsts.MiniprofilerEndPoint" target="_blank">
<a href="@AbpProHttpApiHostConst.MiniprofilerEndPoint" target="_blank">
<img class="lazy" src="/images/miniprofiler.png" width="300" height="150"/>
</a>
<div class="caption">
<h3>
<a href="@AbpProHttpApiHostConsts.MiniprofilerEndPoint" target="_blank">Miniprofiler</a>
<a href="@AbpProHttpApiHostConst.MiniprofilerEndPoint" target="_blank">Miniprofiler</a>
</h3>
</div>
</div>
</div>
<div class="col-sm-6 col-md-4 col-lg-3">
<div class="thumbnail" style="height: 180px">
<a href="@AbpProHttpApiHostConsts.MoreEndPoint" target="_blank">
<a href="@AbpProHttpApiHostConst.MoreEndPoint" target="_blank">
<img class="lazy" src="/images/more.png" width="300" height="150"/>
</a>
<div class="caption">
<h3>
<a href="@AbpProHttpApiHostConsts.MoreEndPoint" target="_blank">了解更多...</a>
<a href="@AbpProHttpApiHostConst.MoreEndPoint" target="_blank">了解更多...</a>
</h3>
</div>
</div>

2
aspnet-core/services/src/Lion.AbpPro.Application/AbpProApplicationModule.cs

@ -1,6 +1,6 @@
using Lion.AbpPro.DataDictionaryManagement;
using Lion.AbpPro.FileManagement;
using Lion.AbpPro.FreeSqlReppsitory;
using Lion.AbpPro.FreeSqlRepository;
using Lion.AbpPro.NotificationManagement;
using Volo.Abp.Account;
using Volo.Abp.AuditLogging;

2
aspnet-core/services/src/Lion.AbpPro.Application/Lion.AbpPro.Application.csproj

@ -12,7 +12,7 @@
<ProjectReference Include="..\..\..\modules\NotificationManagement\src\Lion.AbpPro.NotificationManagement.Application\Lion.AbpPro.NotificationManagement.Application.csproj" />
<ProjectReference Include="..\Lion.AbpPro.Domain\Lion.AbpPro.Domain.csproj" />
<ProjectReference Include="..\Lion.AbpPro.Application.Contracts\Lion.AbpPro.Application.Contracts.csproj" />
<ProjectReference Include="..\Lion.AbpPro.FreeSqlReppsitory\Lion.AbpPro.FreeSqlReppsitory.csproj" />
<ProjectReference Include="..\Lion.AbpPro.FreeSqlRepository\Lion.AbpPro.FreeSqlRepository.csproj" />
</ItemGroup>
<ItemGroup>

13
aspnet-core/services/src/Lion.AbpPro.Domain.Shared/Users/Dto/UserOutput.cs

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lion.AbpPro.Users.Dto
{
public class UserOutput
{
public Guid Id { get; set; }
}
}

14
aspnet-core/services/src/Lion.AbpPro.Domain/Users/IUserFreeSqlBasicRepository.cs

@ -0,0 +1,14 @@
using Lion.AbpPro.Users.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lion.AbpPro.Users
{
public interface IUserFreeSqlBasicRepository
{
Task<List<UserOutput>> GetListAsync();
}
}

4
aspnet-core/services/src/Lion.AbpPro.FreeSqlReppsitory/AbpProFreeSqlModule.cs → aspnet-core/services/src/Lion.AbpPro.FreeSqlRepository/AbpProFreeSqlModule.cs

@ -2,7 +2,7 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Modularity;
namespace Lion.AbpPro.FreeSqlReppsitory;
namespace Lion.AbpPro.FreeSqlRepository;
public class AbpProFreeSqlModule : AbpModule
{
@ -13,7 +13,7 @@ public class AbpProFreeSqlModule : AbpModule
var freeSql = new FreeSql.FreeSqlBuilder()
.UseConnectionString(FreeSql.DataType.MySql, connectionString)
.Build();
context.Services.AddSingleton<IFreeSql>(freeSql);
}
}

2
aspnet-core/services/src/Lion.AbpPro.FreeSqlReppsitory/FreeSqlBasicRepository.cs → aspnet-core/services/src/Lion.AbpPro.FreeSqlRepository/FreeSqlBasicRepository.cs

@ -1,7 +1,7 @@
using Volo.Abp.Domain.Services;
using Volo.Abp.Threading;
namespace Lion.AbpPro.FreeSqlReppsitory;
namespace Lion.AbpPro.FreeSqlRepository;
public abstract class FreeSqlBasicRepository : DomainService
{

0
aspnet-core/services/src/Lion.AbpPro.FreeSqlReppsitory/Lion.AbpPro.FreeSqlReppsitory.csproj → aspnet-core/services/src/Lion.AbpPro.FreeSqlRepository/Lion.AbpPro.FreeSqlRepository.csproj

17
aspnet-core/services/src/Lion.AbpPro.FreeSqlRepository/UserFreeSqlBasicRepository.cs

@ -0,0 +1,17 @@
using Lion.AbpPro.Users;
using Lion.AbpPro.Users.Dto;
namespace Lion.AbpPro.FreeSqlRepository
{
public class UserFreeSqlBasicRepository : FreeSqlBasicRepository, IUserFreeSqlBasicRepository
{
public async Task<List<UserOutput>> GetListAsync()
{
var sql = "select id from AbpUsers";
var result = await FreeSql.Select<UserOutput>()
.WithSql(sql)
.ToListAsync();
return result;
}
}
}

13
aspnet-core/services/test/Lion.AbpPro.FreeSqlRepository.Tests/AbpProFreeSqlRepositoryTestBase.cs

@ -0,0 +1,13 @@
using Lion.AbpPro.FreeSqlReppsitory.Tests;
using Lion.AbpPro.Localization;
namespace Lion.AbpPro.FreeSqlRepository.Tests
{
public abstract class AbpProFreeSqlRepositoryTestBase: AbpProTestBase<AbpProFreeSqlRepositoryTestModule>
{
protected AbpProFreeSqlRepositoryTestBase()
{
ServiceProvider.InitializeLocalization();
}
}
}

78
aspnet-core/services/test/Lion.AbpPro.FreeSqlRepository.Tests/AbpProFreeSqlRepositoryTestModule.cs

@ -0,0 +1,78 @@
using System;
using System.Linq;
using Lion.AbpPro.EntityFrameworkCore;
using Lion.AbpPro.FreeSqlRepository;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.Sqlite;
using Volo.Abp.Modularity;
namespace Lion.AbpPro.FreeSqlReppsitory.Tests;
[DependsOn(
typeof(AbpProTestBaseModule),
typeof(AbpProEntityFrameworkCoreTestModule),
typeof(AbpProFreeSqlModule)
)]
public class AbpProFreeSqlRepositoryTestModule : AbpModule
{
private const string ConnectionString = "Data Source=:memory:";
private SqliteConnection _sqliteConnection;
public override void ConfigureServices(ServiceConfigurationContext context)
{
var freeSql = new FreeSql.FreeSqlBuilder()
.UseConnectionString(FreeSql.DataType.Sqlite, ConnectionString)
.UseAutoSyncStructure(true)
.Build();
context.Services.AddSingleton<IFreeSql>(freeSql);
var connection = new SqliteConnection(ConnectionString);
ConfigureInMemorySqlite(context.Services, freeSql);
}
private void ConfigureInMemorySqlite(IServiceCollection services, IFreeSql freeSql)
{
_sqliteConnection = CreateDatabaseAndGetConnection(freeSql);
//services.Configure<AbpDbContextOptions>(options =>
//{
// options.PreConfigure<AbpProDbContext>(options => { options.DbContextOptions.UseBatchEF_Sqlite(); });
// options.Configure(context => { context.DbContextOptions.UseSqlite(_sqliteConnection); });
//});
}
public override void OnApplicationShutdown(ApplicationShutdownContext context)
{
// _sqliteConnection.Dispose();
}
private static SqliteConnection CreateDatabaseAndGetConnection(IFreeSql freeSql)
{
var connection = new SqliteConnection(ConnectionString);
//connection.Open();
var options = new DbContextOptionsBuilder<AbpProDbContext>()
.UseSqlite(connection)
.Options;
using (var context = new AbpProDbContext(options))
{
foreach (var entityType in context.Model.GetEntityTypes())
{
freeSql.CodeFirst.SyncStructure(entityType.ClrType, entityType.GetTableName(), true);
}
//context.GetService<IRelationalDatabaseCreator>().CreateTables();
}
return connection;
}
}

24
aspnet-core/services/test/Lion.AbpPro.FreeSqlRepository.Tests/Lion.AbpPro.FreeSqlRepository.Tests.csproj

@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
<RootNamespace>Lion.AbpPro.FreeSqlRepository.Tests</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNETTestSdkVersion)" />
<PackageReference Include="FreeSql.Provider.Sqlite" Version="$(FreesqlVersion)" />
<PackageReference Include="Volo.Abp.EntityFrameworkCore.Sqlite" Version="$(AbpPackageVersion)" />
<PackageReference Include="Zack.EFCore.Batch.Sqlite_NET6" Version="$(ZackEFCoreBatchVersion)" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Lion.AbpPro.FreeSqlRepository\Lion.AbpPro.FreeSqlRepository.csproj" />
<ProjectReference Include="..\Lion.AbpPro.EntityFrameworkCore.Tests\Lion.AbpPro.EntityFrameworkCore.Tests.csproj" />
<ProjectReference Include="..\Lion.AbpPro.TestBase\Lion.AbpPro.TestBase.csproj" />
</ItemGroup>
</Project>

26
aspnet-core/services/test/Lion.AbpPro.FreeSqlRepository.Tests/Users/UserFreeSqlBasicRepository_Tests.cs

@ -0,0 +1,26 @@
using System.Threading.Tasks;
using Lion.AbpPro.Users;
using Shouldly;
using Xunit;
namespace Lion.AbpPro.FreeSqlRepository.Tests.Users
{
public class UserFreeSqlBasicRepository_Tests: AbpProFreeSqlRepositoryTestBase
{
private readonly IUserFreeSqlBasicRepository _userFreeSqlBasicRepository;
public UserFreeSqlBasicRepository_Tests()
{
_userFreeSqlBasicRepository = GetRequiredService<IUserFreeSqlBasicRepository>();
}
[Fact]
public async Task Should_NotThrow_ListAsyncTest()
{
var result = await _userFreeSqlBasicRepository.GetListAsync();
result.ShouldNotBeNull();
}
}
}

18
aspnet-core/services/test/Lion.AbpPro.FreeSqlReppsitory.Tests1/AbpProFreeSqlRepositoryTestBase.cs

@ -0,0 +1,18 @@
using Lion.AbpPro.FreeSqlReppsitory.Tests;
using Lion.AbpPro.Localization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lion.AbpPro
{
public abstract class AbpProFreeSqlRepositoryTestBase: AbpProTestBase<AbpProFreeSqlRepositoryTestModule>
{
public AbpProFreeSqlRepositoryTestBase()
{
ServiceProvider.InitializeLocalization();
}
}
}

30
aspnet-core/services/test/Lion.AbpPro.FreeSqlReppsitory.Tests1/AbpProFreeSqlRepositoryTestModule.cs

@ -0,0 +1,30 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Modularity;
namespace Lion.AbpPro.FreeSqlReppsitory.Tests;
[DependsOn(
typeof(AbpProTestBaseModule),
typeof(AbpProFreeSqlModule)
)]
public class AbpProFreeSqlRepositoryTestModule: AbpModule
{
//public override void ConfigureServices(ServiceConfigurationContext context)
//{
// var configuration = context.Services.GetConfiguration();
// var connectionString = configuration.GetConnectionString("Default");
// var freeSql = new FreeSql.FreeSqlBuilder()
// .UseConnectionString(FreeSql.DataType.Sqlite, @"Data Source=|DataDirectory|\document.db;Pooling=true;Max Pool Size=10")
// .UseAutoSyncStructure(true)
// .Build();
// context.Services.AddSingleton<IFreeSql>(freeSql);
//}
}

13
aspnet-core/services/test/Lion.AbpPro.FreeSqlReppsitory.Tests1/Lion.AbpPro.FreeSqlReppsitory.Tests.csproj

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\common.props" />
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>Lion.AbpPro</RootNamespace>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Lion.AbpPro.FreeSqlReppsitory\Lion.AbpPro.FreeSqlReppsitory.csproj" />
<ProjectReference Include="..\Lion.AbpPro.TestBase\Lion.AbpPro.TestBase.csproj" />
</ItemGroup>
</Project>

29
aspnet-core/services/test/Lion.AbpPro.FreeSqlReppsitory.Tests1/Users/UserFreeSqlBasicRepository_Tests.cs

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Shouldly;
using Xunit;
namespace Lion.AbpPro.Users
{
public class UserFreeSqlBasicRepository_Tests: AbpProFreeSqlRepositoryTestBase
{
//private readonly IUserFreeSqlBasicRepository _userFreeSqlBasicRepository;
//public UserFreeSqlBasicRepositoryTest()
//{
// _userFreeSqlBasicRepository = GetRequiredService<IUserFreeSqlBasicRepository>();
//}
[Fact]
public void Should_NotThrow_ListAsyncTest()
{
//var result = await _userFreeSqlBasicRepository.GetListAsync();
var s = 1;
}
}
}

2
aspnet-core/services/test/Lion.AbpPro.TestBase/AbpProTestBaseModule.cs

@ -43,7 +43,7 @@ namespace Lion.AbpPro
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
SeedTestData(context);
//SeedTestData(context);
}
private static void SeedTestData(ApplicationInitializationContext context)

Loading…
Cancel
Save