首页 > 解决方案 > 如何为 ReadAsStringAsync 编写单元测试

问题描述

我正在尝试为以下代码编写单元测试:

m_Client.SendAsync(request).ContinueWith(responseTask =>
{
    HttpResponseMessage response = responseTask.Result;

    try
    {
        string str = response.Content.ReadAsStringAsync().Result;

        // ...
    }
    catch
    {
        // process exception here
    }
}

是否可以在 ReadAsStringAsync 执行期间模拟任何类型的异常?

标签: c#unit-testinghttpcontent

解决方案


推荐阅读