private IEnumerable <IDisposable> Binding() { yield return(DocumentManagerViewModel.WhenAnyValue(x => x.IsBusy).Subscribe(isBusy => IsBusy = isBusy)); yield return (this.WhenAnyValue(x => x.HasDocument) .Where(doc => doc != null) .Subscribe(DocumentManagerViewModel.SetHasDocument)); yield return (this.WhenAny(x => x.SelectedDocument).Where(doc => doc != null && doc.Content == null).Subscribe( doc => { var loader = new AsyncRunner <byte[]>(); loader.RegisterFunction( () => { using (IUnitOfWork unitOfWork = this._unitOfWorkFactory.Create()) { var service = unitOfWork.Create <IAttachedDocumentService>(); return service.GetContent(doc.Rn); } }); var bytes = loader.GetInvokedTask().Result; if (bytes == null || bytes.Length == 0) { doc.Content = null; } else { doc.Content = bytes; } })); }
public void RunTest2() { var runner = new AsyncRunner <string>(); runner.RegisterFunction(() => "HELLO WORLD!"); bool isSuccessfull = runner.Wait(); Assert.That(isSuccessfull); Assert.That(runner.Result, Is.EqualTo("HELLO WORLD!")); }
public void LoadNotificationComplete() { bool loadNotificationComplete = false; var runner = new AsyncRunner <string>(); runner.RegisterFunction(() => "HELLO WORLD!"); runner.LoadCompletedNotification.Subscribe( res => { loadNotificationComplete = true; Assert.That(res, Is.EqualTo("HELLO WORLD!")); }); runner.Wait(); Assert.That(loadNotificationComplete == true); }
public void ThrowException() { byte countHandledException = 0; var runner = new AsyncRunner <string>(); runner.ThrownExceptions.Subscribe(exc => { countHandledException++; Assert.That(exc, Is.InstanceOf <Exception>()); Assert.That(exc.Message, Is.EqualTo("SASAI LALKA!")); throw exc; }); runner.RegisterFunction(() => { throw new Exception("SASAI LALKA!"); }); if (runner.Wait()) { Assert.Fail(); } if (runner.Wait()) { Assert.Fail(); } if (runner.Wait()) { Assert.Fail(); } if (countHandledException != 3) { Assert.Fail("Должно быть обработано 3 исключения, а обработано: " + countHandledException); } }