【问题标题】:WireMock fail after half of the body has been sent发送半个身体后,WireMock 失败
【发布时间】:2020-06-23 07:21:56
【问题描述】:

我们想在测试中模拟在已经将一半正文发送到客户端后发送响应失败。

我们能想到的最好办法是:

_server.Given(Request.Create().UsingGet())
  .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK).WithBody(rm => throw new Exception()));

但是,这已经向客户端返回 InternalServerError 而不是 OK。这不是我们想要的。

在发送了几个字节的正文后如何正确返回OK然后失败?

【问题讨论】:

    标签: c# .net wiremock


    【解决方案1】:

    看起来没有办法做到这一点,但我们可以使用https://github.com/WireMock-Net/WireMock.Net/wiki/Faults中描述的“故障”

    我们将使用:

    _server.Given(Request.Create().UsingGet())
      .RespondWith(Response.Create()
        .WithStatusCode(HttpStatusCode.OK)
        .WithBody(someBody)
        .WithFaults(FaultType.MALFORMED_RESPONSE_CHUNK, 0.5));
    

    【讨论】:

      猜你喜欢
      • 2019-05-09
      • 1970-01-01
      • 1970-01-01
      • 2021-11-23
      • 2020-07-28
      • 2020-10-15
      • 2011-08-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多