I want to test methods on the viewmodel but the .Model property always raises the System.InvalidOperationException: "The calling thread cannot access this object because a different thread owns it." in the asynchronously-QueryCompleted method of ViewModelBase<T>.
#1 public class ProjectGetter : ViewModel<ProjectTracker.Library.ProjectGetter>
#3 public ProjectGetter()
#5 BeginRefresh(callback => ProjectTracker.Library.ProjectGetter.CreateNewProject(callback));
From my UnitTest
#1 ProjectGetter vm = new ProjectGetter();
#4 Assert.AreEqual(vm.Child.GetType(), typeof(ProjectGetter.ProjectEdit));
When I rewrite the ProjectTracker Line#5 and replace BeginRefresh with DoRefresh which is synchronous, the .Model property is properly populated.
I tried waiting on the PropertyChanged event of the ViewModel, but, alas, it is never raised. There does not seem to be a way to properly wait on some event/callback method when the asynchronous method completes. I am at a loss and any help anyone can provide would be much appreciated.
(I have properly used the UnitDriven test framework to test synch/asynch BO's with much success, however, these asynch-viewmodels have me stuck.)
Copyright (c) Marimer LLC