I have an SL4 application that uses the MVVM Light Toolkit. In the view model, I call the data service, which retrieves data from the OData service. Inside the virtual machine, I use the utility class DispatcherHelper (part of MVVM Light) to update the property on the virtual machine from the data in the callback that I pass to the data service. For example, my model method is as follows:
public string CurrentUserLogin { get { if (string.IsNullOrEmpty(_currentUserLogin)) RetrieveCurrentUserLogin(); return string.IsNullOrEmpty(_currentUserLogin) ? _currentUserLogin : _currentUserLogin.Replace(@"\\", @"\"); } set { if (_currentUserLogin != value) { _currentUserLogin = value; RaisePropertyChanged(CurrentUserLoginPropertyName); } } } private void RetrieveCurrentUserLogin() { DataService.GetCurrentUserLogin(result => { DispatcherHelper.UIDispatcher.BeginInvoke(() => { CurrentUserLogin = result; }); }); }
And here is what my after-sales service looks like:
public void GetCurrentUserLogin(Action<string> callback) {
Everything works fine when I run my SL application. However, the problem is that I am trying to write unit tests against it using the SL module testing module. I can check my data service without any problems, but it seems that DispatcherHelper throws the key in all my tests, since DispatcherHelper.UIDispatcher is always null at startup. I assume this has something to do with initlization (which is in my SL Application_Startup () application). I tried to initialize it in my test application, but that does not help. I also tried using DispatcherHelper.CheckBeginInvokeOnUI (), but this does not affect the problem.
Ideas?
source share