ExampleSignalR/TestProject/WebAppFactoryFixture.cs

50 lines
1.3 KiB
C#

using System.Net.Http.Headers;
using System.Text.Json;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using static Microsoft.AspNetCore.Http.StatusCodes;
namespace ExampleSignalR.Test;
public class WebAppFactoryFixture : WebApplicationFactory<ExampleSignalR.Program>
{
public string url = "https://localhost:7083";
//private static readonly JsonSerializerOptions JsonSerializerOptions = new()
//{
//};
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
builder.ConfigureServices(ConfigureServices);
//builder.UseEnvironment("Development");
builder.UseUrls(url);
base.ConfigureWebHost(builder);
}
private void ConfigureServices(IServiceCollection services)
{
//var t = services.Select(e => e.ServiceType == typeof(IMessageService));
services.RemoveAll(typeof(IMessageService));
services.AddTransient<IMessageService, MessageServiceT>();
services.AddHttpsRedirection(options =>
{
options.RedirectStatusCode = Status307TemporaryRedirect;
options.HttpsPort = 7083;
});
}
}
public class MessageServiceT() : IMessageService
{
public string GetMessage()
{
return "321";
}
}