Files
Yi.Admin/Yi.Abp.Net8/test/Yi.Abp.Test/YiAbpTestWebBase.cs

38 lines
1.4 KiB
C#
Raw Normal View History

2025-02-23 01:41:31 +08:00
using Microsoft.AspNetCore.Builder;
2024-01-19 18:08:11 +08:00
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
2025-02-23 01:41:31 +08:00
namespace Yi.Abp.Test;
public class YiAbpTestWebBase:YiAbpTestBase
2024-01-19 18:08:11 +08:00
{
2025-02-23 01:41:31 +08:00
public HttpContext HttpContext { get; private set; }
public YiAbpTestWebBase():base()
2024-01-19 18:08:11 +08:00
{
2025-02-23 01:41:31 +08:00
HttpContext httpContext = DefaultHttpContextAccessor.CurrentHttpContext;
this.ConfigureHttpContext(httpContext);
HttpContext = httpContext;
IApplicationBuilder app = new ApplicationBuilder(this.ServiceProvider);
RequestDelegate httpDelegate = app.Build();
httpDelegate.Invoke(httpContext);
}
2024-01-19 18:08:11 +08:00
2025-02-23 01:41:31 +08:00
public override void ConfigureServices(HostBuilderContext host, IServiceCollection service)
{
service.Replace(new ServiceDescriptor(typeof(IHttpContextAccessor), typeof(DefaultHttpContextAccessor), ServiceLifetime.Singleton));
base.ConfigureServices(host, service);
}
2024-01-19 18:08:11 +08:00
2025-02-23 01:41:31 +08:00
protected virtual void ConfigureHttpContext(HttpContext httpContext)
{
httpContext.Request.Path= "/test";
2024-01-19 18:08:11 +08:00
}
}
2025-02-23 01:41:31 +08:00
2024-01-19 18:08:11 +08:00
internal class DefaultHttpContextAccessor : IHttpContextAccessor
{
internal static HttpContext? CurrentHttpContext { get; set; } = new DefaultHttpContext();
public HttpContext? HttpContext { get => CurrentHttpContext; set => throw new NotImplementedException(); }
2025-02-23 01:41:31 +08:00
}