Add `AbpTestServer`.

pull/13357/head
maliming 3 years ago
parent c59d75be61
commit d6152d01c2
No known key found for this signature in database
GPG Key ID: 096224957E51C89E

@ -40,7 +40,7 @@ public abstract class AbpAspNetCoreIntegratedTestBase<TStartup> : AbpTestBaseWit
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<TStartup>();
webBuilder.UseTestServer();
webBuilder.UseAbpTestServer();
})
.UseAutofac()
.ConfigureServices(ConfigureServices);

@ -0,0 +1,18 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
namespace Volo.Abp.AspNetCore.TestBase;
public class AbpNoopHostLifetime : IHostLifetime
{
public Task StopAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
public Task WaitForStartAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
}

@ -0,0 +1,19 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace Volo.Abp.AspNetCore.TestBase;
public static class AbpWebHostBuilderExtensions
{
public static IWebHostBuilder UseAbpTestServer(this IWebHostBuilder builder)
{
return builder.ConfigureServices(services =>
{
services.AddScoped<IHostLifetime, AbpNoopHostLifetime>();
services.AddScoped<IServer, TestServer>();
});
}
}

@ -6,8 +6,10 @@ using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
using Shouldly;
using Volo.Abp.Http;
using Volo.Abp.Json.SystemTextJson;
using Volo.Abp.Timing;
using Xunit;
@ -106,7 +108,7 @@ public abstract class ModelBindingController_Tests : AspNetCoreMvcTestBase
}
}
public class ModelBindingController_Utc_Tests : ModelBindingController_Tests
public abstract class ModelBindingController_Utc_Tests : ModelBindingController_Tests
{
protected override void ConfigureServices(HostBuilderContext context, IServiceCollection services)
{
@ -117,7 +119,7 @@ public class ModelBindingController_Utc_Tests : ModelBindingController_Tests
}
}
public class ModelBindingController_Local_Tests : ModelBindingController_Tests
public abstract class ModelBindingController_Local_Tests : ModelBindingController_Tests
{
protected override void ConfigureServices(HostBuilderContext context, IServiceCollection services)
{
@ -127,3 +129,46 @@ public class ModelBindingController_Local_Tests : ModelBindingController_Tests
base.ConfigureServices(context, services);
}
}
public class SystemTextJson_ModelBindingController_Utc_Tests : ModelBindingController_Utc_Tests
{
}
public class SystemTextJson_ModelBindingController_Local_Tests : ModelBindingController_Local_Tests
{
}
public class Newtonsoft_ModelBindingController_Utc_Tests : ModelBindingController_Utc_Tests
{
protected override void ConfigureServices(HostBuilderContext context, IServiceCollection services)
{
services.Configure<AbpSystemTextJsonSerializerOptions>(options =>
{
options.UnsupportedTypes.Add<GetDateTimeKindModel>();
options.UnsupportedTypes.Add<GetDateTimeKindModel.GetDateTimeKindInnerModel>();
});
services.Configure<IOptions<Newtonsoft_ModelBindingController_Utc_Tests>>(x =>
{
});
base.ConfigureServices(context, services);
}
}
public class Newtonsoft_ModelBindingController_Local_Tests : ModelBindingController_Local_Tests
{
protected override void ConfigureServices(HostBuilderContext context, IServiceCollection services)
{
services.Configure<AbpSystemTextJsonSerializerOptions>(options =>
{
options.UnsupportedTypes.Add<GetDateTimeKindModel>();
options.UnsupportedTypes.Add<GetDateTimeKindModel.GetDateTimeKindInnerModel>();
});
base.ConfigureServices(context, services);
}
}

Loading…
Cancel
Save