Unità testare qualcosa con ObserveOnDispatcher
-
25-09-2019 - |
Domanda
Ho un po 'di codice nel mio modello di vista come segue:
miService.GetSomething(par1, par2)
.ObserveOnDispatcher()
.Subscribe(dt =>
{
DoSomething(dt);
});
Poi, nel mio test, ho "beffarda" il mio servizio nel seguente modo:
miService.Setup(ms => ms.GetSomething(....))
.Returns(Observable.Return(XYZ));
Il problema è che a causa della ObserveOnDispatcher, l'sottoscrivere delegato non viene mai eseguito.
Ho visto alcuni codice con DispatcherFrame e PushFrame, ma il problema è che non so "dove", posso chiamare
frame.Continue = false;
Soluzione
Si potrebbe provare
var frame = new DispatcherFrame();
Dispatcher.CurrentDispatcher.BeginInvoke(
DispatcherPriority.Background,
new Action(() => frame.Continue = false));
Dispatcher.PushFrame(frame);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow