public void Execute_ShouldCallCallback( object expected, TestSchedulers schedulers) { //arrange object actual = null; var value = Observable.Return(expected, ImmediateScheduler.Instance); var sut = new ObservableMvvmCommand <object, object>( o => value, schedulers, schedulers, "name", new AlwaysTrueCanExecuteStrategy <object>(), doObserver: () => Observer.Create <object>(o => actual = o), doScheduler: ImmediateScheduler.Instance); //act sut.Execute(null); schedulers.AdvanceBy(200); //assert actual.Should().Be(expected); }
public void Show_OnePriceUpdate_OnePrice() { var modelMock = new Mock <IMyModel>(); var schedulers = new TestSchedulers(); var viewModel = new MyViewModel(modelMock.Object, schedulers); var pricesSubject = new Subject <decimal>(); modelMock.Setup(m => m.PriceStream(It.Is <string>(symbol => symbol == "AAPL"))).Returns(pricesSubject); viewModel.Show("AAPL"); schedulers.ThreadPool.Schedule <object>(null, (_, a) => { pricesSubject.OnNext(10); return(Disposable.Empty); }); schedulers.ThreadPool.AdvanceTo(1); schedulers.Dispatcher.AdvanceTo(1); Assert.AreEqual(1, viewModel.Prices.Count); }
public void Execute_ShouldBeCalledWithArg( IObservable <object> value, object arg, TestSchedulers schedulers) { //arrange object actual = null; var sut = new ObservableMvvmCommand <object, object>(o => { actual = o; return(value); }, schedulers, schedulers, "name", new AlwaysTrueCanExecuteStrategy <object>()); //act sut.Execute(arg); schedulers.AdvanceBy(200); //assert actual.Should().Be(arg); }
public MyViewModel(IMyModel myModel, TestSchedulers schedulers) { _myModel = myModel; _schedulers = schedulers; _prices = new ObservableCollection <decimal>(); }