wpf - Why can't I update my ObservableCollection with Filtered CollectionView attached during unit testing? -


i've got observablecollection in viewmodel need modify in code on background thread (using task object). i've got icollectionview attached collection. when modify collection @ run-time, code runs fine. in unit testing error, "this type of collectionview not support changes sourcecollection thread different dispatcher thread."

i create collection thusly (on ui thread @ run-time):

    cashdeliverydepots = new observablecollection<cashdeliverydepot>();     filteredcashdeliverydepots = collectionviewsource.getdefaultview(cashdeliverydepots); 

and modify using code (which running on non-ui thread @ run-time):

    currentdispatcher.invoke(() =>     {         foreach (var depot in depots)         {             cashdeliverydepots.add(depot);         }     }); 

the currentdispatcher class executes code according whether or not there application dispatcher.

internal static class currentdispatcher {     internal static void invoke(action action)     {         if (application.current != null)             application.current.dispatcher.invoke(action);         else             action();     } } 

so @ run-time dispatcher picked correctly, observable collection updated , filtered view updates too. when running unit tests exception @ point of trying add new item collection.

can suggest way around can tests working?


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -