当前位置: 首页>>代码示例>>C#>>正文


C# BehaviorSubject.OnError方法代码示例

本文整理汇总了C#中BehaviorSubject.OnError方法的典型用法代码示例。如果您正苦于以下问题:C# BehaviorSubject.OnError方法的具体用法?C# BehaviorSubject.OnError怎么用?C# BehaviorSubject.OnError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BehaviorSubject的用法示例。


在下文中一共展示了BehaviorSubject.OnError方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Should_Complete_When_Source_Observable_Errors

        public void Should_Complete_When_Source_Observable_Errors()
        {
            var source = new BehaviorSubject<object>(1);
            var target = new ExpressionObserver(source, "Foo");
            var completed = false;

            target.Subscribe(_ => { }, () => completed = true);
            source.OnError(new Exception());

            Assert.True(completed);
        }
开发者ID:jkoritzinsky,项目名称:Avalonia,代码行数:11,代码来源:ExpressionObserverTests_Lifetime.cs

示例2: errors_are_sent_through_scheduler

        public void errors_are_sent_through_scheduler()
        {
            ManualScheduler scheduler = new ManualScheduler();

            BehaviorSubject<int> subject = new BehaviorSubject<int>(0, scheduler);

            StatsObserver<int> stats = new StatsObserver<int>();

            subject.OnError(new Exception());

            subject.Subscribe(stats);

            Assert.IsFalse(stats.ErrorCalled);

            scheduler.RunNext();
            Assert.IsTrue(stats.ErrorCalled);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:17,代码来源:BehaviorSubjectFixture.cs

示例3: BehaviorSubject

        public void BehaviorSubject()
        {
            // OnCompletedPattern
            {
                var subject = new BehaviorSubject<int>(3333);

                var onNext = new List<int>();
                var exception = new List<Exception>();
                int onCompletedCallCount = 0;
                var _ = subject.Subscribe(x => onNext.Add(x), x => exception.Add(x), () => onCompletedCallCount++);

                onNext.IsCollection(3333);

                subject.OnNext(1);
                subject.OnNext(10);
                subject.OnNext(100);
                subject.OnNext(1000);

                onNext.IsCollection(3333, 1, 10, 100, 1000);

                // re subscription
                onNext.Clear();
                _.Dispose();
                subject.Subscribe(x => onNext.Add(x), x => exception.Add(x), () => onCompletedCallCount++);
                onNext.IsCollection(1000);

                subject.OnCompleted();
                onCompletedCallCount.Is(1);

                subject.OnNext(1);
                subject.OnNext(10);
                subject.OnNext(100);
                onNext.Count.Is(1);

                subject.OnCompleted();
                subject.OnError(new Exception());
                exception.Count.Is(0);
                onCompletedCallCount.Is(1);

                // ++subscription
                onNext.Clear();
                onCompletedCallCount = 0;
                subject.Subscribe(x => onNext.Add(x), x => exception.Add(x), () => onCompletedCallCount++);
                onNext.Count.Is(0);
                exception.Count.Is(0);
                onCompletedCallCount.Is(1);
            }

            // OnErrorPattern
            {
                var subject = new BehaviorSubject<int>(3333);

                var onNext = new List<int>();
                var exception = new List<Exception>();
                int onCompletedCallCount = 0;
                subject.Subscribe(x => onNext.Add(x), x => exception.Add(x), () => onCompletedCallCount++);

                subject.OnNext(1);
                subject.OnNext(10);
                subject.OnNext(100);
                subject.OnNext(1000);
                onNext.IsCollection(3333, 1, 10, 100, 1000);

                subject.OnError(new Exception());
                exception.Count.Is(1);

                subject.OnNext(1);
                subject.OnNext(10);
                subject.OnNext(100);
                onNext.Count.Is(5);

                subject.OnCompleted();
                subject.OnError(new Exception());
                exception.Count.Is(1);
                onCompletedCallCount.Is(0);

                // ++subscription
                onNext.Clear();
                exception.Clear();
                onCompletedCallCount = 0;
                subject.Subscribe(x => onNext.Add(x), x => exception.Add(x), () => onCompletedCallCount++);
                onNext.Count.Is(0);
                exception.Count.Is(1);
                onCompletedCallCount.Is(0);
            }
        }
开发者ID:ragcat,项目名称:UniRx,代码行数:86,代码来源:UnitTests.cs

示例4: Value_ThrowsAfterOnError

        public void Value_ThrowsAfterOnError()
        {
            var s = new BehaviorSubject<int>(42);
            Assert.AreEqual(42, s.Value);

            s.OnError(new InvalidOperationException());
            
            Assert.Fail("Should not be able to read Value: {0}", s.Value);
        }
开发者ID:Balharmander123,项目名称:Rx.NET,代码行数:9,代码来源:BehaviorSubjectTest.cs

示例5: HasObservers_OnError

        public void HasObservers_OnError()
        {
            var s = new BehaviorSubject<int>(42);
            Assert.IsFalse(s.HasObservers);

            var d = s.Subscribe(_ => { }, ex => { });
            Assert.IsTrue(s.HasObservers);

            s.OnNext(42);
            Assert.IsTrue(s.HasObservers);

            s.OnError(new Exception());
            Assert.IsFalse(s.HasObservers);
        }
开发者ID:Balharmander123,项目名称:Rx.NET,代码行数:14,代码来源:BehaviorSubjectTest.cs

示例6: Observable_Current_propagates_exception

        public async Task Observable_Current_propagates_exception()
        {
            var subject = new BehaviorSubject<int>(1);
            var asyncEnumerable = subject.Current();

            using (var asyncEnumerator = asyncEnumerable.GetEnumerator())
            {
                subject.OnNext(1);
                subject.OnNext(2);
                subject.OnNext(3);

                subject.OnError(new InvalidOperationException());

                asyncEnumerator
                    .Awaiting(_ => _.MoveNext(CancellationToken.None))
                    .ShouldThrowExactly<AggregateException>()
                    .Where(ex => ex.GetBaseException() is InvalidOperationException);
            }
        }
开发者ID:ExRam,项目名称:ExRam.Extensions,代码行数:19,代码来源:ObservableExtensionsTests.cs

示例7: Value_ThrowsAfterOnError

        public void Value_ThrowsAfterOnError()
        {
            var s = new BehaviorSubject<int>(42);
            Assert.AreEqual(42, s.Value);

            s.OnError(new InvalidOperationException());

            ReactiveAssert.Throws<InvalidOperationException>(() =>
            {
                var ignored = s.Value;
            });

            ReactiveAssert.Throws<InvalidOperationException>(() =>
            {
                var x = default(int);
                s.TryGetValue(out x);
            });
        }
开发者ID:Ziriax,项目名称:Rx.NET,代码行数:18,代码来源:BehaviorSubjectTest.cs

示例8: replays_no_values_when_errored

        public void replays_no_values_when_errored()
        {
            BehaviorSubject<int> subject = new BehaviorSubject<int>(0);

            StatsObserver<int> stats = new StatsObserver<int>();

            subject.OnNext(1);
            subject.OnNext(2);
            subject.OnNext(3);
            subject.OnError(new Exception());

            subject.Subscribe(stats);

            Assert.AreEqual(0, stats.NextCount);
            Assert.IsTrue(stats.ErrorCalled);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:16,代码来源:BehaviorSubjectFixture.cs

示例9: replays_error_sequence

        public void replays_error_sequence()
        {
            BehaviorSubject<int> subject = new BehaviorSubject<int>(0);

            StatsObserver<int> stats = new StatsObserver<int>();

            subject.OnError(new Exception());

            subject.Subscribe(stats);

            Assert.IsTrue(stats.ErrorCalled);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:12,代码来源:BehaviorSubjectFixture.cs


注:本文中的BehaviorSubject.OnError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。