正在获得这样的请求响应: var response = command.PostCommand(testCommand);
我想验证响应是否为json格式,因此应执行以下操作:
Assert.AreEqual(“ application / json”,response.ContentType);
这是正确的方法还是我需要从内容类型标头响应中特别验证它?
答案 0 :(得分:0)
您可以使用IRestRequest.OnBeforeDeserialization
回调在反序列化响应内容类型之前对其进行检查:
var request = new RestRequest(url)
.AddQueryParameter(x, y); // whatever you need to configure
request.OnBeforeDeserialization =
response => CheckContentType(response.ContentType);
await client.PostAsync<MyResponse>(request);