-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10928 from abpframework/new-hosting-model
Use new hosting model for the app template.
- Loading branch information
Showing
90 changed files
with
1,519 additions
and
635 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
....AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase/AbpAspNetCoreAsyncIntegratedTestBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting.Server; | ||
using Microsoft.AspNetCore.Routing; | ||
using Microsoft.AspNetCore.TestHost; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Volo.Abp.Modularity; | ||
|
||
namespace Volo.Abp.AspNetCore.TestBase; | ||
|
||
public class AbpAspNetCoreAsyncIntegratedTestBase<TModule> | ||
where TModule : IAbpModule | ||
{ | ||
protected WebApplication WebApplication { get; set; } | ||
|
||
protected TestServer Server { get; set; } | ||
|
||
protected HttpClient Client { get; set; } | ||
|
||
protected IServiceProvider ServiceProvider { get; set; } | ||
|
||
protected virtual T GetService<T>() | ||
{ | ||
return ServiceProvider.GetService<T>(); | ||
} | ||
|
||
protected virtual T GetRequiredService<T>() | ||
{ | ||
return ServiceProvider.GetRequiredService<T>(); | ||
} | ||
|
||
public virtual async Task InitializeAsync() | ||
{ | ||
var builder = WebApplication.CreateBuilder(); | ||
builder.Host.ConfigureServices(services => | ||
{ | ||
services.AddSingleton<IHostLifetime, TestNoopHostLifetime>(); | ||
services.AddSingleton<IServer, TestServer>(); | ||
}) | ||
.UseAutofac(); | ||
|
||
await builder.Services.AddApplicationAsync<TModule>(options => | ||
{ | ||
options.Services.ReplaceConfiguration(builder.Configuration); | ||
}); | ||
|
||
await ConfigureServicesAsync(builder.Services); | ||
WebApplication = builder.Build(); | ||
await WebApplication.InitializeApplicationAsync(); | ||
await WebApplication.StartAsync(); | ||
|
||
Server = WebApplication.Services.GetRequiredService<IHost>().GetTestServer(); | ||
Client = Server.CreateClient(); | ||
|
||
ServiceProvider = Server.Services; | ||
ServiceProvider.GetRequiredService<ITestServerAccessor>().Server = Server; | ||
} | ||
|
||
public virtual async Task DisposeAsync() | ||
{ | ||
await WebApplication.DisposeAsync(); | ||
} | ||
|
||
protected virtual Task ConfigureServicesAsync(IServiceCollection services) | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
|
||
#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", "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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...ork/src/Volo.Abp.AspNetCore.TestBase/Volo/Abp/AspNetCore/TestBase/TestNoopHostLifetime.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace Volo.Abp.AspNetCore.TestBase; | ||
|
||
public class TestNoopHostLifetime : IHostLifetime | ||
{ | ||
public Task StopAsync(CancellationToken cancellationToken) | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
|
||
public Task WaitForStartAsync(CancellationToken cancellationToken) | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.