I am Unit Testing ViewModel in WPF application and there is a Delegate Command that calls a Method which further calls async method inside it . I have to wait for every Task to be finished before calling Assert statement. the Method called by the delegate command is like :
private void Methodcalled()
{
this.uiService.SetBusyState();
UIExecuteHelper executeHelper = new UIExecuteHelper(ViewName.Window);
executeHelper.ExecuteAsync(() =>
{
// some stuff
method1();
}
}
Now I am waiting for the method in the following way in my unit test:
try
{
var task = Task.Factory.StartNew(() =>
{
classobj.DelegateCommand.Execute();
});
var afterTask = task.ContinueWith((myobject)=>
{
classobj.Load();
Assert.AreEqual(true, someflag);
}, TaskContinuationOptions.OnlyOnRanToCompletion);
}
But it is still not waiting for all the inner tasks spawned to be finished. Please suggest