Note that there are some explanatory texts on larger screens.

plurals
  1. POUnit Testing CompositePresentationEvent when using the Dispatcher
    primarykey
    data
    text
    <p>Im using the Prism/Composite Application Library and trying to unit test some code that subscribes to a CompositePresentationEvent using the EventAggregator. The code that is raising the event is raising it on another thread so I am subscribing to the event using ThreadOption.UIThread.</p> <p>When the event raises the callback it uses the application dispatcher to put it onto the UI thread. This is fine during normal execution but during a unit test there is no dispatcher. The code in CompositePresentationEvent looks like this:</p> <pre><code> private IDispatcherFacade UIDispatcher { get { if (uiDispatcher == null) { this.uiDispatcher = new DefaultDispatcher(); } return uiDispatcher; } } public class DefaultDispatcher : IDispatcherFacade { /// &lt;summary&gt; /// Forwards the BeginInvoke to the current application's &lt;see cref="Dispatcher"/&gt;. /// &lt;/summary&gt; /// &lt;param name="method"&gt;Method to be invoked.&lt;/param&gt; /// &lt;param name="arg"&gt;Arguments to pass to the invoked method.&lt;/param&gt; public void BeginInvoke(Delegate method, object arg) { if (Application.Current != null) { Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, method, arg); } } } </code></pre> <p>The problem being that CompositePresentationEvent is tied to the DefaultDispatcher, and this dispatcher does nothing if there is no Application running.</p> <p>Has anyone had any success unit testing in this kind of situation? Any tips or workarounds to kick the dispatcher into life?</p> <p>I know I could make my callback internal and allow my unit test to call this method but I would prefer not to change my code and leave this approach as a last resort.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload