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;
                }
            }
Exemple #2
0
        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();
        }
Exemple #3
0
        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);
        }
Exemple #4
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);
        }
Exemple #5
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);
        }
Exemple #6
0
        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();
        }
Exemple #7
0
        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>());
        }
Exemple #8
0
        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);
        }
Exemple #9
0
        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>());
        }
Exemple #10
0
            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);
 }