All checks were successful
Build and Deploy / deploy (push) Successful in 1m13s
Co-authored-by: Cursor <cursoragent@cursor.com>
78 lines
3.1 KiB
C#
78 lines
3.1 KiB
C#
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.TestHost;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using SimpleAdmin.Api;
|
|
|
|
namespace Oms.E2E.Tests.Support;
|
|
|
|
internal sealed class OrderE2eTestHost : IAsyncDisposable
|
|
{
|
|
private readonly WebApplication _app;
|
|
|
|
private OrderE2eTestHost(WebApplication app)
|
|
{
|
|
_app = app;
|
|
Client = app.GetTestClient();
|
|
}
|
|
|
|
public HttpClient Client { get; }
|
|
|
|
public static async Task<OrderE2eTestHost> CreateAsync(
|
|
string connectionString,
|
|
Action<IServiceCollection>? configureServices = null)
|
|
{
|
|
var builder = SimpleAdminApiBootstrap.CreateBuilder([], webAppBuilder =>
|
|
{
|
|
webAppBuilder.WebHost.UseTestServer();
|
|
webAppBuilder.Configuration.AddInMemoryCollection(new Dictionary<string, string?>
|
|
{
|
|
["UseLocalConfigs"] = "true",
|
|
["ConnectionStrings:Default"] = connectionString,
|
|
["App:SendStartupNotification"] = "false",
|
|
["App:CorsOrigins:0"] = "http://localhost",
|
|
["App:Urls:0"] = "http://127.0.0.1:5005",
|
|
["Jwt:SecretKey"] = "oms-e2e-test-secret-key-32chars-min",
|
|
["Jwt:Issuer"] = "Oms.E2E.Tests",
|
|
["Jwt:Audience"] = "Oms.E2E.Tests",
|
|
["Jwt:ExpiryInMinutes"] = "120",
|
|
["Jwt:RefreshExpiryInDays"] = "7",
|
|
["Jwt:ClockSkewMinutes"] = "5",
|
|
["JwtSettings:SecretKey"] = "oms-e2e-test-secret-key-32chars-min",
|
|
["JwtSettings:Issuer"] = "Oms.E2E.Tests",
|
|
["JwtSettings:Audience"] = "Oms.E2E.Tests",
|
|
["JwtSettings:ExpiryInMinutes"] = "120",
|
|
["JwtSettings:RefreshExpiryInDays"] = "7",
|
|
["JwtSettings:ClockSkewMinutes"] = "5",
|
|
["FeiShu:Webhook"] = "https://example.com/webhook",
|
|
["FeiShu:EnableFeiShuExceptionSubscribe"] = "false",
|
|
["FeiShuNotice:Webhook"] = "https://example.com/webhook",
|
|
["FeiShuNotice:EnableFeiShuExceptionSubscribe"] = "false",
|
|
["Redis:Host"] = "127.0.0.1:6379",
|
|
["Redis:Database"] = "0",
|
|
["OrderBatch:RabbitMq:Enabled"] = "false",
|
|
["Oms:TrackChangeSubscribe:Enabled"] = "false",
|
|
["Oms:TrackService:Enabled"] = "false",
|
|
["Oms:TrackService:BaseUrl"] = "http://127.0.0.1:9090",
|
|
["Oms:TrackService:AppKey"] = "E2E_KEY",
|
|
["Oms:TrackService:AppSecret"] = "E2E_SECRET",
|
|
["Oms:TrackService:TimeoutSeconds"] = "5"
|
|
});
|
|
}, environmentName: "Testing");
|
|
|
|
configureServices?.Invoke(builder.Services);
|
|
|
|
var app = SimpleAdminApiBootstrap.BuildApplication(builder);
|
|
await app.StartAsync();
|
|
return new OrderE2eTestHost(app);
|
|
}
|
|
|
|
public async ValueTask DisposeAsync()
|
|
{
|
|
Client.Dispose();
|
|
await _app.StopAsync();
|
|
await _app.DisposeAsync();
|
|
}
|
|
}
|