Browse Source

Fix unit tests.

pull/20803/head
maliming 1 year ago
parent
commit
c366cf362c
  1. 9
      framework/src/Volo.Abp.AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase/WebApplicationBuilderExtensions.cs
  2. 28
      framework/src/Volo.Abp.AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase/WebProjectPatchHelper.cs
  3. 5
      modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/EfCoreAuditLogRepository.cs
  4. 2
      modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Tokens/AbpOpenIddictTokenStore.cs
  5. 9
      templates/app/aspnet-core/test/MyCompanyName.MyProjectName.Web.Tests/Program.cs

9
framework/src/Volo.Abp.AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase/WebApplicationBuilderExtensions.cs

@ -9,15 +9,16 @@ namespace Volo.Abp.AspNetCore.TestBase;
public static class WebApplicationBuilderExtensions
{
public async static Task RunAbpModuleAsync<TModule>(this WebApplicationBuilder builder, Action<AbpApplicationCreationOptions>? optionsAction = null)
public async static Task RunAbpModuleAsync<TModule>(this WebApplicationBuilder builder, Action<AbpApplicationCreationOptions>? optionsAction = null, string? applicationName = null)
where TModule : IAbpModule
{
var assemblyName = typeof(TModule).Assembly.GetName()?.Name;
if (!assemblyName.IsNullOrWhiteSpace())
applicationName = applicationName ?? typeof(TModule).Assembly.GetName()?.Name;
if (!applicationName.IsNullOrWhiteSpace())
{
// Set the application name as the assembly name of the module will automatically add assembly to the ApplicationParts of MVC application.
builder.Environment.ApplicationName = assemblyName!;
builder.Environment.ApplicationName = applicationName;
}
builder.Host.UseAutofac();
await builder.AddApplicationAsync<TModule>(optionsAction);
var app = builder.Build();

28
framework/src/Volo.Abp.AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase/WebProjectPatchHelper.cs

@ -0,0 +1,28 @@
using System.IO;
namespace Volo.Abp.AspNetCore.TestBase;
public static class GetWebProjectContentRootPathHelper
{
public static string Get(string webProjectName)
{
var currentDirectory = new DirectoryInfo(Directory.GetCurrentDirectory());
while (currentDirectory != null && Directory.GetParent(currentDirectory.FullName) != null)
{
currentDirectory = Directory.GetParent(currentDirectory.FullName);
if (currentDirectory == null)
{
continue;
}
var files = currentDirectory.GetFiles(webProjectName, SearchOption.AllDirectories);
if (files.Length > 0)
{
return files[0].DirectoryName!;
}
}
throw new AbpException($"Web project({webProjectName}) not found!");
}
}

5
modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/EfCoreAuditLogRepository.cs

@ -149,12 +149,13 @@ public class EfCoreAuditLogRepository : EfCoreRepository<IAuditLoggingDbContext,
DateTime endDate,
CancellationToken cancellationToken = default)
{
var result = await (await GetDbSetAsync()).AsNoTracking()
var result = (await (await GetDbSetAsync()).AsNoTracking()
.Where(a => a.ExecutionTime < endDate.AddDays(1) && a.ExecutionTime > startDate)
.OrderBy(t => t.ExecutionTime)
.GroupBy(t => new { t.ExecutionTime.Date })
.ToListAsync(cancellationToken: cancellationToken))
.Select(g => new { Day = g.Min(t => t.ExecutionTime), avgExecutionTime = g.Average(t => t.ExecutionDuration) })
.ToListAsync(GetCancellationToken(cancellationToken));
.ToList();
return result.ToDictionary(element => element.Day.ClearTime(), element => element.avgExecutionTime);
}

2
modules/openiddict/src/Volo.Abp.OpenIddict.Domain/Volo/Abp/OpenIddict/Tokens/AbpOpenIddictTokenStore.cs

@ -63,7 +63,7 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
try
{
await Repository.DeleteAsync(token.ToEntity(), autoSave: true, cancellationToken: cancellationToken);
await Repository.DeleteAsync(token.Id, autoSave: true, cancellationToken: cancellationToken);
}
catch (AbpDbConcurrencyException e)
{

9
templates/app/aspnet-core/test/MyCompanyName.MyProjectName.Web.Tests/Program.cs

@ -3,9 +3,10 @@ using MyCompanyName.MyProjectName;
using Volo.Abp.AspNetCore.TestBase;
var builder = WebApplication.CreateBuilder();
await builder.RunAbpModuleAsync<MyProjectNameWebTestModule>();
public partial class Program
{
builder.Environment.ContentRootPath = GetWebProjectContentRootPathHelper.Get("MyCompanyName.MyProjectName.Web.csproj");
await builder.RunAbpModuleAsync<MyProjectNameWebTestModule>(applicationName: "MyCompanyName.MyProjectName.Web" );
}
public partial class Program
{
}

Loading…
Cancel
Save