mirror of https://github.com/abpframework/abp.git
54 changed files with 328 additions and 308 deletions
@ -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<TProgram> : WebApplicationFactory<TProgram> |
||||
|
where TProgram : class |
||||
|
{ |
||||
|
protected HttpClient Client { get; set; } |
||||
|
|
||||
|
public IServiceProvider ServiceProvider => Services; |
||||
|
|
||||
|
protected AbpAspNetCoreWebApplicationFactoryIntegratedTestBase() |
||||
|
{ |
||||
|
Client = CreateClient(new WebApplicationFactoryClientOptions |
||||
|
{ |
||||
|
AllowAutoRedirect = false |
||||
|
}); |
||||
|
ServiceProvider.GetRequiredService<ITestServerAccessor>().Server = Server; |
||||
|
} |
||||
|
|
||||
|
protected override IHost CreateHost(IHostBuilder builder) |
||||
|
{ |
||||
|
builder.ConfigureServices(ConfigureServices); |
||||
|
return base.CreateHost(builder); |
||||
|
} |
||||
|
|
||||
|
public virtual T? GetService<T>() |
||||
|
{ |
||||
|
return ServiceProvider!.GetService<T>(); |
||||
|
} |
||||
|
|
||||
|
public virtual T GetRequiredService<T>() where T : notnull |
||||
|
{ |
||||
|
return ServiceProvider!.GetRequiredService<T>(); |
||||
|
} |
||||
|
|
||||
|
protected virtual void ConfigureServices(IServiceCollection services) |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
#region GetUrl
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets default URL for given controller type.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TController">The type of the controller.</typeparam>
|
||||
|
protected virtual string GetUrl<TController>() |
||||
|
{ |
||||
|
return "/" + typeof(TController).Name.RemovePostFix("Controller", "AppService", "ApplicationService", "IntService", "IntegrationService", "Service"); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets default URL for given controller type's given action.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TController">The type of the controller.</typeparam>
|
||||
|
protected virtual string GetUrl<TController>(string actionName) |
||||
|
{ |
||||
|
return GetUrl<TController>() + "/" + actionName; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets default URL for given controller type's given action with query string parameters (as anonymous object).
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TController">The type of the controller.</typeparam>
|
||||
|
protected virtual string GetUrl<TController>(string actionName, object queryStringParamsAsAnonymousObject) |
||||
|
{ |
||||
|
var url = GetUrl<TController>(actionName); |
||||
|
|
||||
|
var dictionary = new RouteValueDictionary(queryStringParamsAsAnonymousObject); |
||||
|
if (dictionary.Any()) |
||||
|
{ |
||||
|
url += "?" + dictionary.Select(d => $"{d.Key}={d.Value}").JoinAsString("&"); |
||||
|
} |
||||
|
|
||||
|
return url; |
||||
|
} |
||||
|
|
||||
|
#endregion
|
||||
|
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
using Microsoft.AspNetCore.Builder; |
||||
|
using Volo.Abp.AspNetCore; |
||||
|
using Volo.Abp.AspNetCore.App; |
||||
|
|
||||
|
var builder = WebApplication.CreateBuilder(); |
||||
|
await builder.RunAbpModuleAsync<AppModule>(); |
||||
|
|
||||
|
public partial class Program |
||||
|
{ |
||||
|
} |
||||
@ -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<AppModule>(); |
|
||||
} |
|
||||
|
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) |
|
||||
{ |
|
||||
app.InitializeApplication(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,7 +1,7 @@ |
|||||
|
|
||||
namespace Volo.Abp.AspNetCore.MultiTenancy; |
namespace Volo.Abp.AspNetCore.MultiTenancy; |
||||
|
|
||||
public abstract class AspNetCoreMultiTenancyTestBase : AbpAspNetCoreTestBase<App.Startup> |
public abstract class AspNetCoreMultiTenancyTestBase : AbpAspNetCoreTestBase<Program> |
||||
{ |
{ |
||||
|
|
||||
} |
} |
||||
|
|||||
@ -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<AbpAspNetCoreMvcTestModule>(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 |
||||
|
{ |
||||
|
} |
||||
@ -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<AbpAspNetCoreMvcTestModule>(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(); |
|
||||
} |
|
||||
} |
|
||||
@ -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<AbpAspNetCoreMvcUiTestModule>(); |
||||
|
|
||||
|
public partial class Program |
||||
|
{ |
||||
|
} |
||||
@ -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<AbpAspNetCoreMvcUiTestModule>(); |
|
||||
} |
|
||||
|
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) |
|
||||
{ |
|
||||
app.InitializeApplication(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,25 +1,10 @@ |
|||||
using System; |
using Microsoft.AspNetCore.Builder; |
||||
using System.Collections.Generic; |
using Volo.Abp.AspNetCore; |
||||
using System.Linq; |
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests.Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; |
||||
using System.Threading.Tasks; |
|
||||
using Microsoft.AspNetCore.Hosting; |
|
||||
using Microsoft.Extensions.Configuration; |
|
||||
using Microsoft.Extensions.Hosting; |
|
||||
using Microsoft.Extensions.Logging; |
|
||||
|
|
||||
namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests; |
var builder = WebApplication.CreateBuilder(); |
||||
|
await builder.RunAbpModuleAsync<AbpAspNetCoreMvcUiThemeSharedTestModule>(); |
||||
|
|
||||
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<Startup>(); |
|
||||
}); |
|
||||
} |
} |
||||
|
|||||
@ -1,5 +1,5 @@ |
|||||
namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests.Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; |
namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Tests.Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; |
||||
|
|
||||
public class AbpAspNetCoreMvcUiThemeSharedTestBase : AbpAspNetCoreTestBase<Startup> |
public class AbpAspNetCoreMvcUiThemeSharedTestBase : AbpAspNetCoreTestBase<Program> |
||||
{ |
{ |
||||
} |
} |
||||
|
|||||
@ -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<AbpAspNetCoreMvcUiThemeSharedTestModule>(); |
|
||||
} |
|
||||
|
|
||||
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) |
|
||||
{ |
|
||||
app.InitializeApplication(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,5 +1,5 @@ |
|||||
namespace Volo.Abp.AspNetCore.Mvc.Versioning; |
namespace Volo.Abp.AspNetCore.Mvc.Versioning; |
||||
|
|
||||
public abstract class AspNetCoreMvcVersioningTestBase : AbpAspNetCoreTestBase<Startup> |
public abstract class AspNetCoreMvcVersioningTestBase : AbpAspNetCoreTestBase<Program> |
||||
{ |
{ |
||||
} |
} |
||||
|
|||||
@ -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<AbpAspNetCoreMvcVersioningTestModule>(); |
||||
|
|
||||
|
public partial class Program |
||||
|
{ |
||||
|
} |
||||
@ -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<AbpAspNetCoreMvcVersioningTestModule>(); |
|
||||
} |
|
||||
|
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) |
|
||||
{ |
|
||||
app.InitializeApplication(); |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,10 @@ |
|||||
|
using Microsoft.AspNetCore.Builder; |
||||
|
using Volo.Abp.AspNetCore; |
||||
|
using Volo.Abp.AspNetCore.App; |
||||
|
|
||||
|
var builder = WebApplication.CreateBuilder(); |
||||
|
await builder.RunAbpModuleAsync<AbpSerilogTestModule>(); |
||||
|
|
||||
|
public partial class Program |
||||
|
{ |
||||
|
} |
||||
@ -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<AbpSerilogTestModule>(); |
|
||||
} |
|
||||
|
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) |
|
||||
{ |
|
||||
app.InitializeApplication(); |
|
||||
} |
|
||||
} |
|
||||
@ -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<AbpAspNetCoreTestModule>(); |
||||
|
|
||||
|
public partial class Program |
||||
|
{ |
||||
|
} |
||||
@ -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<AbpAspNetCoreTestModule>(); |
|
||||
} |
|
||||
|
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) |
|
||||
{ |
|
||||
app.InitializeApplication(); |
|
||||
} |
|
||||
} |
|
||||
@ -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<TModule>(this WebApplicationBuilder builder, Action<AbpApplicationCreationOptions> optionsAction = null) |
||||
|
where TModule : IAbpModule |
||||
|
{ |
||||
|
builder.Host.UseAutofac(); |
||||
|
await builder.AddApplicationAsync<TModule>(optionsAction); |
||||
|
var app = builder.Build(); |
||||
|
await app.InitializeApplicationAsync(); |
||||
|
await app.RunAsync(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
using Microsoft.AspNetCore.Builder; |
||||
|
using Volo.Abp.AspNetCore; |
||||
|
using Volo.Abp.Http; |
||||
|
|
||||
|
var builder = WebApplication.CreateBuilder(); |
||||
|
await builder.RunAbpModuleAsync<AbpHttpClientTestModule>(); |
||||
|
|
||||
|
public partial class Program |
||||
|
{ |
||||
|
} |
||||
@ -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<AbpHttpClientTestModule>(); |
|
||||
} |
|
||||
|
|
||||
public void Configure(IApplicationBuilder app) |
|
||||
{ |
|
||||
app.InitializeApplication(); |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue