c# - 如何为 ReadAsStringAsync 编写单元测试
问题描述
我正在尝试为以下代码编写单元测试:
m_Client.SendAsync(request).ContinueWith(responseTask =>
{
HttpResponseMessage response = responseTask.Result;
try
{
string str = response.Content.ReadAsStringAsync().Result;
// ...
}
catch
{
// process exception here
}
}
是否可以在 ReadAsStringAsync 执行期间模拟任何类型的异常?
解决方案
推荐阅读
- docker - 在 Fargate 上运行 docker(网络作为本地主机)的问题
- javascript - 如何让 JS “看到”已发布到当前页面的 html
- webpack - 配置 webpack、coffeescript、mocha 和 mochapack 的问题
- entity-framework - 错误无法更新数据库以匹配当前模型,因为有待处理的更改
- javascript - 在 JS 中从 chrome 扩展中保存和读取数据
- xamarin.forms - Xamarin Forms CollectionView 无法正常工作(支持库?)
- r - R 将 SQLiteResult 记录集导出到 Excel 或 csv
- interface - 在启动时使用 systemd 启用 vcan0 接口
- android - 如何通过定时通知启动我的服务
- syntax - 尝试使用 getUserMedia(next.js 应用程序)时出现 SyntaxError Unexpected Token