C# formatting

This commit is contained in:
2026-02-05 20:39:12 +01:00
parent 78cdbfe51e
commit c0756ff2c6
34 changed files with 830 additions and 582 deletions

View File

@@ -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);
}
}

View File

@@ -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;

View File

@@ -49,5 +49,4 @@ internal static class TestClientExtensions
var me = await client.GetFromJsonAsync<JsonElement>("/api/me");
return Guid.Parse(me.GetProperty("id").GetString()!);
}
}

View File

@@ -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>();