【发布时间】:2015-12-02 10:25:19
【问题描述】:
我在视图模型中有一个 void 方法
public void TestMethod()
{
AsyncMethod01();
AsyncMethod02();
}
在那个 void 方法里面有两个异步方法被调用
async void AsyncMethod01()
{
ServiceResponse<ObservableCollection<User>> response = await
Task.Factory.StartNew<ServiceResponse<ObservableCollection<User>>>(UserDetails);
}
async void AsyncMethod02()
{
ServiceResponse<ObservableCollection<Customer>> response = await
Task.Factory.StartNew<ServiceResponse<ObservableCollection<Customer>>>(CustDetails);
}
所以我需要使用 moq 为 TestMethod() 编写一个单元测试
[TestMethod]
public async Task TestMethodForViewModel()
{
//Code
}
那么如何为 void TestMethod() 编写单元测试,其中包含两个异步方法。所以我需要一种方法来等到单元测试方法中的两个异步调用完成。
【问题讨论】:
标签: c# unit-testing async-await moq