C# Restsharp - 如何验证内容结果是否为意外结果
C# Restsharp - How to verify the content result is unexpected result
获取内容结果的代码
IRestResponse response = client.Execute(request);
var content = (string)JsonConvert.DeserializeObject(response.Content);
response.content
应该 return 将这 4 条消息中的一条设为以太。
- 好的
- INVALID_MESSAGE_ID
- MESSAGE_NOT_FOUND
- INTERNAL_ERROR
如果 API return 正在发送其他内容,我该如何验证?
查看内容:
if(content != "OK" && content != "INVALID_MESSAGE_ID" && content != "MESSAGE_NOT_FOUND" && content != "INTERNAL_ERROR") {
//Do some handling, like logging
}
或者:
switch(content) {
case "OK":
// Do something, when content is OK
break;
case "INVALID_MESSAGE_ID":
// Do something, when content is INVALID_MESSAGE_ID
break;
case "MESSAGE_NOT_FOUND":
// Do something, when content is MESSAGE_NOT_FOUND
break;
case "INTERNAL_ERROR":
// Do something, when content is INTERNAL_ERROR
break;
case default:
// Do something, if no case is matched
break;
}
获取内容结果的代码
IRestResponse response = client.Execute(request);
var content = (string)JsonConvert.DeserializeObject(response.Content);
response.content
应该 return 将这 4 条消息中的一条设为以太。
- 好的
- INVALID_MESSAGE_ID
- MESSAGE_NOT_FOUND
- INTERNAL_ERROR
如果 API return 正在发送其他内容,我该如何验证?
查看内容:
if(content != "OK" && content != "INVALID_MESSAGE_ID" && content != "MESSAGE_NOT_FOUND" && content != "INTERNAL_ERROR") {
//Do some handling, like logging
}
或者:
switch(content) {
case "OK":
// Do something, when content is OK
break;
case "INVALID_MESSAGE_ID":
// Do something, when content is INVALID_MESSAGE_ID
break;
case "MESSAGE_NOT_FOUND":
// Do something, when content is MESSAGE_NOT_FOUND
break;
case "INTERNAL_ERROR":
// Do something, when content is INTERNAL_ERROR
break;
case default:
// Do something, if no case is matched
break;
}