开发者

Unit testing something with ObserveOnDispatcher

开发者 https://www.devze.com 2022-12-18 15:40 出处:网络
I\'ve some code i开发者_开发问答n my view model as follows: miService.GetSomething(par1, par2) .ObserveOnDispatcher()

I've some code i开发者_开发问答n 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;


You could try

var frame = new DispatcherFrame();
Dispatcher.CurrentDispatcher.BeginInvoke(
  DispatcherPriority.Background, 
  new Action(() => frame.Continue = false));
Dispatcher.PushFrame(frame);
0

精彩评论

暂无评论...
验证码 换一张
取 消