diff --git a/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/WebApplicationBuilderExtensions.cs b/framework/src/Volo.Abp.AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase/WebApplicationBuilderExtensions.cs similarity index 90% rename from framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/WebApplicationBuilderExtensions.cs rename to framework/src/Volo.Abp.AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase/WebApplicationBuilderExtensions.cs index ff584d18c5..026d4da2a5 100644 --- a/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/WebApplicationBuilderExtensions.cs +++ b/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(this WebApplicationBuilder builder, Action optionsAction = null) + public async static Task RunAbpModuleAsync(this WebApplicationBuilder builder, Action? optionsAction = null) where TModule : IAbpModule { builder.Host.UseAutofac(); diff --git a/framework/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/App/Program.cs b/framework/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/App/Program.cs index e6960b28a4..d2e28ce2c1 100644 --- a/framework/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/App/Program.cs +++ b/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(); diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AspNetCoreMvcTestBase.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AspNetCoreMvcTestBase.cs index 2792448d9c..d1e02f8ebc 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AspNetCoreMvcTestBase.cs +++ b/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 { - 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); - } } diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Program.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Program.cs index 5bba766f40..9e1bf5e51c 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Program.cs +++ b/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(); diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Tests/Volo/Abp/AspNetCore/Mvc/UI/Program.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Tests/Volo/Abp/AspNetCore/Mvc/UI/Program.cs index 9775d17edc..bd6027c624 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Tests/Volo/Abp/AspNetCore/Mvc/UI/Program.cs +++ b/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(); diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests/Program.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests/Program.cs index 4bd87d1533..b7c7d4cd34 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests/Program.cs +++ b/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(); diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/Program.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/Program.cs index 88a8601822..3d85fb71f9 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/Program.cs +++ b/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(); diff --git a/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/App/Program.cs b/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/App/Program.cs index 1d6fc96801..dbbce46a5e 100644 --- a/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/App/Program.cs +++ b/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(); diff --git a/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/AbpHostEnvironment_Tests.cs b/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/AbpHostEnvironment_Tests.cs index dcd47ddc88..a87772536b 100644 --- a/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/AbpHostEnvironment_Tests.cs +++ b/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 { - protected override IHost CreateHost(IHostBuilder builder) - { - builder.UseEnvironment("test"); - return base.CreateHost(builder); - } - [Fact] public void Should_Set_Environment_From_IWebHostEnvironment() { diff --git a/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/Program.cs b/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/Program.cs index 112772fc82..841b2903c2 100644 --- a/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/Program.cs +++ b/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 { diff --git a/framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/Program.cs b/framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/Program.cs index 0cf3a51d99..a0cfe08f84 100644 --- a/framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/Program.cs +++ b/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(); diff --git a/templates/app/aspnet-core/test/MyCompanyName.MyProjectName.Web.Tests/MyProjectNameWebTestBase.cs b/templates/app/aspnet-core/test/MyCompanyName.MyProjectName.Web.Tests/MyProjectNameWebTestBase.cs index d038106f5a..139ef8d69e 100644 --- a/templates/app/aspnet-core/test/MyCompanyName.MyProjectName.Web.Tests/MyProjectNameWebTestBase.cs +++ b/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 +public abstract class MyProjectNameWebTestBase : AbpAspNetCoreWebApplicationFactoryIntegratedTestBase { - protected override IHostBuilder CreateHostBuilder() - { - return base - .CreateHostBuilder() - .UseContentRoot(WebContentDirectoryFinder.CalculateContentRootFolder() ?? throw new InvalidOperationException()); - } - protected virtual async Task GetResponseAsObjectAsync(string url, HttpStatusCode expectedStatusCode = HttpStatusCode.OK) { var strResponse = await GetResponseAsStringAsync(url, expectedStatusCode); diff --git a/templates/app/aspnet-core/test/MyCompanyName.MyProjectName.Web.Tests/Program.cs b/templates/app/aspnet-core/test/MyCompanyName.MyProjectName.Web.Tests/Program.cs new file mode 100644 index 0000000000..f4c388685f --- /dev/null +++ b/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(); + +public partial class Program +{ +}