public void CallingRefreshAfterCausesNewRefresh() { var mockFinder = new Mock <ISpheroFinder>(); Ioc.RegisterServiceInstance(mockFinder.Object); Action <IList <IAvailableSphero> > successCallback = null; Action <Exception> failureCallback = null; mockFinder.Setup( finder => finder.Find(It.IsAny <Action <IList <IAvailableSphero> > >(), It.IsAny <Action <Exception> >())) .Callback((Action <IList <IAvailableSphero> > onSuccess, Action <Exception> onError) => { successCallback = onSuccess; failureCallback = onError; }); var service = new SpheroListService(); Assert.IsTrue(service.IsRefreshing); Assert.IsNull(service.AvailableSpheros); var mockList = new List <IAvailableSphero>(); successCallback(mockList); Assert.IsFalse(service.IsRefreshing); service.RefreshList(); Assert.IsTrue(service.IsRefreshing); mockFinder.Verify( finder => finder.Find(It.IsAny <Action <IList <IAvailableSphero> > >(), It.IsAny <Action <Exception> >()), Times.Exactly(2)); }
public void CallingRefreshMultipleTimesConcurrentlyJustResultsInOneCall() { var mockFinder = new Mock <ISpheroFinder>(); Ioc.RegisterServiceInstance(mockFinder.Object); var service = new SpheroListService(); Assert.IsTrue(service.IsRefreshing); Assert.IsNull(service.AvailableSpheros); service.RefreshList(); service.RefreshList(); service.RefreshList(); service.RefreshList(); service.RefreshList(); mockFinder.Verify( finder => finder.Find(It.IsAny <Action <IList <IAvailableSphero> > >(), It.IsAny <Action <Exception> >()), Times.Once()); }