private void OnDestroy() { if (_updateSource != null) { _updateSource.Dispose(); _updateSource = null; } if (_lateUpdateSource != null) { _lateUpdateSource.Dispose(); _lateUpdateSource = null; } if (_fixedUpdateSource != null) { _fixedUpdateSource.Dispose(); _fixedUpdateSource = null; } if (_eofUpdateSource != null) { _eofUpdateSource.Dispose(); _eofUpdateSource = null; } }
public void Dispose_CallsCompleted() { // Arrange var updateSource = new AsyncUpdateSource(); var observer = Substitute.For <IObserver <float> >(); updateSource.Subscribe(observer); // Act updateSource.Dispose(); // Assert observer.Received().OnCompleted(); }
public void OnNext_CallsNext() { // Arrange var updateSource = new AsyncUpdateSource(); var observer = Substitute.For <IObserver <float> >(); updateSource.Subscribe(observer); // Act updateSource.OnNext(0); // Assert observer.Received().OnNext(0); }
public void OnNext_CallsUpdate() { // Arrange var updateSource = new AsyncUpdateSource(); var observer = Substitute.For <IAsyncUpdatable>(); updateSource.AddListener(observer); // Act updateSource.OnNext(0); // Assert observer.Received().Update(0); }
public void OnError_CallsError() { // Arrange var updateSource = new AsyncUpdateSource(); var observer = Substitute.For <IObserver <float> >(); var e = new Exception(); updateSource.Subscribe(observer); // Act updateSource.OnError(e); // Assert observer.Received().OnError(e); }
public void Unsubscribe_CanBeCalledFromDispose() { // Arrange var updateSource = new AsyncUpdateSource(); var observer = Substitute.For <IObserver <float> >(); var subscription = updateSource.Subscribe(observer); observer.When(x => x.OnCompleted()).Do(x => subscription.Dispose()); // Act updateSource.Dispose(); // Assert observer.Received(1).OnCompleted(); }
public void AddListener_CanBeCalledFromUpdate() { // Arrange var updateSource = new AsyncUpdateSource(); var observer = Substitute.For <IAsyncUpdatable>(); observer.When(x => x.Update(Arg.Any <float>())).Do(x => updateSource.AddListener(observer)); updateSource.AddListener(observer); // Act updateSource.OnNext(0); updateSource.OnNext(0); // Assert observer.Received(3).Update(Arg.Any <float>()); }
public void Subscribe_CanBeCalledFromOnError() { // Arrange var updateSource = new AsyncUpdateSource(); var observer = Substitute.For <IObserver <float> >(); var subscription = updateSource.Subscribe(observer); var e = new Exception(); observer.When(x => x.OnError(e)).Do(x => updateSource.Subscribe(observer)); // Act updateSource.OnError(e); // Assert observer.Received(1).OnError(e); }
public void Subscribe_CanBeCalledFromOnNext() { // Arrange var updateSource = new AsyncUpdateSource(); var observer = Substitute.For <IObserver <float> >(); var subscription = updateSource.Subscribe(observer); observer.When(x => x.OnNext(Arg.Any <float>())).Do(x => updateSource.Subscribe(observer)); // Act updateSource.OnNext(0); updateSource.OnNext(0); // Assert observer.Received(3).OnNext(Arg.Any <float>()); }
private void OnDestroy() { if (_updateSource != null) { _updateSource.Dispose(); _updateSource = null; } if (_lateUpdateSource != null) { _lateUpdateSource.Dispose(); _lateUpdateSource = null; } if (_fixedUpdateSource != null) { _fixedUpdateSource.Dispose(); _fixedUpdateSource = null; } if (_eofUpdateSource != null) { _eofUpdateSource.Dispose(); _eofUpdateSource = null; } if (_context != null && _context == SynchronizationContext.Current) { SynchronizationContext.SetSynchronizationContext(null); } #if NET_2_0 || NET_2_0_SUBSET lock (_actionQueue) { _actionQueue.Clear(); } #endif _mainThreadContext = null; _context = null; }
public ObservableSubscription(AsyncUpdateSource parent, IObserver <float> observer) { _parent = parent; _observer = observer; _parent._observers.Add(observer); }