namespace Yh.SchClass.OpenApi.Tests; /// 测试宿主:提供共享配置、门面实例与端点契约断言辅助。 internal static class SchClassTestHost { /// 测试用配置(不设 BasePath,端点直接挂在根路径下)。 public static SchClassOpenApiOptions Options() => new() { BaseHost = "http://base.yunhaixingtong.com" }; /// 用伪造 handler 装配门面。 public static SchClassOpenApi Api(FakeHandler handler) => new(new HttpClient(handler), Options()); /// 回放一段无害响应(JSON 字面量 null),使任意端点都能安全走完解析流程。 public static FakeHandler Ok() => FakeHandler.Json(HttpStatusCode.OK, "null"); /// 断言最近一次请求的 method / 路径 / query。 public static void Verify(FakeHandler handler, HttpMethod method, string path, string query = "") { var request = handler.LastRequest; Assert.NotNull(request); Assert.Equal(method, request!.Method); Assert.Equal(path, request.RequestUri!.AbsolutePath); Assert.Equal(query, Uri.UnescapeDataString(request.RequestUri.Query)); } /// 断言最近一次请求的方法、路径与请求体(用于 POST @RequestBody String 端点)。 public static void VerifyBody(FakeHandler handler, string path, string? body, string contentType = "text/plain") { var request = handler.LastRequest; Assert.NotNull(request); Assert.Equal(HttpMethod.Post, request!.Method); Assert.Equal(path, request.RequestUri!.AbsolutePath); Assert.Equal(body, handler.LastRequestBody); Assert.Equal(contentType, handler.LastContentType); } }