2

I've some code in my view model as follows:

miService.GetSomething(par1, par2)
.ObserveOnDispatcher()
.Subscribe(dt =>
 {
    DoSomething(dt);
 });

Then in my test, I'm "mocking" my service as follows:

miService.Setup(ms => ms.GetSomething(....))
.Returns(Observable.Return(XYZ));

The problem is that due to the ObserveOnDispatcher, the subscribe delegate is never executed.

I've seen some code with DispatcherFrame and PushFrame, but the problem is that I don't know "where", I can call

frame.Continue = false;
abatishchev
  • 98,240
  • 88
  • 296
  • 433
José F. Romaniello
  • 13,866
  • 3
  • 36
  • 38

1 Answers1

5

You could try

var frame = new DispatcherFrame();
Dispatcher.CurrentDispatcher.BeginInvoke(
  DispatcherPriority.Background, 
  new Action(() => frame.Continue = false));
Dispatcher.PushFrame(frame);
Samuel Jack
  • 32,712
  • 16
  • 118
  • 155
  • Sorry but this code doesn't even compile. if i change to : Dispatcher.CurrentDispatcher.BeginInvoke( DispatcherPriority.Background, new DispatcherOperationCallback(o => { frame.Continue = false; return null; // or return null; })); I get the following exception: System.Reflection.TargetParameterCountException : Parameter count mismatch. – José F. Romaniello Feb 02 '10 at 16:12
  • Sorry - should have tried to compile my code first. Try the updated version. – Samuel Jack Feb 02 '10 at 16:42