mercredi 2 décembre 2015

How to mock async method which is inside a void method

I have a void method which is in the view model

public void TestMethod()
{
  AsyncMethod01();
  AsyncMethod02();
}

Inside that void method there is two async methods are called

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);
}
So i need to write a unit test to TestMethod() using moq
[TestMethod]
public async Task TestMethodForViewModel()
{
  //Code
}

So how to write the unit test for the void TestMethod() which include two async methods inside of it. So i need a way to wait till the two async calls are completed in the unit test method.

Aucun commentaire:

Enregistrer un commentaire