I ve got code in a ViewModel that calls a service through a task. When the task finishes, it ll populate an ObservableCollection. The problem is that it s waiting on the task to finish by using the ContinueWith method and providing TaskScheduler.FromCurrentSynchronizationContext as task scheduler, so that the OC gets updated on the UI thread.
So far so good, but when it comes to unit testing, it throws an exception saying that "the current SynchronizationContext may not be used as a TaskScheduler." If I use a mock SynchronizationContext on the unit test, then the ObservableCollection throws an error because it s being updated based from the dispatcher thread.
Is there any way to work around this?
感谢。