使用 Wiremock .NET C# 的动态响应

问题描述 投票:0回答:0

我最近开始使用 wiremock .net 创建一个将在 kubernetes 中运行的模拟 API。我的代码中有这一行,它在 Wiremock 服务器启动时运行:

server.Given(Request.Create().WithPath(_urlPath).UsingPost().WithBody(new XPathMatcher($"{_surname}='TestResponse'"))).RespondWith(Response.Create().WithStatusCode(200) ).WithHeader("content-type", "text/xml;charset=UTF-8").WithBody(GetTestData()));

在我的测试数据响应中,我有一个 CreatedDateTime。我想知道每次向 wiremock 测试服务器发送请求时是否有有效的方法来更改它?

我目前的代码在一个 while 循环中,它不断地读取响应文件并调用一个函数来更新响应中的日期。它有效,但我想知道有没有更好的方法。

while (server.IsStarted)
{
    MockSetup.MockResponses(server);
    MockSetup.UpdateDates();
    Console.WriteLine("Mock Running");
    Thread.Sleep(30000);
    continue;
}
c# wiremock
© www.soinside.com 2019 - 2024. All rights reserved.