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 a6f6a55f39..5bf1cc54aa 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 0000000000..11d27221df --- /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 0000000000..e6960b28a4 --- /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 46981d27be..0000000000 --- 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 15991117f4..7ff1acc7a5 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 a630df4986..e80b47b2a5 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 class AspNetCoreMultiTenancy_WithDomainResolver_Tests : AspNetCoreMultiTe _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 ccbd941bae..56da287ef8 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 class AspNetCoreMultiTenancy_Without_DomainResolver_Tests : AspNetCoreMul _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 6051ae6520..1b2901d304 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.Collections.Generic; 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 6acbb77242..2792448d9c 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 @@ using Microsoft.Extensions.Hosting; namespace Volo.Abp.AspNetCore.Mvc; -public abstract class AspNetCoreMvcTestBase : AbpAspNetCoreTestBase +public abstract class AspNetCoreMvcTestBase : AbpAspNetCoreTestBase { protected override IHostBuilder CreateHostBuilder() { @@ -17,8 +17,7 @@ public abstract class AspNetCoreMvcTestBase : AbpAspNetCoreTestBase ) ); - 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 129035f406..74677b27c4 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 class AuditIntegrationServiceTestController_Tests : AspNetCoreMvcTestBase _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 class AuditIntegrationServiceTestController_Tests : AspNetCoreMvcTestBase 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 78d537e252..2a4ee0a8f2 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 class AuditTestController_Tests : AspNetCoreMvcTestBase _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 aae671d6d4..3758669457 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 class AuditTestPage_Tests : AspNetCoreMvcTestBase _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 46aa0369e3..7060a91b99 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 e8e49b4946..95e6b5ca47 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 class AbpAuthorizationExceptionTestController_Tests : AspNetCoreMvcTestBa 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 689f3a00dc..0b10ff91da 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 class AbpAuthorizationExceptionTestPage_Tests : AspNetCoreMvcTestBase _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 2f10f4b027..1b79441de8 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 class ExceptionTestController_Tests : AspNetCoreMvcTestBase 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 3290b37c95..48ccf6499f 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 class ExceptionTestPage_Tests : AspNetCoreMvcTestBase _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 e7015313cb..23c16677e2 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 1613e4bb49..d0888a0fdf 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 class JsonSerializer_Tests : AspNetCoreMvcTestBase _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 b575b4ce78..d23a5c1a9f 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 class LocalizationTestController_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/ModelBinding/ModelBindingController_Tests.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ModelBinding/ModelBindingController_Tests.cs index 53bfff8b68..973e2f7192 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 abstract class ModelBindingController_Tests : AspNetCoreMvcTestBase 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 0000000000..5bba766f40 --- /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 4c419ef744..dab4a03466 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 @@ public class SecurityHeadersTestController_Tests : AspNetCoreMvcTestBase 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 df5a8b7b9c..0000000000 --- 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 068accad6a..7c0658638d 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 f5e3bf2123..652c936276 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 588c130a22..ab0fd586b3 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 class ValidationTestController_Tests : AspNetCoreMvcTestBase 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 99ca4da729..d6f6402eca 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 0000000000..9775d17edc --- /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 0e1954b630..0000000000 --- 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 3f2eaedeb0..4bd87d1533 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 b450dd97d2..1f7f5f2a82 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 bfc1303970..a665d2c49d 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 4bd8c2d036..cab4ca631c 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 d17ee6203b..0000000000 --- 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 d9e5be8b2d..2c5394a931 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 @@ public class Toolbar_Tests : AbpAspNetCoreMvcUiThemeSharedTestBase 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 0df183aca1..5792517562 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 0000000000..88a8601822 --- /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 4ccb18feac..0000000000 --- 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 992800cda5..4088412b88 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 0000000000..1d6fc96801 --- /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 8464f6e77b..0000000000 --- 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 acfb7e54d0..acf053ced7 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 @@ using Volo.Abp.AspNetCore.App; 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 @@ public class AbpSerilogTestBase : AbpAspNetCoreTestBase .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 b8f197d3c1..4782a5e768 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 class Serilog_Enrichers_Tests : AbpSerilogTestBase _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 a79c4998e8..29a157a3f5 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 @@ using Volo.Abp.AspNetCore.TestBase; 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 16799162bb..dcd47ddc88 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 @@ using Xunit; 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 0000000000..112772fc82 --- /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 133b77fcc8..0000000000 --- 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 0000000000..ff584d18c5 --- /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 9ae4370b38..dfa5c335b2 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 @@ using Volo.Abp.AspNetCore; 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 6540b717d3..003cd065e2 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 8469ba121a..f679ccd9c9 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 class RegularTestControllerClientProxy_AbpRemoteCallException_Tests : Abp _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 0000000000..0cf3a51d99 --- /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 063b9999c1..0000000000 --- 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(); - } -}