added tests to project

This commit is contained in:
2026-08-09 18:31:43 +05:00
parent 6da32504f9
commit d5dc228ebe
39 changed files with 6491 additions and 0 deletions
@@ -0,0 +1,41 @@
using System.Net;
using System.Net.Http;
using System.Text;
namespace CursorLang.Tests.Infrastructure;
/// <summary>
/// The network as the test writes it: the answer is decided here rather than
/// by a repository somewhere.
/// </summary>
internal sealed class FakeHttpHandler : HttpMessageHandler
{
private readonly Func<HttpRequestMessage, HttpResponseMessage> _reply;
internal FakeHttpHandler(Func<HttpRequestMessage, HttpResponseMessage> reply) => _reply = reply;
internal List<HttpRequestMessage> Requests { get; } = [];
internal static FakeHttpHandler Json(string json) => new(_ => new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(json, Encoding.UTF8, "application/json"),
});
internal static FakeHttpHandler Status(HttpStatusCode status) =>
new(_ => new HttpResponseMessage(status));
internal static FakeHttpHandler Bytes(byte[] content) => new(_ => new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new ByteArrayContent(content),
});
internal HttpClient CreateClient() => new(this);
protected override Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request,
CancellationToken cancellationToken)
{
Requests.Add(request);
return Task.FromResult(_reply(request));
}
}