Browse Source

Use `WebApplicationFactory` in template project.

pull/17497/head
maliming 2 years ago
parent
commit
5b903a4eb5
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 4
      framework/src/Volo.Abp.AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase/WebApplicationBuilderExtensions.cs
  2. 1
      framework/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/App/Program.cs
  3. 34
      framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AspNetCoreMvcTestBase.cs
  4. 1
      framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Program.cs
  5. 1
      framework/test/Volo.Abp.AspNetCore.Mvc.UI.Tests/Volo/Abp/AspNetCore/Mvc/UI/Program.cs
  6. 1
      framework/test/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests/Program.cs
  7. 1
      framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/Program.cs
  8. 1
      framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/App/Program.cs
  9. 6
      framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/AbpHostEnvironment_Tests.cs
  10. 1
      framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/Program.cs
  11. 1
      framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/Program.cs
  12. 13
      templates/app/aspnet-core/test/MyCompanyName.MyProjectName.Web.Tests/MyProjectNameWebTestBase.cs
  13. 10
      templates/app/aspnet-core/test/MyCompanyName.MyProjectName.Web.Tests/Program.cs

4
framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/WebApplicationBuilderExtensions.cs → framework/src/Volo.Abp.AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase/WebApplicationBuilderExtensions.cs

@ -5,11 +5,11 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Volo.Abp.Modularity;
namespace Volo.Abp.AspNetCore;
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)
where TModule : IAbpModule
{
builder.Host.UseAutofac();

1
framework/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/App/Program.cs

@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Builder;
using Volo.Abp.AspNetCore;
using Volo.Abp.AspNetCore.App;
using Volo.Abp.AspNetCore.TestBase;
var builder = WebApplication.CreateBuilder();
await builder.RunAbpModuleAsync<AppModule>();

34
framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AspNetCoreMvcTestBase.cs

@ -1,40 +1,6 @@
using System.IO;
using System.Linq;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
namespace Volo.Abp.AspNetCore.Mvc;
public abstract class AspNetCoreMvcTestBase : AbpAspNetCoreTestBase<Program>
{
protected override IHostBuilder CreateHostBuilder()
{
var contentRootPath = CalculateContentRootPath(
"Volo.Abp.AspNetCore.Mvc.Tests.csproj",
string.Format(
"Volo{0}Abp{0}AspNetCore{0}App",
Path.DirectorySeparatorChar
)
);
return base.CreateHostBuilder()?.UseContentRoot(contentRootPath);
}
private static string CalculateContentRootPath(string projectFileName, string contentPath)
{
var currentDirectory = Directory.GetCurrentDirectory();
while (!ContainsFile(currentDirectory, projectFileName))
{
currentDirectory = new DirectoryInfo(currentDirectory).Parent.FullName;
}
return Path.Combine(currentDirectory, contentPath);
}
private static bool ContainsFile(string currentDirectory, string projectFileName)
{
return Directory
.GetFiles(currentDirectory, "*.*", SearchOption.TopDirectoryOnly)
.Any(f => Path.GetFileName(f) == projectFileName);
}
}

1
framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Program.cs

@ -5,6 +5,7 @@ using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
using Volo.Abp.AspNetCore;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.TestBase;
using Volo.Abp.Modularity.PlugIns;
var builder = WebApplication.CreateBuilder();

1
framework/test/Volo.Abp.AspNetCore.Mvc.UI.Tests/Volo/Abp/AspNetCore/Mvc/UI/Program.cs

@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Builder;
using Volo.Abp.AspNetCore;
using Volo.Abp.AspNetCore.Mvc.UI;
using Volo.Abp.AspNetCore.TestBase;
var builder = WebApplication.CreateBuilder();
await builder.RunAbpModuleAsync<AbpAspNetCoreMvcUiTestModule>();

1
framework/test/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests/Program.cs

@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Builder;
using Volo.Abp.AspNetCore;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests.Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
using Volo.Abp.AspNetCore.TestBase;
var builder = WebApplication.CreateBuilder();
await builder.RunAbpModuleAsync<AbpAspNetCoreMvcUiThemeSharedTestModule>();

1
framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/Program.cs

@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Builder;
using Volo.Abp.AspNetCore;
using Volo.Abp.AspNetCore.Mvc.Versioning;
using Volo.Abp.AspNetCore.TestBase;
var builder = WebApplication.CreateBuilder();
await builder.RunAbpModuleAsync<AbpAspNetCoreMvcVersioningTestModule>();

1
framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/App/Program.cs

@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Builder;
using Volo.Abp.AspNetCore;
using Volo.Abp.AspNetCore.App;
using Volo.Abp.AspNetCore.TestBase;
var builder = WebApplication.CreateBuilder();
await builder.RunAbpModuleAsync<AbpSerilogTestModule>();

6
framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/AbpHostEnvironment_Tests.cs

@ -9,12 +9,6 @@ namespace Volo.Abp.AspNetCore;
public class AbpHostEnvironment_Tests : AbpAspNetCoreTestBase<Program>
{
protected override IHost CreateHost(IHostBuilder builder)
{
builder.UseEnvironment("test");
return base.CreateHost(builder);
}
[Fact]
public void Should_Set_Environment_From_IWebHostEnvironment()
{

1
framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/Program.cs

@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Hosting;
using Volo.Abp.AspNetCore;
using Volo.Abp.AspNetCore.TestBase;
var builder = WebApplication.CreateBuilder(new WebApplicationOptions
{

1
framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/Program.cs

@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Builder;
using Volo.Abp.AspNetCore;
using Volo.Abp.AspNetCore.TestBase;
using Volo.Abp.Http;
var builder = WebApplication.CreateBuilder();

13
templates/app/aspnet-core/test/MyCompanyName.MyProjectName.Web.Tests/MyProjectNameWebTestBase.cs

@ -1,23 +1,14 @@
using System;
using System.Net;
using System.Net;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
using Shouldly;
using Volo.Abp.AspNetCore.TestBase;
namespace MyCompanyName.MyProjectName;
public abstract class MyProjectNameWebTestBase : AbpAspNetCoreIntegratedTestBase<MyProjectNameWebTestModule>
public abstract class MyProjectNameWebTestBase : AbpAspNetCoreWebApplicationFactoryIntegratedTestBase<Program>
{
protected override IHostBuilder CreateHostBuilder()
{
return base
.CreateHostBuilder()
.UseContentRoot(WebContentDirectoryFinder.CalculateContentRootFolder() ?? throw new InvalidOperationException());
}
protected virtual async Task<T?> GetResponseAsObjectAsync<T>(string url, HttpStatusCode expectedStatusCode = HttpStatusCode.OK)
{
var strResponse = await GetResponseAsStringAsync(url, expectedStatusCode);

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

@ -0,0 +1,10 @@
using Microsoft.AspNetCore.Builder;
using MyCompanyName.MyProjectName;
using Volo.Abp.AspNetCore.TestBase;
var builder = WebApplication.CreateBuilder();
await builder.RunAbpModuleAsync<MyProjectNameWebTestModule>();
public partial class Program
{
}
Loading…
Cancel
Save