C# formatting
This commit is contained in:
@@ -1,18 +1,9 @@
|
||||
using System.Net.Http;
|
||||
|
||||
namespace GameList.Tests.Support;
|
||||
|
||||
internal class StubHttpClientFactory : IHttpClientFactory
|
||||
internal class StubHttpClientFactory(StubHttpMessageHandler handler) : IHttpClientFactory
|
||||
{
|
||||
private readonly StubHttpMessageHandler _handler;
|
||||
|
||||
public StubHttpClientFactory(StubHttpMessageHandler handler)
|
||||
{
|
||||
_handler = handler;
|
||||
}
|
||||
|
||||
public HttpClient CreateClient(string name)
|
||||
{
|
||||
return new HttpClient(_handler, disposeHandler: false);
|
||||
return new HttpClient(handler, disposeHandler: false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,24 +5,16 @@ namespace GameList.Tests.Support;
|
||||
|
||||
internal class StubHttpMessageHandler : HttpMessageHandler
|
||||
{
|
||||
private Func<HttpRequestMessage, HttpResponseMessage> _responder;
|
||||
|
||||
public StubHttpMessageHandler()
|
||||
{
|
||||
_responder = DefaultResponder;
|
||||
}
|
||||
private Func<HttpRequestMessage, HttpResponseMessage> _responder = DefaultResponder;
|
||||
|
||||
public void SetResponder(Func<HttpRequestMessage, HttpResponseMessage> responder)
|
||||
{
|
||||
_responder = responder ?? DefaultResponder;
|
||||
_responder = responder;
|
||||
}
|
||||
|
||||
private static HttpResponseMessage DefaultResponder(HttpRequestMessage _)
|
||||
{
|
||||
var response = new HttpResponseMessage(HttpStatusCode.OK)
|
||||
{
|
||||
Content = new ByteArrayContent(Array.Empty<byte>())
|
||||
};
|
||||
var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new ByteArrayContent([]) };
|
||||
response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png");
|
||||
response.Content.Headers.ContentLength = 0;
|
||||
return response;
|
||||
|
||||
@@ -49,5 +49,4 @@ internal static class TestClientExtensions
|
||||
var me = await client.GetFromJsonAsync<JsonElement>("/api/me");
|
||||
return Guid.Parse(me.GetProperty("id").GetString()!);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GameList.Data;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
@@ -18,13 +16,7 @@ internal class TestWebApplicationFactory : WebApplicationFactory<Program>
|
||||
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
||||
{
|
||||
builder.UseEnvironment("Development");
|
||||
builder.ConfigureAppConfiguration((context, config) =>
|
||||
{
|
||||
config.AddInMemoryCollection(new Dictionary<string, string?>
|
||||
{
|
||||
["ADMIN_PASSWORD"] = "admin-key"
|
||||
});
|
||||
});
|
||||
builder.ConfigureAppConfiguration((_, config) => { config.AddInMemoryCollection(new Dictionary<string, string?> { ["ADMIN_PASSWORD"] = "admin-key" }); });
|
||||
|
||||
builder.ConfigureServices(services =>
|
||||
{
|
||||
@@ -37,10 +29,7 @@ internal class TestWebApplicationFactory : WebApplicationFactory<Program>
|
||||
_connection = new SqliteConnection("Data Source=:memory:;Cache=Shared");
|
||||
_connection.Open();
|
||||
|
||||
services.AddDbContext<AppDbContext>(options =>
|
||||
{
|
||||
options.UseSqlite(_connection);
|
||||
});
|
||||
services.AddDbContext<AppDbContext>(options => { options.UseSqlite(_connection); });
|
||||
|
||||
services.AddSingleton<StubHttpMessageHandler>();
|
||||
services.AddSingleton<IHttpClientFactory, StubHttpClientFactory>();
|
||||
|
||||
Reference in New Issue
Block a user