Rund 2.600 Kommentarblöcke in 310 C#-Dateien übersetzt, Begründungen vollständig erhalten: blockweise gleiche Anzahl wie vorher, kein Block unter 60 % seiner Länge, der Code außerhalb der Kommentare per Tokenizer byte-identisch geprüft. Zitate deutscher Oberflächentexte und Testdaten bleiben deutsch. WebUI: Kommentare in JS/CSS/HTML übersetzt, JSDoc-@param an die in 4b umbenannten Parameter angeglichen. Dabei behoben: - 4b hatte "tag" (HTML-Tag) als deutsches "Tag" gelesen und zu "dayValue" gemacht (makeElement, svg, Tagesübersicht) - zurück auf tag/day. - Aufgaben "InProgress" bekamen die Plakettenart "laufend", für die es nie eine CSS-Klasse gab - jetzt "success" wie laufende Instanzen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
50 lines
1.6 KiB
C#
50 lines
1.6 KiB
C#
using System.Net;
|
|
|
|
namespace ClawdDotNet.Core.Tests.Infrastructure;
|
|
|
|
/// <summary>
|
|
/// Delivers preprogrammed HTTP responses without any network access taking place.
|
|
/// </summary>
|
|
internal sealed class FakeHttpMessageHandler : HttpMessageHandler
|
|
{
|
|
private readonly Queue<Func<HttpResponseMessage>> _responses = new();
|
|
|
|
public int RequestCount { get; private set; }
|
|
|
|
public FakeHttpMessageHandler Responds(HttpStatusCode status, string body = "{}", TimeSpan? retryAfter = null)
|
|
{
|
|
_responses.Enqueue(() =>
|
|
{
|
|
var response = new HttpResponseMessage(status)
|
|
{
|
|
Content = new StringContent(body, System.Text.Encoding.UTF8, "application/json")
|
|
};
|
|
if (retryAfter is { } delta)
|
|
response.Headers.RetryAfter = new System.Net.Http.Headers.RetryConditionHeaderValue(delta);
|
|
return response;
|
|
});
|
|
return this;
|
|
}
|
|
|
|
public FakeHttpMessageHandler RespondsWithSuccess(string body = """{"id":"x","choices":[]}""")
|
|
=> Responds(HttpStatusCode.OK, body);
|
|
|
|
public FakeHttpMessageHandler Throws(Exception ex)
|
|
{
|
|
_responses.Enqueue(() => throw ex);
|
|
return this;
|
|
}
|
|
|
|
protected override Task<HttpResponseMessage> SendAsync(
|
|
HttpRequestMessage request, CancellationToken cancellationToken)
|
|
{
|
|
RequestCount++;
|
|
|
|
if (_responses.Count == 0)
|
|
throw new InvalidOperationException(
|
|
$"FakeHttpMessageHandler: unerwartete Anfrage Nr. {RequestCount}.");
|
|
|
|
return Task.FromResult(_responses.Dequeue()());
|
|
}
|
|
}
|