反骨仔

我的个人云笔记

如何编写干净流畅的 Web API 测试

前言 当我们为 Web API 编写测试用例时,代码基本是这样的: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 public class UnitTest1 { private readonly TestServer _server; private readonly HttpClient _client; public UnitTest1() { // Arrange _server = new TestServer(new

如何判断当前请求的是健康检查 API

前言 为了性能监控的目的,我们使用了 Middleware 记录所有请求的 Log 。实现代码如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 public class RequestLoggingMiddleware { ... public async Task Invoke(HttpContext context) { try { await _next(context); } finally { //Log } }
0%