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


C# StatsObserver类代码示例

本文整理汇总了C#中StatsObserver的典型用法代码示例。如果您正苦于以下问题:C# StatsObserver类的具体用法?C# StatsObserver怎么用?C# StatsObserver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: each_subscriber_is_scheduled_individually

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

            AsyncSubject<int> subject = new AsyncSubject<int>(scheduler);

            StatsObserver<int> statsA = new StatsObserver<int>();
            StatsObserver<int> statsB = new StatsObserver<int>();

            subject.OnNext(1);
            subject.OnNext(2);
            subject.OnNext(3);
            subject.OnCompleted();

            subject.Subscribe(statsA);
            subject.Subscribe(statsB);

            scheduler.RunNext();

            Assert.IsTrue(statsA.NextCalled);
            Assert.IsFalse(statsB.NextCalled);

            scheduler.RunNext();

            Assert.IsTrue(statsB.NextCalled);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:26,代码来源:AsyncSubjectFixture.cs

示例2: live_values_are_sent_through_scheduler

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

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

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

            subject.Subscribe(stats);

            subject.OnNext(1);
            subject.OnNext(2);
            subject.OnCompleted();

            Assert.IsFalse(stats.NextCalled);

            scheduler.RunNext();
            Assert.AreEqual(1, stats.NextCount);
            Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 0 }));
            Assert.IsFalse(stats.CompletedCalled);

            scheduler.RunNext();
            Assert.AreEqual(2, stats.NextCount);
            Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 0, 1 }));
            Assert.IsFalse(stats.CompletedCalled);

            scheduler.RunNext();
            Assert.AreEqual(3, stats.NextCount);
            Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 0, 1, 2 }));
            Assert.IsFalse(stats.CompletedCalled);

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

