From 0329dd29c1881a438a9a59c9df317262359cb9c0 Mon Sep 17 00:00:00 2001 From: maliming Date: Tue, 29 Aug 2023 11:00:32 +0800 Subject: [PATCH 1/5] Using `WebApplicationFactory` as web unit test base class. Resolve #17484 --- .../Volo.Abp.AspNetCore.TestBase.csproj | 1 + ...WebApplicationFactoryIntegratedTestBase.cs | 87 +++++++++++++++++++ .../Volo/Abp/AspNetCore/App/Program.cs | 10 +++ .../Volo/Abp/AspNetCore/App/Startup.cs | 19 ---- .../AspNetCoreMultiTenancyTestBase.cs | 2 +- ...reMultiTenancy_WithDomainResolver_Tests.cs | 23 +++-- ...ltiTenancy_Without_DomainResolver_Tests.cs | 15 ++-- .../Mvc/AbpAspNetCoreMvcTestModule.cs | 7 ++ .../AspNetCore/Mvc/AspNetCoreMvcTestBase.cs | 5 +- ...tIntegrationServiceTestController_Tests.cs | 6 +- .../Mvc/Auditing/AuditTestController_Tests.cs | 4 +- .../Mvc/Auditing/AuditTestPage_Tests.cs | 4 +- .../ReplaceBuiltInController_Tests.cs | 2 +- ...horizationExceptionTestController_Tests.cs | 4 +- ...AbpAuthorizationExceptionTestPage_Tests.cs | 4 +- .../ExceptionTestController_Tests.cs | 4 +- .../ExceptionTestPage_Tests.cs | 4 +- .../Mvc/Json/JsonResultController_Tests.cs | 4 +- .../Mvc/Json/JsonSerializer_Tests.cs | 4 +- .../LocalizationTestController_Tests.cs | 2 +- .../ModelBindingController_Tests.cs | 8 +- .../Volo/Abp/AspNetCore/Mvc/Program.cs | 48 ++++++++++ .../SecurityHeadersTestController_Tests.cs | 4 +- .../Volo/Abp/AspNetCore/Mvc/Startup.cs | 56 ------------ ...WorkMiddleware_Exception_Rollback_Tests.cs | 2 +- ...WorkPageFilter_Exception_Rollback_Tests.cs | 2 +- .../ValidationTestController_Tests.cs | 4 +- .../Mvc/UI/AbpAspNetCoreMvcUiTestBase.cs | 2 +- .../Volo/Abp/AspNetCore/Mvc/UI/Program.cs | 10 +++ .../Volo/Abp/AspNetCore/Mvc/UI/Startup.cs | 20 ----- .../Program.cs | 27 ++---- .../AbpAspNetCoreMvcUiThemeSharedTestBase.cs | 2 +- ...AbpAspNetCoreMvcUiThemeSharedTestModule.cs | 3 - .../Shared/PageToolbars/PageToolbar_Tests.cs | 2 +- .../AspNetCore/Mvc/UI/Theme/Shared/Startup.cs | 18 ---- .../UI/Theme/Shared/Toolbars/Toolbar_Tests.cs | 4 +- .../AspNetCoreMvcVersioningTestBase.cs | 2 +- .../Abp/AspNetCore/Mvc/Versioning/Program.cs | 10 +++ .../Abp/AspNetCore/Mvc/Versioning/Startup.cs | 20 ----- .../AspNetCore/App/AbpSerilogTestModule.cs | 9 ++ .../Volo/Abp/AspNetCore/App/Program.cs | 10 +++ .../Volo/Abp/AspNetCore/App/Startup.cs | 19 ---- .../AspNetCore/Serilog/AbpSerilogTestBase.cs | 8 +- .../Serilog/Serilog_Enrichers_Tests.cs | 14 ++- .../Abp/AspNetCore/AbpAspNetCoreTestBase.cs | 7 +- .../AspNetCore/AbpHostEnvironment_Tests.cs | 20 ++--- .../Volo/Abp/AspNetCore/Program.cs | 13 +++ .../Volo/Abp/AspNetCore/Startup.cs | 20 ----- .../WebApplicationBuilderExtensions.cs | 21 +++++ .../Volo/Abp/Http/AbpHttpClientTestBase.cs | 2 +- .../Volo/Abp/Http/AbpHttpClientTestModule.cs | 8 ++ ...lientProxy_AbpRemoteCallException_Tests.cs | 2 +- .../Volo/Abp/Http/Program.cs | 10 +++ .../Volo/Abp/Http/Startup.cs | 18 ---- 54 files changed, 328 insertions(+), 308 deletions(-) create mode 100644 framework/src/Volo.Abp.AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase/AbpAspNetCoreWebApplicationFactoryIntegratedTestBase.cs create mode 100644 framework/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/App/Program.cs delete mode 100644 framework/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/App/Startup.cs create mode 100644 framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Program.cs delete mode 100644 framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Startup.cs create mode 100644 framework/test/Volo.Abp.AspNetCore.Mvc.UI.Tests/Volo/Abp/AspNetCore/Mvc/UI/Program.cs delete mode 100644 framework/test/Volo.Abp.AspNetCore.Mvc.UI.Tests/Volo/Abp/AspNetCore/Mvc/UI/Startup.cs delete mode 100644 framework/test/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests/Volo/Abp/AspNetCore/Mvc/UI/Theme/Shared/Startup.cs create mode 100644 framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/Program.cs delete mode 100644 framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/Startup.cs create mode 100644 framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/App/Program.cs delete mode 100644 framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/App/Startup.cs create mode 100644 framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/Program.cs delete mode 100644 framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/Startup.cs create mode 100644 framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/WebApplicationBuilderExtensions.cs create mode 100644 framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/Program.cs delete mode 100644 framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/Startup.cs diff --git a/framework/src/Volo.Abp.AspNetCore.TestBase/Volo.Abp.AspNetCore.TestBase.csproj b/framework/src/Volo.Abp.AspNetCore.TestBase/Volo.Abp.AspNetCore.TestBase.csproj index a6f6a55f397..5bf1cc54aa2 100644 --- a/framework/src/Volo.Abp.AspNetCore.TestBase/Volo.Abp.AspNetCore.TestBase.csproj +++ b/framework/src/Volo.Abp.AspNetCore.TestBase/Volo.Abp.AspNetCore.TestBase.csproj @@ -28,6 +28,7 @@ + diff --git a/framework/src/Volo.Abp.AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase/AbpAspNetCoreWebApplicationFactoryIntegratedTestBase.cs b/framework/src/Volo.Abp.AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase/AbpAspNetCoreWebApplicationFactoryIntegratedTestBase.cs new file mode 100644 index 00000000000..11d27221dfe --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase/AbpAspNetCoreWebApplicationFactoryIntegratedTestBase.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using Microsoft.AspNetCore.Mvc.Testing; +using Microsoft.AspNetCore.Routing; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; + +namespace Volo.Abp.AspNetCore.TestBase; + +public abstract class AbpAspNetCoreWebApplicationFactoryIntegratedTestBase : WebApplicationFactory + where TProgram : class +{ + protected HttpClient Client { get; set; } + + public IServiceProvider ServiceProvider => Services; + + protected AbpAspNetCoreWebApplicationFactoryIntegratedTestBase() + { + Client = CreateClient(new WebApplicationFactoryClientOptions + { + AllowAutoRedirect = false + }); + ServiceProvider.GetRequiredService().Server = Server; + } + + protected override IHost CreateHost(IHostBuilder builder) + { + builder.ConfigureServices(ConfigureServices); + return base.CreateHost(builder); + } + + public virtual T? GetService() + { + return ServiceProvider!.GetService(); + } + + public virtual T GetRequiredService() where T : notnull + { + return ServiceProvider!.GetRequiredService(); + } + + protected virtual void ConfigureServices(IServiceCollection services) + { + + } + + #region GetUrl + + /// + /// Gets default URL for given controller type. + /// + /// The type of the controller. + protected virtual string GetUrl() + { + return "/" + typeof(TController).Name.RemovePostFix("Controller", "AppService", "ApplicationService", "IntService", "IntegrationService", "Service"); + } + + /// + /// Gets default URL for given controller type's given action. + /// + /// The type of the controller. + protected virtual string GetUrl(string actionName) + { + return GetUrl() + "/" + actionName; + } + + /// + /// Gets default URL for given controller type's given action with query string parameters (as anonymous object). + /// + /// The type of the controller. + protected virtual string GetUrl(string actionName, object queryStringParamsAsAnonymousObject) + { + var url = GetUrl(actionName); + + var dictionary = new RouteValueDictionary(queryStringParamsAsAnonymousObject); + if (dictionary.Any()) + { + url += "?" + dictionary.Select(d => $"{d.Key}={d.Value}").JoinAsString("&"); + } + + return url; + } + + #endregion +} 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 new file mode 100644 index 00000000000..e6960b28a42 --- /dev/null +++ b/framework/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/App/Program.cs @@ -0,0 +1,10 @@ +using Microsoft.AspNetCore.Builder; +using Volo.Abp.AspNetCore; +using Volo.Abp.AspNetCore.App; + +var builder = WebApplication.CreateBuilder(); +await builder.RunAbpModuleAsync(); + +public partial class Program +{ +} diff --git a/framework/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/App/Startup.cs b/framework/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/App/Startup.cs deleted file mode 100644 index 46981d27bed..00000000000 --- a/framework/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/App/Startup.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; - -namespace Volo.Abp.AspNetCore.App; - -public class Startup -{ - public void ConfigureServices(IServiceCollection services) - { - services.AddApplication(); - } - - public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) - { - app.InitializeApplication(); - } -} diff --git a/framework/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/MultiTenancy/AspNetCoreMultiTenancyTestBase.cs b/framework/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/MultiTenancy/AspNetCoreMultiTenancyTestBase.cs index 15991117f4f..7ff1acc7a5e 100644 --- a/framework/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/MultiTenancy/AspNetCoreMultiTenancyTestBase.cs +++ b/framework/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/MultiTenancy/AspNetCoreMultiTenancyTestBase.cs @@ -1,7 +1,7 @@ namespace Volo.Abp.AspNetCore.MultiTenancy; -public abstract class AspNetCoreMultiTenancyTestBase : AbpAspNetCoreTestBase +public abstract class AspNetCoreMultiTenancyTestBase : AbpAspNetCoreTestBase { } diff --git a/framework/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/MultiTenancy/AspNetCoreMultiTenancy_WithDomainResolver_Tests.cs b/framework/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/MultiTenancy/AspNetCoreMultiTenancy_WithDomainResolver_Tests.cs index a630df49866..e80b47b2a5d 100644 --- a/framework/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/MultiTenancy/AspNetCoreMultiTenancy_WithDomainResolver_Tests.cs +++ b/framework/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/MultiTenancy/AspNetCoreMultiTenancy_WithDomainResolver_Tests.cs @@ -24,23 +24,22 @@ public AspNetCoreMultiTenancy_WithDomainResolver_Tests() _options = ServiceProvider.GetRequiredService>().Value; } - protected override IHostBuilder CreateHostBuilder() + protected override void ConfigureServices(IServiceCollection services) { - return base.CreateHostBuilder().ConfigureServices(services => + services.Configure(options => { - services.Configure(options => + options.Tenants = new[] { - options.Tenants = new[] - { - new TenantConfiguration(_testTenantId, _testTenantName) - }; - }); + new TenantConfiguration(_testTenantId, _testTenantName) + }; + }); - services.Configure(options => - { - options.AddDomainTenantResolver("{0}.abp.io:8080"); - }); + services.Configure(options => + { + options.AddDomainTenantResolver("{0}.abp.io:8080"); }); + + base.ConfigureServices(services); } [Fact] diff --git a/framework/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/MultiTenancy/AspNetCoreMultiTenancy_Without_DomainResolver_Tests.cs b/framework/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/MultiTenancy/AspNetCoreMultiTenancy_Without_DomainResolver_Tests.cs index ccbd941bae0..56da287ef8d 100644 --- a/framework/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/MultiTenancy/AspNetCoreMultiTenancy_Without_DomainResolver_Tests.cs +++ b/framework/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/MultiTenancy/AspNetCoreMultiTenancy_Without_DomainResolver_Tests.cs @@ -25,18 +25,17 @@ public AspNetCoreMultiTenancy_Without_DomainResolver_Tests() _options = ServiceProvider.GetRequiredService>().Value; } - protected override IHostBuilder CreateHostBuilder() + protected override void ConfigureServices(IServiceCollection services) { - return base.CreateHostBuilder().ConfigureServices(services => + services.Configure(options => { - services.Configure(options => + options.Tenants = new[] { - options.Tenants = new[] - { - new TenantConfiguration(_testTenantId, _testTenantName) - }; - }); + new TenantConfiguration(_testTenantId, _testTenantName) + }; }); + + base.ConfigureServices(services); } [Fact] diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs index 6051ae65209..1b2901d304b 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs @@ -3,6 +3,7 @@ using System.Security.Claims; using Localization.Resources.AbpUi; using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Mvc.ApplicationParts; using Microsoft.AspNetCore.Mvc.Razor; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.Extensions.DependencyInjection; @@ -37,6 +38,12 @@ public class AbpAspNetCoreMvcTestModule : AbpModule public override void PreConfigureServices(ServiceConfigurationContext context) { + PreConfigure(mvcBuilder => + { + mvcBuilder.PartManager.ApplicationParts.Add(new AssemblyPart(typeof(AbpAspNetCoreMvcTestModule).Assembly)); + mvcBuilder.PartManager.ApplicationParts.Add(new CompiledRazorAssemblyPart(typeof(AbpAspNetCoreMvcTestModule).Assembly)); + }); + context.Services.PreConfigure(options => { options.AddAssemblyResource( 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 6acbb772429..2792448d9c6 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 @@ -5,7 +5,7 @@ namespace Volo.Abp.AspNetCore.Mvc; -public abstract class AspNetCoreMvcTestBase : AbpAspNetCoreTestBase +public abstract class AspNetCoreMvcTestBase : AbpAspNetCoreTestBase { protected override IHostBuilder CreateHostBuilder() { @@ -17,8 +17,7 @@ protected override IHostBuilder CreateHostBuilder() ) ); - return base.CreateHostBuilder() - .UseContentRoot(contentRootPath); + return base.CreateHostBuilder()?.UseContentRoot(contentRootPath); } private static string CalculateContentRootPath(string projectFileName, string contentPath) diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Auditing/AuditIntegrationServiceTestController_Tests.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Auditing/AuditIntegrationServiceTestController_Tests.cs index 129035f406f..74677b27c47 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Auditing/AuditIntegrationServiceTestController_Tests.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Auditing/AuditIntegrationServiceTestController_Tests.cs @@ -22,11 +22,11 @@ public AuditIntegrationServiceTestController_Tests() _auditingStore = ServiceProvider.GetRequiredService(); } - protected override void ConfigureServices(HostBuilderContext context, IServiceCollection services) + protected override void ConfigureServices(IServiceCollection services) { _auditingStore = Substitute.For(); services.Replace(ServiceDescriptor.Singleton(_auditingStore)); - base.ConfigureServices(context, services); + base.ConfigureServices(services); } [Fact] @@ -55,4 +55,4 @@ public async Task Should_Not_Write_Audit_Log_For_Controllers_With_IntegrationSer await GetResponseAsync("/integration-api/audit-test/"); await _auditingStore.DidNotReceive().SaveAsync(Arg.Any()); } -} \ No newline at end of file +} diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Auditing/AuditTestController_Tests.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Auditing/AuditTestController_Tests.cs index 78d537e252e..2a4ee0a8f2b 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Auditing/AuditTestController_Tests.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Auditing/AuditTestController_Tests.cs @@ -23,11 +23,11 @@ public AuditTestController_Tests() _auditingStore = ServiceProvider.GetRequiredService(); } - protected override void ConfigureServices(HostBuilderContext context, IServiceCollection services) + protected override void ConfigureServices(IServiceCollection services) { _auditingStore = Substitute.For(); services.Replace(ServiceDescriptor.Singleton(_auditingStore)); - base.ConfigureServices(context, services); + base.ConfigureServices(services); } [Fact] diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Auditing/AuditTestPage_Tests.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Auditing/AuditTestPage_Tests.cs index aae671d6d47..37586694571 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Auditing/AuditTestPage_Tests.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Auditing/AuditTestPage_Tests.cs @@ -22,11 +22,11 @@ public AuditTestPage_Tests() _auditingStore = ServiceProvider.GetRequiredService(); } - protected override void ConfigureServices(HostBuilderContext context, IServiceCollection services) + protected override void ConfigureServices(IServiceCollection services) { _auditingStore = Substitute.For(); services.Replace(ServiceDescriptor.Singleton(_auditingStore)); - base.ConfigureServices(context, services); + base.ConfigureServices(services); } [Fact] diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Controllers/ReplaceBuiltInController_Tests.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Controllers/ReplaceBuiltInController_Tests.cs index 46aa0369e3d..7060a91b995 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Controllers/ReplaceBuiltInController_Tests.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Controllers/ReplaceBuiltInController_Tests.cs @@ -11,7 +11,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Controllers; public class ReplaceBuiltInController_Tests : AspNetCoreMvcTestBase { - protected override void ConfigureServices(HostBuilderContext context, IServiceCollection services) + protected override void ConfigureServices(IServiceCollection services) { services.Configure(options => { diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/AbpAuthorizationExceptionTestController_Tests.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/AbpAuthorizationExceptionTestController_Tests.cs index e8e49b49466..95e6b5ca47b 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/AbpAuthorizationExceptionTestController_Tests.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/AbpAuthorizationExceptionTestController_Tests.cs @@ -24,9 +24,9 @@ public AbpAuthorizationExceptionTestController_Tests() FakeRequiredService = GetRequiredService(); } - protected override void ConfigureServices(HostBuilderContext context, IServiceCollection services) + protected override void ConfigureServices(IServiceCollection services) { - base.ConfigureServices(context, services); + base.ConfigureServices(services); FakeExceptionSubscriber = Substitute.For(); diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/AbpAuthorizationExceptionTestPage_Tests.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/AbpAuthorizationExceptionTestPage_Tests.cs index 689f3a00dca..0b10ff91da7 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/AbpAuthorizationExceptionTestPage_Tests.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/AbpAuthorizationExceptionTestPage_Tests.cs @@ -24,9 +24,9 @@ public AbpAuthorizationExceptionTestPage_Tests() _fakeRequiredService = GetRequiredService(); } - protected override void ConfigureServices(HostBuilderContext context, IServiceCollection services) + protected override void ConfigureServices(IServiceCollection services) { - base.ConfigureServices(context, services); + base.ConfigureServices(services); _fakeExceptionSubscriber = Substitute.For(); diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/ExceptionTestController_Tests.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/ExceptionTestController_Tests.cs index 2f10f4b0279..1b79441de89 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/ExceptionTestController_Tests.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/ExceptionTestController_Tests.cs @@ -26,9 +26,9 @@ public ExceptionTestController_Tests() FakeRequiredService = GetRequiredService(); } - protected override void ConfigureServices(HostBuilderContext context, IServiceCollection services) + protected override void ConfigureServices(IServiceCollection services) { - base.ConfigureServices(context, services); + base.ConfigureServices(services); _fakeExceptionSubscriber = Substitute.For(); diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/ExceptionTestPage_Tests.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/ExceptionTestPage_Tests.cs index 3290b37c957..48ccf6499ff 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/ExceptionTestPage_Tests.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/ExceptionTestPage_Tests.cs @@ -26,9 +26,9 @@ public ExceptionTestPage_Tests() _fakeRequiredService = GetRequiredService(); } - protected override void ConfigureServices(HostBuilderContext context, IServiceCollection services) + protected override void ConfigureServices(IServiceCollection services) { - base.ConfigureServices(context, services); + base.ConfigureServices(services); _fakeExceptionSubscriber = Substitute.For(); diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Json/JsonResultController_Tests.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Json/JsonResultController_Tests.cs index e7015313cb0..23c16677e20 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Json/JsonResultController_Tests.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Json/JsonResultController_Tests.cs @@ -10,14 +10,14 @@ namespace Volo.Abp.AspNetCore.Mvc.Json; public class JsonResultController_Tests : AspNetCoreMvcTestBase { - protected override void ConfigureServices(HostBuilderContext context, IServiceCollection services) + protected override void ConfigureServices(IServiceCollection services) { services.Configure(options => { options.OutputDateTimeFormat = "yyyy*MM*dd"; }); - base.ConfigureServices(context, services); + base.ConfigureServices(services); } [Fact] diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Json/JsonSerializer_Tests.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Json/JsonSerializer_Tests.cs index 1613e4bb49f..d0888a0fdf2 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Json/JsonSerializer_Tests.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Json/JsonSerializer_Tests.cs @@ -17,14 +17,14 @@ public JsonSerializer_Tests() _jsonSerializer = ServiceProvider.GetRequiredService(); } - protected override void ConfigureServices(HostBuilderContext context, IServiceCollection services) + protected override void ConfigureServices(IServiceCollection services) { services.Configure(options => { options.OutputDateTimeFormat = "yyyy*MM*dd"; }); - base.ConfigureServices(context, services); + base.ConfigureServices(services); } [Fact] diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Localization/LocalizationTestController_Tests.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Localization/LocalizationTestController_Tests.cs index b575b4ce78f..d23a5c1a9fe 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Localization/LocalizationTestController_Tests.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Localization/LocalizationTestController_Tests.cs @@ -21,7 +21,7 @@ public override Task DetermineProviderCultureResult(HttpC } } - protected override void ConfigureServices(HostBuilderContext context, IServiceCollection services) + protected override void ConfigureServices(IServiceCollection services) { services.Configure(options => { diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ModelBinding/ModelBindingController_Tests.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ModelBinding/ModelBindingController_Tests.cs index 53bfff8b687..973e2f7192c 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ModelBinding/ModelBindingController_Tests.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ModelBinding/ModelBindingController_Tests.cs @@ -122,22 +122,22 @@ public async Task Guid_Json_Test() public class ModelBindingController_Utc_Tests : ModelBindingController_Tests { - protected override void ConfigureServices(HostBuilderContext context, IServiceCollection services) + protected override void ConfigureServices(IServiceCollection services) { Kind = DateTimeKind.Utc; services.Configure(x => x.Kind = Kind); - base.ConfigureServices(context, services); + base.ConfigureServices(services); } } public class ModelBindingController_Local_Tests : ModelBindingController_Tests { - protected override void ConfigureServices(HostBuilderContext context, IServiceCollection services) + protected override void ConfigureServices(IServiceCollection services) { Kind = DateTimeKind.Local; services.Configure(x => x.Kind = Kind); - base.ConfigureServices(context, services); + base.ConfigureServices(services); } } 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 new file mode 100644 index 00000000000..5bba766f401 --- /dev/null +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Program.cs @@ -0,0 +1,48 @@ +using System; +using System.IO; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp; +using Volo.Abp.AspNetCore; +using Volo.Abp.AspNetCore.Mvc; +using Volo.Abp.Modularity.PlugIns; + +var builder = WebApplication.CreateBuilder(); +await builder.RunAbpModuleAsync(options => +{ + var hostEnvironment = options.Services.GetHostingEnvironment(); + var currentDirectory = hostEnvironment.ContentRootPath; + var plugDllInPath = ""; + + for (var i = 0; i < 10; i++) + { + var parentDirectory = new DirectoryInfo(currentDirectory).Parent; + if (parentDirectory == null) + { + break; + } + + if (parentDirectory.Name == "test") + { +#if DEBUG + plugDllInPath = Path.Combine(parentDirectory.FullName, "Volo.Abp.AspNetCore.Mvc.PlugIn", "bin", "Debug", "net7.0"); +#else + plugDllInPath = Path.Combine(parentDirectory.FullName, "Volo.Abp.AspNetCore.Mvc.PlugIn", "bin", "Release", "net7.0"); +#endif + break; + } + + currentDirectory = parentDirectory.FullName; + } + + if (plugDllInPath.IsNullOrWhiteSpace()) + { + throw new AbpException("Could not find the plug DLL path!"); + } + + options.PlugInSources.AddFolder(plugDllInPath); +}); + +public partial class Program +{ +} diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Security/Headers/SecurityHeadersTestController_Tests.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Security/Headers/SecurityHeadersTestController_Tests.cs index 4c419ef744f..dab4a034660 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Security/Headers/SecurityHeadersTestController_Tests.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Security/Headers/SecurityHeadersTestController_Tests.cs @@ -10,7 +10,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Security.Headers; public class SecurityHeadersTestController_Tests : AspNetCoreMvcTestBase { - protected override void ConfigureServices(HostBuilderContext context, IServiceCollection services) + protected override void ConfigureServices(IServiceCollection services) { services.Configure(options => { @@ -18,7 +18,7 @@ protected override void ConfigureServices(HostBuilderContext context, IServiceCo options.Headers["Referrer-Policy"] = "no-referrer"; }); - base.ConfigureServices(context, services); + base.ConfigureServices(services); } [Fact] diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Startup.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Startup.cs deleted file mode 100644 index df5a8b7b9c3..00000000000 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Startup.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; -using System.IO; -using System.Linq; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Volo.Abp.Modularity.PlugIns; - -namespace Volo.Abp.AspNetCore.Mvc; - -public class Startup -{ - public void ConfigureServices(IServiceCollection services) - { - services.AddApplication(options => - { - var hostEnvironment = services.GetHostingEnvironment(); - var currentDirectory = hostEnvironment.ContentRootPath; - var plugDllInPath = ""; - - for (var i = 0; i < 10; i++) - { - var parentDirectory = new DirectoryInfo(currentDirectory).Parent; - if (parentDirectory == null) - { - break; - } - - if (parentDirectory.Name == "test") - { -#if DEBUG - plugDllInPath = Path.Combine(parentDirectory.FullName, "Volo.Abp.AspNetCore.Mvc.PlugIn", "bin", "Debug", "net7.0"); -#else - plugDllInPath = Path.Combine(parentDirectory.FullName, "Volo.Abp.AspNetCore.Mvc.PlugIn", "bin", "Release", "net7.0"); -#endif - break; - } - - currentDirectory = parentDirectory.FullName; - } - - if (plugDllInPath.IsNullOrWhiteSpace()) - { - throw new AbpException("Could not find the plug DLL path!"); - } - - options.PlugInSources.AddFolder(plugDllInPath); - }); - } - - public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) - { - app.InitializeApplication(); - } -} diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Uow/UnitOfWorkMiddleware_Exception_Rollback_Tests.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Uow/UnitOfWorkMiddleware_Exception_Rollback_Tests.cs index 068accad6a5..7c0658638d5 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Uow/UnitOfWorkMiddleware_Exception_Rollback_Tests.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Uow/UnitOfWorkMiddleware_Exception_Rollback_Tests.cs @@ -14,7 +14,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Uow; public class UnitOfWorkMiddleware_Exception_Rollback_Tests : AspNetCoreMvcTestBase { - protected override void ConfigureServices(HostBuilderContext context, IServiceCollection services) + protected override void ConfigureServices(IServiceCollection services) { services.Replace(ServiceDescriptor.Transient()); } diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Uow/UnitOfWorkPageFilter_Exception_Rollback_Tests.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Uow/UnitOfWorkPageFilter_Exception_Rollback_Tests.cs index f5e3bf2123f..652c9362766 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Uow/UnitOfWorkPageFilter_Exception_Rollback_Tests.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Uow/UnitOfWorkPageFilter_Exception_Rollback_Tests.cs @@ -14,7 +14,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Uow; public class UnitOfWorkPageFilter_Exception_Rollback_Tests : AspNetCoreMvcTestBase { - protected override void ConfigureServices(HostBuilderContext context, IServiceCollection services) + protected override void ConfigureServices(IServiceCollection services) { services.Replace(ServiceDescriptor.Transient()); } diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Validation/ValidationTestController_Tests.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Validation/ValidationTestController_Tests.cs index 588c130a22d..ab0fd586b31 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Validation/ValidationTestController_Tests.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Validation/ValidationTestController_Tests.cs @@ -118,14 +118,14 @@ public async Task SubClass_Should_Disable_Validate_If_Action_Has_DisableValidati public class DisableAutoModelValidationTestController_Tests : AspNetCoreMvcTestBase { - protected override void ConfigureServices(HostBuilderContext context, IServiceCollection services) + protected override void ConfigureServices(IServiceCollection services) { services.Configure(options => { options.AutoModelValidation = false; }); - base.ConfigureServices(context, services); + base.ConfigureServices(services); } [Fact] diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Tests/Volo/Abp/AspNetCore/Mvc/UI/AbpAspNetCoreMvcUiTestBase.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Tests/Volo/Abp/AspNetCore/Mvc/UI/AbpAspNetCoreMvcUiTestBase.cs index 99ca4da729d..d6f6402ecac 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Tests/Volo/Abp/AspNetCore/Mvc/UI/AbpAspNetCoreMvcUiTestBase.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Tests/Volo/Abp/AspNetCore/Mvc/UI/AbpAspNetCoreMvcUiTestBase.cs @@ -2,7 +2,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI; -public abstract class AbpAspNetCoreMvcUiTestBase : AbpAspNetCoreIntegratedTestBase +public abstract class AbpAspNetCoreMvcUiTestBase : AbpAspNetCoreIntegratedTestBase { } 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 new file mode 100644 index 00000000000..9775d17edc4 --- /dev/null +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Tests/Volo/Abp/AspNetCore/Mvc/UI/Program.cs @@ -0,0 +1,10 @@ +using Microsoft.AspNetCore.Builder; +using Volo.Abp.AspNetCore; +using Volo.Abp.AspNetCore.Mvc.UI; + +var builder = WebApplication.CreateBuilder(); +await builder.RunAbpModuleAsync(); + +public partial class Program +{ +} diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Tests/Volo/Abp/AspNetCore/Mvc/UI/Startup.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Tests/Volo/Abp/AspNetCore/Mvc/UI/Startup.cs deleted file mode 100644 index 0e1954b6309..00000000000 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Tests/Volo/Abp/AspNetCore/Mvc/UI/Startup.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; - -namespace Volo.Abp.AspNetCore.Mvc.UI; - -public class Startup -{ - public void ConfigureServices(IServiceCollection services) - { - services.AddApplication(); - } - - public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) - { - app.InitializeApplication(); - } -} 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 3f2eaedeb01..4bd87d1533d 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,25 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; +using Microsoft.AspNetCore.Builder; +using Volo.Abp.AspNetCore; +using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests.Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; -namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests; +var builder = WebApplication.CreateBuilder(); +await builder.RunAbpModuleAsync(); -public class Program +public partial class Program { - public static void Main(string[] args) - { - CreateHostBuilder(args).Build().Run(); - } - - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup(); - }); } diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests/Volo/Abp/AspNetCore/Mvc/UI/Theme/Shared/AbpAspNetCoreMvcUiThemeSharedTestBase.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests/Volo/Abp/AspNetCore/Mvc/UI/Theme/Shared/AbpAspNetCoreMvcUiThemeSharedTestBase.cs index b450dd97d25..1f7f5f2a82d 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests/Volo/Abp/AspNetCore/Mvc/UI/Theme/Shared/AbpAspNetCoreMvcUiThemeSharedTestBase.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests/Volo/Abp/AspNetCore/Mvc/UI/Theme/Shared/AbpAspNetCoreMvcUiThemeSharedTestBase.cs @@ -1,5 +1,5 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests.Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; -public class AbpAspNetCoreMvcUiThemeSharedTestBase : AbpAspNetCoreTestBase +public class AbpAspNetCoreMvcUiThemeSharedTestBase : AbpAspNetCoreTestBase { } diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests/Volo/Abp/AspNetCore/Mvc/UI/Theme/Shared/AbpAspNetCoreMvcUiThemeSharedTestModule.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests/Volo/Abp/AspNetCore/Mvc/UI/Theme/Shared/AbpAspNetCoreMvcUiThemeSharedTestModule.cs index bfc1303970f..a665d2c49dd 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests/Volo/Abp/AspNetCore/Mvc/UI/Theme/Shared/AbpAspNetCoreMvcUiThemeSharedTestModule.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests/Volo/Abp/AspNetCore/Mvc/UI/Theme/Shared/AbpAspNetCoreMvcUiThemeSharedTestModule.cs @@ -11,8 +11,5 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests.Volo.Abp.AspNetCore.Mvc. )] public class AbpAspNetCoreMvcUiThemeSharedTestModule : AbpModule { - public override void ConfigureServices(ServiceConfigurationContext context) - { - } } diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests/Volo/Abp/AspNetCore/Mvc/UI/Theme/Shared/PageToolbars/PageToolbar_Tests.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests/Volo/Abp/AspNetCore/Mvc/UI/Theme/Shared/PageToolbars/PageToolbar_Tests.cs index 4bd8c2d036d..cab4ca631c6 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests/Volo/Abp/AspNetCore/Mvc/UI/Theme/Shared/PageToolbars/PageToolbar_Tests.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests/Volo/Abp/AspNetCore/Mvc/UI/Theme/Shared/PageToolbars/PageToolbar_Tests.cs @@ -13,7 +13,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests.Volo.Abp.AspNetCore.Mvc. public class PageToolbar_Tests : AbpAspNetCoreMvcUiThemeSharedTestBase { - protected override void ConfigureServices(HostBuilderContext context, IServiceCollection services) + protected override void ConfigureServices(IServiceCollection services) { services.Configure(options => { diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests/Volo/Abp/AspNetCore/Mvc/UI/Theme/Shared/Startup.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests/Volo/Abp/AspNetCore/Mvc/UI/Theme/Shared/Startup.cs deleted file mode 100644 index d17ee6203b3..00000000000 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests/Volo/Abp/AspNetCore/Mvc/UI/Theme/Shared/Startup.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; -using Microsoft.AspNetCore.Builder; -using Microsoft.Extensions.Logging; - -namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests.Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; - -public class Startup -{ - public void ConfigureServices(IServiceCollection services) - { - services.AddApplication(); - } - - public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) - { - app.InitializeApplication(); - } -} diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests/Volo/Abp/AspNetCore/Mvc/UI/Theme/Shared/Toolbars/Toolbar_Tests.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests/Volo/Abp/AspNetCore/Mvc/UI/Theme/Shared/Toolbars/Toolbar_Tests.cs index d9e5be8b2d2..2c5394a9318 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests/Volo/Abp/AspNetCore/Mvc/UI/Theme/Shared/Toolbars/Toolbar_Tests.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests/Volo/Abp/AspNetCore/Mvc/UI/Theme/Shared/Toolbars/Toolbar_Tests.cs @@ -19,7 +19,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests.Volo.Abp.AspNetCore.Mvc. public class Toolbar_Tests : AbpAspNetCoreMvcUiThemeSharedTestBase { - protected override void ConfigureServices(HostBuilderContext context, IServiceCollection services) + protected override void ConfigureServices(IServiceCollection services) { services.Configure(options => { @@ -35,7 +35,7 @@ protected override void ConfigureServices(HostBuilderContext context, IServiceCo var claimsPrincipal = new ClaimsPrincipal(identity); var principalAccessor = Substitute.For(); principalAccessor.Principal.Returns(ci => claimsPrincipal); - Thread.CurrentPrincipal = claimsPrincipal; + services.Replace(ServiceDescriptor.Singleton(principalAccessor)); var themeManager = Substitute.For(); themeManager.CurrentTheme.Returns(x => null); diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/AspNetCoreMvcVersioningTestBase.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/AspNetCoreMvcVersioningTestBase.cs index 0df183aca16..5792517562d 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/AspNetCoreMvcVersioningTestBase.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/AspNetCoreMvcVersioningTestBase.cs @@ -1,5 +1,5 @@ namespace Volo.Abp.AspNetCore.Mvc.Versioning; -public abstract class AspNetCoreMvcVersioningTestBase : AbpAspNetCoreTestBase +public abstract class AspNetCoreMvcVersioningTestBase : AbpAspNetCoreTestBase { } 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 new file mode 100644 index 00000000000..88a86018224 --- /dev/null +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/Program.cs @@ -0,0 +1,10 @@ +using Microsoft.AspNetCore.Builder; +using Volo.Abp.AspNetCore; +using Volo.Abp.AspNetCore.Mvc.Versioning; + +var builder = WebApplication.CreateBuilder(); +await builder.RunAbpModuleAsync(); + +public partial class Program +{ +} diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/Startup.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/Startup.cs deleted file mode 100644 index 4ccb18feace..00000000000 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/Startup.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; - -namespace Volo.Abp.AspNetCore.Mvc.Versioning; - -public class Startup -{ - public void ConfigureServices(IServiceCollection services) - { - services.AddApplication(); - } - - public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) - { - app.InitializeApplication(); - } -} diff --git a/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/App/AbpSerilogTestModule.cs b/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/App/AbpSerilogTestModule.cs index 992800cda55..4088412b88f 100644 --- a/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/App/AbpSerilogTestModule.cs +++ b/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/App/AbpSerilogTestModule.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; using Volo.Abp.AspNetCore.MultiTenancy; using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Serilog; @@ -18,6 +19,14 @@ namespace Volo.Abp.AspNetCore.App; )] public class AbpSerilogTestModule : AbpModule { + public override void PreConfigureServices(ServiceConfigurationContext context) + { + PreConfigure(mvcBuilder => + { + mvcBuilder.AddApplicationPartIfNotExists(typeof(AbpSerilogTestModule).Assembly); + }); + } + public override void ConfigureServices(ServiceConfigurationContext context) { Configure(options => { options.IsEnabled = true; }); 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 new file mode 100644 index 00000000000..1d6fc968015 --- /dev/null +++ b/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/App/Program.cs @@ -0,0 +1,10 @@ +using Microsoft.AspNetCore.Builder; +using Volo.Abp.AspNetCore; +using Volo.Abp.AspNetCore.App; + +var builder = WebApplication.CreateBuilder(); +await builder.RunAbpModuleAsync(); + +public partial class Program +{ +} diff --git a/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/App/Startup.cs b/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/App/Startup.cs deleted file mode 100644 index 8464f6e77be..00000000000 --- a/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/App/Startup.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; - -namespace Volo.Abp.AspNetCore.App; - -public class Startup -{ - public void ConfigureServices(IServiceCollection services) - { - services.AddApplication(); - } - - public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) - { - app.InitializeApplication(); - } -} diff --git a/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/Serilog/AbpSerilogTestBase.cs b/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/Serilog/AbpSerilogTestBase.cs index acfb7e54d06..acf053ced75 100644 --- a/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/Serilog/AbpSerilogTestBase.cs +++ b/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/Serilog/AbpSerilogTestBase.cs @@ -6,11 +6,11 @@ namespace Volo.Abp.AspNetCore.Serilog; -public class AbpSerilogTestBase : AbpAspNetCoreTestBase +public class AbpSerilogTestBase : AbpAspNetCoreTestBase { protected readonly CollectingSink CollectingSink = new CollectingSink(); - protected override IHostBuilder CreateHostBuilder() + protected override IHost CreateHost(IHostBuilder builder) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Information() @@ -19,8 +19,8 @@ protected override IHostBuilder CreateHostBuilder() .WriteTo.Sink(CollectingSink) .CreateLogger(); - return base.CreateHostBuilder() - .UseSerilog(); + builder.UseSerilog(); + return base.CreateHost(builder);; } protected LogEvent GetLogEvent(string text) diff --git a/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/Serilog/Serilog_Enrichers_Tests.cs b/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/Serilog/Serilog_Enrichers_Tests.cs index b8f197d3c13..4782a5e7688 100644 --- a/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/Serilog/Serilog_Enrichers_Tests.cs +++ b/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/Serilog/Serilog_Enrichers_Tests.cs @@ -33,18 +33,16 @@ public Serilog_Enrichers_Tests() _logger = ServiceProvider.GetRequiredService>(); } - protected override IHostBuilder CreateHostBuilder() + protected override void ConfigureServices(IServiceCollection services) { - return base.CreateHostBuilder().ConfigureServices(services => + services.Configure(options => { - services.Configure(options => + options.Tenants = new[] { - options.Tenants = new[] - { - new TenantConfiguration(_testTenantId, _testTenantName) - }; - }); + new TenantConfiguration(_testTenantId, _testTenantName) + }; }); + base.ConfigureServices(services); } [Fact] diff --git a/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/AbpAspNetCoreTestBase.cs b/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/AbpAspNetCoreTestBase.cs index a79c4998e8d..29a157a3f59 100644 --- a/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/AbpAspNetCoreTestBase.cs +++ b/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/AbpAspNetCoreTestBase.cs @@ -9,13 +9,12 @@ namespace Volo.Abp.AspNetCore; -public class AbpAspNetCoreTestBase : AbpAspNetCoreTestBase +public class AbpAspNetCoreTestBase : AbpAspNetCoreTestBase { - } -public abstract class AbpAspNetCoreTestBase : AbpAspNetCoreIntegratedTestBase - where TStartup : class +public abstract class AbpAspNetCoreTestBase : AbpAspNetCoreWebApplicationFactoryIntegratedTestBase + where TProgram : class { protected virtual async Task GetResponseAsObjectAsync(string url, HttpStatusCode expectedStatusCode = HttpStatusCode.OK) { 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 16799162bbe..dcd47ddc884 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 @@ -1,7 +1,5 @@ -using System.Collections.Generic; -using System.Threading.Tasks; +using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; -using Microsoft.Extensions.Configuration.Memory; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Shouldly; @@ -9,20 +7,12 @@ namespace Volo.Abp.AspNetCore; -public class AbpHostEnvironment_Tests : AbpAspNetCoreTestBase +public class AbpHostEnvironment_Tests : AbpAspNetCoreTestBase { - protected override IHostBuilder CreateHostBuilder() + protected override IHost CreateHost(IHostBuilder builder) { - var builder = base.CreateHostBuilder(); - builder.ConfigureHostConfiguration(x => x.Sources.Insert(0, - new MemoryConfigurationSource() - { - InitialData = new List> - { - new(HostDefaults.EnvironmentKey, Environments.Staging), - } - })); - return builder; + builder.UseEnvironment("test"); + return base.CreateHost(builder); } [Fact] 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 new file mode 100644 index 00000000000..112772fc82a --- /dev/null +++ b/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/Program.cs @@ -0,0 +1,13 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.Hosting; +using Volo.Abp.AspNetCore; + +var builder = WebApplication.CreateBuilder(new WebApplicationOptions +{ + EnvironmentName = Environments.Staging +}); +await builder.RunAbpModuleAsync(); + +public partial class Program +{ +} diff --git a/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/Startup.cs b/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/Startup.cs deleted file mode 100644 index 133b77fcc82..00000000000 --- a/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/Startup.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; - -namespace Volo.Abp.AspNetCore; - -public class Startup -{ - public void ConfigureServices(IServiceCollection services) - { - services.AddApplication(); - } - - public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) - { - app.InitializeApplication(); - } -} diff --git a/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/WebApplicationBuilderExtensions.cs b/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/WebApplicationBuilderExtensions.cs new file mode 100644 index 00000000000..ff584d18c5d --- /dev/null +++ b/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/WebApplicationBuilderExtensions.cs @@ -0,0 +1,21 @@ +using System; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Volo.Abp.Modularity; + +namespace Volo.Abp.AspNetCore; + +public static class WebApplicationBuilderExtensions +{ + public async static Task RunAbpModuleAsync(this WebApplicationBuilder builder, Action optionsAction = null) + where TModule : IAbpModule + { + builder.Host.UseAutofac(); + await builder.AddApplicationAsync(optionsAction); + var app = builder.Build(); + await app.InitializeApplicationAsync(); + await app.RunAsync(); + } +} diff --git a/framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/AbpHttpClientTestBase.cs b/framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/AbpHttpClientTestBase.cs index 9ae4370b381..dfa5c335b20 100644 --- a/framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/AbpHttpClientTestBase.cs +++ b/framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/AbpHttpClientTestBase.cs @@ -2,7 +2,7 @@ namespace Volo.Abp.Http; -public abstract class AbpHttpClientTestBase : AbpAspNetCoreTestBase +public abstract class AbpHttpClientTestBase : AbpAspNetCoreTestBase { } diff --git a/framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/AbpHttpClientTestModule.cs b/framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/AbpHttpClientTestModule.cs index 6540b717d3a..003cd065e25 100644 --- a/framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/AbpHttpClientTestModule.cs +++ b/framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/AbpHttpClientTestModule.cs @@ -21,6 +21,14 @@ namespace Volo.Abp.Http; )] public class AbpHttpClientTestModule : AbpModule { + public override void PreConfigureServices(ServiceConfigurationContext context) + { + PreConfigure(mvcBuilder => + { + mvcBuilder.AddApplicationPartIfNotExists(typeof(AbpHttpClientTestModule).Assembly); + }); + } + public override void ConfigureServices(ServiceConfigurationContext context) { context.Services.AddHttpClientProxies(typeof(TestAppModule).Assembly); diff --git a/framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/RegularTestControllerClientProxy_AbpRemoteCallException_Tests.cs b/framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/RegularTestControllerClientProxy_AbpRemoteCallException_Tests.cs index 8469ba121a9..f679ccd9c9c 100644 --- a/framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/RegularTestControllerClientProxy_AbpRemoteCallException_Tests.cs +++ b/framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/RegularTestControllerClientProxy_AbpRemoteCallException_Tests.cs @@ -20,7 +20,7 @@ public RegularTestControllerClientProxy_AbpRemoteCallException_Tests() _controller = ServiceProvider.GetRequiredService(); } - protected override void ConfigureServices(HostBuilderContext context, IServiceCollection services) + protected override void ConfigureServices(IServiceCollection services) { services.Replace(ServiceDescriptor.Singleton()); } 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 new file mode 100644 index 00000000000..0cf3a51d994 --- /dev/null +++ b/framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/Program.cs @@ -0,0 +1,10 @@ +using Microsoft.AspNetCore.Builder; +using Volo.Abp.AspNetCore; +using Volo.Abp.Http; + +var builder = WebApplication.CreateBuilder(); +await builder.RunAbpModuleAsync(); + +public partial class Program +{ +} diff --git a/framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/Startup.cs b/framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/Startup.cs deleted file mode 100644 index 063b9999c10..00000000000 --- a/framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/Startup.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using Microsoft.AspNetCore.Builder; -using Microsoft.Extensions.DependencyInjection; - -namespace Volo.Abp.Http; - -public class Startup -{ - public void ConfigureServices(IServiceCollection services) - { - services.AddApplication(); - } - - public void Configure(IApplicationBuilder app) - { - app.InitializeApplication(); - } -} From 5b903a4eb5faf9be2702629da6be6dbcc587a627 Mon Sep 17 00:00:00 2001 From: maliming Date: Tue, 29 Aug 2023 11:31:45 +0800 Subject: [PATCH 2/5] Use `WebApplicationFactory` in template project. --- .../WebApplicationBuilderExtensions.cs | 4 +-- .../Volo/Abp/AspNetCore/App/Program.cs | 1 + .../AspNetCore/Mvc/AspNetCoreMvcTestBase.cs | 34 ------------------- .../Volo/Abp/AspNetCore/Mvc/Program.cs | 1 + .../Volo/Abp/AspNetCore/Mvc/UI/Program.cs | 1 + .../Program.cs | 1 + .../Abp/AspNetCore/Mvc/Versioning/Program.cs | 1 + .../Volo/Abp/AspNetCore/App/Program.cs | 1 + .../AspNetCore/AbpHostEnvironment_Tests.cs | 6 ---- .../Volo/Abp/AspNetCore/Program.cs | 1 + .../Volo/Abp/Http/Program.cs | 1 + .../MyProjectNameWebTestBase.cs | 13 ++----- .../Program.cs | 10 ++++++ 13 files changed, 22 insertions(+), 53 deletions(-) rename framework/{test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore => src/Volo.Abp.AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase}/WebApplicationBuilderExtensions.cs (90%) create mode 100644 templates/app/aspnet-core/test/MyCompanyName.MyProjectName.Web.Tests/Program.cs 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 ff584d18c5d..026d4da2a5c 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.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 e6960b28a42..d2e28ce2c18 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 2792448d9c6..d1e02f8ebcb 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 5bba766f401..9e1bf5e51c6 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 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 9775d17edc4..bd6027c6243 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 4bd87d1533d..b7c7d4cd343 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 88a86018224..3d85fb71f9e 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 1d6fc968015..dbbce46a5e8 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 dcd47ddc884..a87772536bb 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 112772fc82a..841b2903c2c 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 0cf3a51d994..a0cfe08f845 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 d038106f5a0..139ef8d69e2 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 00000000000..f4c388685f1 --- /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 +{ +} From 29005af5eac173e3b0f8ee30b55529b84acf1faf Mon Sep 17 00:00:00 2001 From: maliming Date: Tue, 29 Aug 2023 14:51:46 +0800 Subject: [PATCH 3/5] `Obsolete` the `AbpAspNetCoreAsyncIntegratedTestBase` and `AbpAspNetCoreIntegratedTestBase ` --- .../AbpAspNetCoreAsyncIntegratedTestBase.cs | 1 + .../TestBase/AbpAspNetCoreIntegratedTestBase.cs | 3 ++- ...s => AbpWebApplicationFactoryIntegratedTest.cs} | 14 +++++++------- .../Mvc/UI/AbpAspNetCoreMvcUiTestBase.cs | 6 ++---- .../Volo/Abp/AspNetCore/AbpAspNetCoreTestBase.cs | 2 +- .../MyProjectNameWebTestBase.cs | 3 ++- 6 files changed, 15 insertions(+), 14 deletions(-) rename framework/src/Volo.Abp.AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase/{AbpAspNetCoreWebApplicationFactoryIntegratedTestBase.cs => AbpWebApplicationFactoryIntegratedTest.cs} (83%) diff --git a/framework/src/Volo.Abp.AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase/AbpAspNetCoreAsyncIntegratedTestBase.cs b/framework/src/Volo.Abp.AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase/AbpAspNetCoreAsyncIntegratedTestBase.cs index 88926233645..e6c49d475c4 100644 --- a/framework/src/Volo.Abp.AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase/AbpAspNetCoreAsyncIntegratedTestBase.cs +++ b/framework/src/Volo.Abp.AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase/AbpAspNetCoreAsyncIntegratedTestBase.cs @@ -13,6 +13,7 @@ namespace Volo.Abp.AspNetCore.TestBase; +[Obsolete("Use AbpWebApplicationFactoryIntegratedTest instead.")] public class AbpAspNetCoreAsyncIntegratedTestBase where TModule : IAbpModule { diff --git a/framework/src/Volo.Abp.AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase/AbpAspNetCoreIntegratedTestBase.cs b/framework/src/Volo.Abp.AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase/AbpAspNetCoreIntegratedTestBase.cs index c362d5074c1..731b21ea03c 100644 --- a/framework/src/Volo.Abp.AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase/AbpAspNetCoreIntegratedTestBase.cs +++ b/framework/src/Volo.Abp.AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase/AbpAspNetCoreIntegratedTestBase.cs @@ -14,6 +14,7 @@ namespace Volo.Abp.AspNetCore.TestBase; /// /// Can be a module type or old-style ASP.NET Core Startup class. /// +[Obsolete("Use AbpWebApplicationFactoryIntegratedTest instead.")] public abstract class AbpAspNetCoreIntegratedTestBase : AbpTestBaseWithServiceProvider, IDisposable where TStartupModule : class { @@ -51,7 +52,7 @@ protected virtual IHostBuilder CreateHostBuilder() { webBuilder.UseStartup(); } - + webBuilder.UseAbpTestServer(); }) .UseAutofac() diff --git a/framework/src/Volo.Abp.AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase/AbpAspNetCoreWebApplicationFactoryIntegratedTestBase.cs b/framework/src/Volo.Abp.AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase/AbpWebApplicationFactoryIntegratedTest.cs similarity index 83% rename from framework/src/Volo.Abp.AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase/AbpAspNetCoreWebApplicationFactoryIntegratedTestBase.cs rename to framework/src/Volo.Abp.AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase/AbpWebApplicationFactoryIntegratedTest.cs index 11d27221dfe..c7b5f48ebec 100644 --- a/framework/src/Volo.Abp.AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase/AbpAspNetCoreWebApplicationFactoryIntegratedTestBase.cs +++ b/framework/src/Volo.Abp.AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase/AbpWebApplicationFactoryIntegratedTest.cs @@ -9,14 +9,14 @@ namespace Volo.Abp.AspNetCore.TestBase; -public abstract class AbpAspNetCoreWebApplicationFactoryIntegratedTestBase : WebApplicationFactory +public abstract class AbpWebApplicationFactoryIntegratedTest : WebApplicationFactory where TProgram : class { protected HttpClient Client { get; set; } - public IServiceProvider ServiceProvider => Services; + protected IServiceProvider ServiceProvider => Services; - protected AbpAspNetCoreWebApplicationFactoryIntegratedTestBase() + protected AbpWebApplicationFactoryIntegratedTest() { Client = CreateClient(new WebApplicationFactoryClientOptions { @@ -31,14 +31,14 @@ protected override IHost CreateHost(IHostBuilder builder) return base.CreateHost(builder); } - public virtual T? GetService() + protected virtual T? GetService() { - return ServiceProvider!.GetService(); + return Services.GetService(); } - public virtual T GetRequiredService() where T : notnull + protected virtual T GetRequiredService() where T : notnull { - return ServiceProvider!.GetRequiredService(); + return Services.GetRequiredService(); } protected virtual void ConfigureServices(IServiceCollection services) diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Tests/Volo/Abp/AspNetCore/Mvc/UI/AbpAspNetCoreMvcUiTestBase.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Tests/Volo/Abp/AspNetCore/Mvc/UI/AbpAspNetCoreMvcUiTestBase.cs index d6f6402ecac..43167ce47d6 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Tests/Volo/Abp/AspNetCore/Mvc/UI/AbpAspNetCoreMvcUiTestBase.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Tests/Volo/Abp/AspNetCore/Mvc/UI/AbpAspNetCoreMvcUiTestBase.cs @@ -1,8 +1,6 @@ -using Volo.Abp.AspNetCore.TestBase; +namespace Volo.Abp.AspNetCore.Mvc.UI; -namespace Volo.Abp.AspNetCore.Mvc.UI; - -public abstract class AbpAspNetCoreMvcUiTestBase : AbpAspNetCoreIntegratedTestBase +public abstract class AbpAspNetCoreMvcUiTestBase : AbpAspNetCoreTestBase { } diff --git a/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/AbpAspNetCoreTestBase.cs b/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/AbpAspNetCoreTestBase.cs index 29a157a3f59..f78f27f141c 100644 --- a/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/AbpAspNetCoreTestBase.cs +++ b/framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/AbpAspNetCoreTestBase.cs @@ -13,7 +13,7 @@ public class AbpAspNetCoreTestBase : AbpAspNetCoreTestBase { } -public abstract class AbpAspNetCoreTestBase : AbpAspNetCoreWebApplicationFactoryIntegratedTestBase +public abstract class AbpAspNetCoreTestBase : AbpWebApplicationFactoryIntegratedTest where TProgram : class { protected virtual async Task GetResponseAsObjectAsync(string url, HttpStatusCode expectedStatusCode = HttpStatusCode.OK) 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 139ef8d69e2..f6c290ef6d8 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 @@ -3,11 +3,12 @@ using System.Text.Json; using System.Threading.Tasks; using Shouldly; +using Volo.Abp.AspNetCore; using Volo.Abp.AspNetCore.TestBase; namespace MyCompanyName.MyProjectName; -public abstract class MyProjectNameWebTestBase : AbpAspNetCoreWebApplicationFactoryIntegratedTestBase +public abstract class MyProjectNameWebTestBase : AbpWebApplicationFactoryIntegratedTest { protected virtual async Task GetResponseAsObjectAsync(string url, HttpStatusCode expectedStatusCode = HttpStatusCode.OK) { From 257ad413c12889b46e1ff6b74e75bda65a930d25 Mon Sep 17 00:00:00 2001 From: maliming Date: Tue, 29 Aug 2023 15:44:16 +0800 Subject: [PATCH 4/5] Set `ApplicationName` as current `assembly name`. --- .../TestBase/WebApplicationBuilderExtensions.cs | 6 ++++++ .../Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs | 7 ------- .../Volo/Abp/AspNetCore/App/AbpSerilogTestModule.cs | 9 --------- .../Volo/Abp/Http/AbpHttpClientTestModule.cs | 9 --------- 4 files changed, 6 insertions(+), 25 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase/WebApplicationBuilderExtensions.cs b/framework/src/Volo.Abp.AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase/WebApplicationBuilderExtensions.cs index 026d4da2a5c..403bbac7b15 100644 --- a/framework/src/Volo.Abp.AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase/WebApplicationBuilderExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase/WebApplicationBuilderExtensions.cs @@ -12,6 +12,12 @@ public static class WebApplicationBuilderExtensions public async static Task RunAbpModuleAsync(this WebApplicationBuilder builder, Action? optionsAction = null) where TModule : IAbpModule { + var assemblyName = typeof(TModule).Assembly.GetName()?.Name; + if (!assemblyName.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.Host.UseAutofac(); await builder.AddApplicationAsync(optionsAction); var app = builder.Build(); diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs index 1b2901d304b..6051ae65209 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs @@ -3,7 +3,6 @@ using System.Security.Claims; using Localization.Resources.AbpUi; using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Mvc.ApplicationParts; using Microsoft.AspNetCore.Mvc.Razor; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.Extensions.DependencyInjection; @@ -38,12 +37,6 @@ public class AbpAspNetCoreMvcTestModule : AbpModule public override void PreConfigureServices(ServiceConfigurationContext context) { - PreConfigure(mvcBuilder => - { - mvcBuilder.PartManager.ApplicationParts.Add(new AssemblyPart(typeof(AbpAspNetCoreMvcTestModule).Assembly)); - mvcBuilder.PartManager.ApplicationParts.Add(new CompiledRazorAssemblyPart(typeof(AbpAspNetCoreMvcTestModule).Assembly)); - }); - context.Services.PreConfigure(options => { options.AddAssemblyResource( diff --git a/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/App/AbpSerilogTestModule.cs b/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/App/AbpSerilogTestModule.cs index 4088412b88f..992800cda55 100644 --- a/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/App/AbpSerilogTestModule.cs +++ b/framework/test/Volo.Abp.AspNetCore.Serilog.Tests/Volo/Abp/AspNetCore/App/AbpSerilogTestModule.cs @@ -1,5 +1,4 @@ using Microsoft.AspNetCore.Builder; -using Microsoft.Extensions.DependencyInjection; using Volo.Abp.AspNetCore.MultiTenancy; using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Serilog; @@ -19,14 +18,6 @@ namespace Volo.Abp.AspNetCore.App; )] public class AbpSerilogTestModule : AbpModule { - public override void PreConfigureServices(ServiceConfigurationContext context) - { - PreConfigure(mvcBuilder => - { - mvcBuilder.AddApplicationPartIfNotExists(typeof(AbpSerilogTestModule).Assembly); - }); - } - public override void ConfigureServices(ServiceConfigurationContext context) { Configure(options => { options.IsEnabled = true; }); diff --git a/framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/AbpHttpClientTestModule.cs b/framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/AbpHttpClientTestModule.cs index 003cd065e25..5e9107a23be 100644 --- a/framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/AbpHttpClientTestModule.cs +++ b/framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/AbpHttpClientTestModule.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using Microsoft.Extensions.DependencyInjection; using Volo.Abp.AspNetCore.Mvc; -using Volo.Abp.AspNetCore.Mvc.Conventions; using Volo.Abp.Http.Client; using Volo.Abp.Http.Client.ClientProxying; using Volo.Abp.Http.DynamicProxying; @@ -21,14 +20,6 @@ namespace Volo.Abp.Http; )] public class AbpHttpClientTestModule : AbpModule { - public override void PreConfigureServices(ServiceConfigurationContext context) - { - PreConfigure(mvcBuilder => - { - mvcBuilder.AddApplicationPartIfNotExists(typeof(AbpHttpClientTestModule).Assembly); - }); - } - public override void ConfigureServices(ServiceConfigurationContext context) { context.Services.AddHttpClientProxies(typeof(TestAppModule).Assembly); From 16999d649b33b0bc02a6243ea77dde6682623996 Mon Sep 17 00:00:00 2001 From: maliming Date: Tue, 29 Aug 2023 16:36:34 +0800 Subject: [PATCH 5/5] Update `Testing` document. --- docs/en/UI/AspNetCore/Testing.md | 19 +++---------------- docs/zh-Hans/UI/AspNetCore/Testing.md | 19 +++---------------- 2 files changed, 6 insertions(+), 32 deletions(-) diff --git a/docs/en/UI/AspNetCore/Testing.md b/docs/en/UI/AspNetCore/Testing.md index 2c880594d30..6efc967cb02 100644 --- a/docs/en/UI/AspNetCore/Testing.md +++ b/docs/en/UI/AspNetCore/Testing.md @@ -198,23 +198,10 @@ ABP Framework doesn't provide any infrastructure to test your JavaScript code. Y > Volo.Abp.AspNetCore.TestBase package is already installed in the `.Web.Tests` project. -This package provides the `AbpAspNetCoreIntegratedTestBase` as the fundamental base class to derive the test classes from. The `MyProjectWebTestBase` base class used above inherits from the `AbpAspNetCoreIntegratedTestBase`, so we indirectly inherited the `AbpAspNetCoreIntegratedTestBase`. +This package provides the `AbpWebApplicationFactoryIntegratedTest` as the fundamental base class to derive the test classes from. It's inherited from the [WebApplicationFactory](https://learn.microsoft.com/en-us/aspnet/core/test/integration-tests) class provided by the ASP.NET Core. -### Base Properties - -The `AbpAspNetCoreIntegratedTestBase` provides the following base properties those are used in the tests: - -* `Server`: A `TestServer` instance that hosts the web application in tests. -* `Client`: An `HttpClient` instance that is configured to perform requests to the test server. -* `ServiceProvider`: The service provider that you can resolve services in case of need. - -### Base Methods - -`AbpAspNetCoreIntegratedTestBase` provides the following methods that you can override if you need to customize the test server: - -* `ConfigureServices` can be overridden to register/replace services only for the derived test class. -* `CreateHostBuilder` can be used to customize building the `IHostBuilder`. +The `MyProjectWebTestBase` base class used above inherits from the `AbpWebApplicationFactoryIntegratedTest`, so we indirectly inherited the `AbpWebApplicationFactoryIntegratedTest`. See Also - +* [Integration tests in ASP.NET Core](https://learn.microsoft.com/en-us/aspnet/core/test/integration-tests) * [Overall / Server Side Testing](../../Testing.md) \ No newline at end of file diff --git a/docs/zh-Hans/UI/AspNetCore/Testing.md b/docs/zh-Hans/UI/AspNetCore/Testing.md index e5b09353fbe..1dfdbe367eb 100644 --- a/docs/zh-Hans/UI/AspNetCore/Testing.md +++ b/docs/zh-Hans/UI/AspNetCore/Testing.md @@ -198,23 +198,10 @@ ABP框架不提供任何基础设施来测试JavaScript代码. 你可以使用 > Volo.Abp.AspNetCore.TestBase 已经安装在 `.Web.Tests` 项目中. -此包提供的`AbpAspNetCoreIntegratedTestBase`作为派生测试类的基类. 上面使用的`MyProjectWebTestBase`继承自`AbpAspNetCoreIntegratedTestBase`, 因此我们间接继承了`AbpAspNetCoreIntegratedTestBase`. - -### 基本属性 - -`AbpAspNetCoreIntegratedTestBase` 提供了测试中使用的以下基本属性: - -* `Server`: 在测试中托管web应用程序的`TestServer`实例. -* `Client`: 为执行对测试服务器的请求配置`HttpClient`实例. -* `ServiceProvider`: 可以在你需要时处理服务提供服务. - -### 基本方法 - -`AbpAspNetCoreIntegratedTestBase` 提供了以下方法, 如果需要自定义测试服务器, 可以重写这些方法: - -* `ConfigureServices` 仅为派生测试类注册/替换服务时可以重写使用. -* `CreateHostBuilder` 可用于自定义生成 `IHostBuilder`. +此包提供的`AbpWebApplicationFactoryIntegratedTest`作为派生测试类的基类. 它继承自ASP.NET Core提供的[WebApplicationFactory](https://learn.microsoft.com/zh-cn/aspnet/core/test/integration-tests)类。 +上面使用的`MyProjectWebTestBase`继承自`AbpWebApplicationFactoryIntegratedTest`, 因此我们间接继承了`AbpWebApplicationFactoryIntegratedTest`. 另请参阅 +* [ASP.NET Core 中的集成测试](https://learn.microsoft.com/zh-cn/aspnet/core/test/integration-tests) * [总览/服务器端测试](../../Testing.md)