mirror of https://github.com/abpframework/abp
parent
c17c4c261d
commit
0329dd29c1
@ -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
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
|
||||
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,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<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.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.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,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();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue