Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can unit test using a dispatcher, you just need to use the DispatcherFrame. Here is an example of one of my unit tests that uses the DispatcherFrame to force the dispatcher queue to execute.</p> <pre><code>[TestMethod] public void DomainCollection_AddDomainObjectFromWorkerThread() { Dispatcher dispatcher = Dispatcher.CurrentDispatcher; DispatcherFrame frame = new DispatcherFrame(); IDomainCollectionMetaData domainCollectionMetaData = this.GenerateIDomainCollectionMetaData(); IDomainObject parentDomainObject = MockRepository.GenerateMock&lt;IDomainObject&gt;(); DomainCollection sut = new DomainCollection(dispatcher, domainCollectionMetaData, parentDomainObject); IDomainObject domainObject = MockRepository.GenerateMock&lt;IDomainObject&gt;(); sut.SetAsLoaded(); bool raisedCollectionChanged = false; sut.ObservableCollection.CollectionChanged += delegate(object sender, NotifyCollectionChangedEventArgs e) { raisedCollectionChanged = true; Assert.IsTrue(e.Action == NotifyCollectionChangedAction.Add, "The action was not add."); Assert.IsTrue(e.NewStartingIndex == 0, "NewStartingIndex was not 0."); Assert.IsTrue(e.NewItems[0] == domainObject, "NewItems not include added domain object."); Assert.IsTrue(e.OldItems == null, "OldItems was not null."); Assert.IsTrue(e.OldStartingIndex == -1, "OldStartingIndex was not -1."); frame.Continue = false; }; WorkerDelegate worker = new WorkerDelegate(delegate(DomainCollection domainCollection) { domainCollection.Add(domainObject); }); IAsyncResult ar = worker.BeginInvoke(sut, null, null); worker.EndInvoke(ar); Dispatcher.PushFrame(frame); Assert.IsTrue(raisedCollectionChanged, "CollectionChanged event not raised."); } </code></pre> <p>I found out about it <a href="http://blogs.msdn.com/dancre/archive/2006/07/26/679870.aspx" rel="noreferrer">here</a>.</p>
    singulars
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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