示例3: values_can_be_triggered_by_time_or_count

        public void values_can_be_triggered_by_time_or_count()
        {
            var scheduler = new TestScheduler();

            var source = scheduler.CreateColdObservable(
                // start #1 (@0)
                new Recorded<Notification<int>>(10, OnNext(1)),
                new Recorded<Notification<int>>(12, OnNext(2)),
                new Recorded<Notification<int>>(14, OnNext(3)),
                // start #2 (@ 15)
                new Recorded<Notification<int>>(16, OnNext(4)),
                new Recorded<Notification<int>>(20, OnNext(5)),
                new Recorded<Notification<int>>(24, OnNext(6)),
                new Recorded<Notification<int>>(28, OnNext(7)),
                // start #3 (@ 28)
                // start #4 (@ 43)
                new Recorded<Notification<int>>(50, OnNext(8)),
                new Recorded<Notification<int>>(51, OnCompleted())
            );

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

            source.BufferWithTimeOrCount(new TimeSpan(15), 4, scheduler)
                .Subscribe(stats);

            scheduler.Run();

            Assert.AreEqual(4, stats.NextCount);
            Assert.AreEqual(3, stats.NextValues[0].Count);
            Assert.AreEqual(4, stats.NextValues[1].Count);
            Assert.AreEqual(0, stats.NextValues[2].Count);
            Assert.AreEqual(1, stats.NextValues[3].Count);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:33,代码来源:BufferWithTimeOrCountFixture.cs

示例4: last_value_is_received_after_completed_if_any_connection_is_disposed

        public void last_value_is_received_after_completed_if_any_connection_is_disposed()
        {
            Subject<int> subject = new Subject<int>();

            var stats = new StatsObserver<int>();

            var obs = subject.Prune();
            var connectionA = obs.Connect();
            var connectionB = obs.Connect();

            subject.OnNext(1);
            subject.OnNext(2);
            subject.OnNext(3);

            connectionA.Dispose();

            subject.OnCompleted();

            connectionB.Dispose();

            obs.Subscribe(stats);

            Assert.IsFalse(stats.NextCalled);
            Assert.IsFalse(stats.CompletedCalled);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:25,代码来源:PruneFixture.cs

示例5: values_are_taken_from_each_selected_value

        public void values_are_taken_from_each_selected_value()
        {
            var stats = new StatsObserver<int>();

            var source = new Subject<int>();
            var first = new Subject<int>();
            var second = new Subject<int>();

            var remaining = new Queue<IObservable<int>>();
            remaining.Enqueue(first);
            remaining.Enqueue(second);

            var manObs = source
                .SelectMany(x => remaining.Dequeue())
                .Subscribe(stats);

            source.OnNext(0);
            first.OnNext(1);

            source.OnNext(2);
            second.OnNext(3);
            first.OnNext(4);
            second.OnNext(5);

            Assert.AreEqual(4, stats.NextCount);
            Assert.AreEqual(1, stats.NextValues[0]);
            Assert.AreEqual(3, stats.NextValues[1]);
            Assert.AreEqual(4, stats.NextValues[2]);
            Assert.AreEqual(5, stats.NextValues[3]);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:30,代码来源:SelectManyFixture.cs

示例6: values_are_buffered_in_specified_time

        public void values_are_buffered_in_specified_time()
        {
            var scheduler = new TestScheduler();

            var source = scheduler.CreateColdObservable(
                                                                // start #1 (@0)
                new Recorded<Notification<int>>(10, OnNext(1)),
                new Recorded<Notification<int>>(12, OnNext(2)),
                                                                // start #2 (@ 15)
                                                                // start #3 (@ 30)
                new Recorded<Notification<int>>(40, OnNext(3)),
                                                                // start #4 (@ 45)
                new Recorded<Notification<int>>(50, OnNext(4)),
                new Recorded<Notification<int>>(51, OnCompleted())
            );

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

            source.BufferWithTime(new TimeSpan(15), scheduler)
                .Subscribe(stats);

            scheduler.Run();

            Assert.AreEqual(4, stats.NextCount);
            Assert.AreEqual(2, stats.NextValues[0].Count);
            Assert.AreEqual(0, stats.NextValues[1].Count);
            Assert.AreEqual(1, stats.NextValues[2].Count);
            Assert.AreEqual(1, stats.NextValues[3].Count);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:29,代码来源:BufferWithTimeFixture.cs

示例7: SetUp

        public void SetUp()
        {
            source = new Subject<int>();
            windows = new List<StatsSubject<Unit>>();
            windowsStats = new List<StatsObserver<int>>();
            overallStats = new StatsObserver<int>();

            subscription = source.Window(() =>
                {
                    StatsSubject<Unit> window = new StatsSubject<Unit>();

                    windows.Add(window);

                    return window;
                })
                .Subscribe(o =>
                {
                    var stats = new StatsObserver<int>();
                    windowsStats.Add(stats);

                    o.Subscribe(stats);
                },
                overallStats.OnError,
                overallStats.OnCompleted);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:25,代码来源:WindowFixture.cs

示例8: time_offset_excludes_values_of_exact_offset

        public void time_offset_excludes_values_of_exact_offset()
        {
            var stats = new StatsObserver<IList<int>>();

            var valueScheduler = new ManualScheduler();
            var bufferScheduler = new ManualScheduler();

            DateTimeOffset startTime = DateTimeOffset.UtcNow;

            Observable.Range(0, 5, valueScheduler)
                .BufferWithTime(TimeSpan.FromMilliseconds(30), TimeSpan.FromMilliseconds(20), bufferScheduler)
                .Subscribe(stats);

            Assert.IsFalse(stats.NextCalled);

            bufferScheduler.Now = startTime.AddMilliseconds(10);
            valueScheduler.RunNext();

            bufferScheduler.Now = startTime.AddMilliseconds(20); // exact offset value
            valueScheduler.RunNext();

            bufferScheduler.Now = startTime.AddMilliseconds(30);
            valueScheduler.RunNext();

            bufferScheduler.RunNext();
            bufferScheduler.RunNext();

            Assert.AreEqual(2, stats.NextCount);
            Assert.AreEqual(1, stats.NextValues[1].Count);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:30,代码来源:BufferWithTimeFixture.cs

示例9: complete_does_not_unsubscribe_from_other_subjects

        public void complete_does_not_unsubscribe_from_other_subjects()
        {
            var subjectA = new StatsSubject<int>();
            var subjectB = new StatsSubject<int>();
            var subjectC = new StatsSubject<int>();
            var subjectD = new StatsSubject<int>();

            var stats = new StatsObserver<string>();

            Observable.Join(
                    subjectA.And(subjectB).Then((x,y) => x.ToString() + "," + y.ToString()),
                    subjectC.And(subjectD).Then((x,y) => x.ToString() + "," + y.ToString())
                )
                .Subscribe(stats);

            Assert.AreEqual(1, subjectA.SubscriptionCount);
            Assert.AreEqual(1, subjectB.SubscriptionCount);
            Assert.AreEqual(1, subjectC.SubscriptionCount);
            Assert.AreEqual(1, subjectD.SubscriptionCount);

            subjectA.OnCompleted();

            Assert.AreEqual(0, subjectA.SubscriptionCount);
            Assert.AreEqual(1, subjectB.SubscriptionCount);
            Assert.AreEqual(1, subjectC.SubscriptionCount);
            Assert.AreEqual(1, subjectD.SubscriptionCount);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:27,代码来源:PatternJoinFixture.cs

示例10: finally_action_is_executed_if_disposition_source_subscription_throws_exception

        public void finally_action_is_executed_if_disposition_source_subscription_throws_exception()
        {
            StatsObserver<int> stats = new StatsObserver<int>();

            bool finallyCalled = true;

            try
            {
                Observable.CreateWithDisposable<int>(obs =>
                    {
                        return Disposable.Create(() =>
                        {
                            throw new ApplicationException();
                        });
                    })
                    .Finally(() =>
                    {
                        finallyCalled = true;
                    })
                    .Subscribe(stats)
                    .Dispose();
            }
            finally
            {
                Assert.IsTrue(finallyCalled);
            }
        }
开发者ID:richardszalay,项目名称:raix,代码行数:27,代码来源:FinallyFixture.cs

示例11: repeatCount_includes_initial_subscription

        public void repeatCount_includes_initial_subscription()
        {
            var stats = new StatsObserver<int>();

            Observable.Return(1).Repeat(2).Subscribe(stats);

            Assert.AreEqual(2, stats.NextCount);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:8,代码来源:RepeatFixture.cs

示例12: exception_thrown_in_error_action_is_bubbled

        public void exception_thrown_in_error_action_is_bubbled()
        {
            StatsObserver<int> stats = new StatsObserver<int>();

            Observable.Throw<int>(new Exception())
                .Do(x => { }, e => { throw new ApplicationException(); })
                .Subscribe(stats);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:8,代码来源:DoFixture.cs

示例13: exception_thrown_in_next_action_bubbles_when_complete_action_is_specifid

        public void exception_thrown_in_next_action_bubbles_when_complete_action_is_specifid()
        {
            StatsObserver<int> stats = new StatsObserver<int>();

            Observable.Range(0, 2)
                .Do(x => { throw new ApplicationException(); }, e => { }, () => { })
                .Subscribe(stats);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:8,代码来源:DoFixture.cs

示例14: empty_sequence

        public void empty_sequence()
        {
            var stats = new StatsObserver<bool>();

            Observable.Empty<int>()
                .All(x => true)
                .Subscribe(stats);

            Assert.IsTrue(stats.NextValues[0]);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:10,代码来源:AllFixture.cs

示例15: value_equals_number_of_values

        public void value_equals_number_of_values()
        {
            StatsObserver<int> stats = new StatsObserver<int>();

            Observable.Range(5, 3).Count().Subscribe(stats);

            Assert.AreEqual(1, stats.NextCount);
            Assert.AreEqual(3, stats.NextValues[0]);
            Assert.IsTrue(stats.CompletedCalled);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:10,代码来源:CountFixture.cs


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