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


C# TestScheduler.Start方法代码示例

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


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

示例1: FilterBurstsInHotObservable

        public void FilterBurstsInHotObservable()
        {
            var scheduler = new TestScheduler();
            var xs = scheduler.CreateHotObservable(
                OnNext(250, 1),
                OnNext(258, 2),
                OnNext(262, 3),

                OnNext(450, -1),
                OnNext(451, -2),
                OnNext(460, -3),

                OnCompleted<int>(500)
                );

            var res = scheduler.Start(() => xs.FilterBursts(TimeSpan.FromTicks(10),scheduler));

            res.Messages.AssertEqual(
                OnNext(250, 1),
                OnNext(450, -1),
                OnCompleted<int>(500));

            xs.Subscriptions.AssertEqual(
                Subscribe(Subscribed, 500));
        }
开发者ID:tamirdresher,项目名称:RxInAction,代码行数:25,代码来源:FilterBurstsTimeTests.cs

示例2: Test_Select_Success

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

            // Create an observable, remember subscribe happens at 200
            var obs = scheduler.CreateHotObservable<string>(
                OnNext(150, "Erik"),
                OnNext(210, "Bart"),
                OnNext(220, "Matthew"),
                OnCompleted<string>(230)
            );

            // Start our virtual time scheduler
            var res = scheduler.Start(() =>
                {
                    return obs.Select(x => x.Length);
                });

            // Check the messages that came through at a specific time
            res.Messages.AssertEqual(
                OnNext(210, 4),
                OnNext(220, 7),
                OnCompleted<int>(230)
            );

            // Check for when subscribe and unsubscribe
            obs.Subscriptions.AssertEqual(
                Subscribe(200, 230)
            );
        }
开发者ID:Reactive-Extensions,项目名称:NDC-Oslo-2014,代码行数:30,代码来源:Rxtests.cs

示例3: FilterBurstsInColdObservable

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

            // A cold observable will begin emitting when the observer subscribes
            // in this case, each emission defined for the observable will be realtive to the observer subscription time
            // which by default is 200 (defined in ReactiveTest.Subscribed)
            var xs = scheduler.CreateColdObservable(
                OnNext(250, 1),
                OnNext(258, 2),
                OnNext(262, 3),

                OnNext(450, -1),
                OnNext(451, -2),
                OnNext(460, -3),

                OnCompleted<int>(500)
                );

            var res = scheduler.Start(() => xs.FilterBursts(TimeSpan.FromTicks(10), scheduler));

            res.Messages.AssertEqual(
                OnNext(450, 1),
                OnNext(650, -1),
                OnCompleted<int>(700));

            xs.Subscriptions.AssertEqual(
                Subscribe(ReactiveTest.Subscribed, 700));
        }
开发者ID:tamirdresher,项目名称:RxInAction,代码行数:29,代码来源:FilterBurstsTimeTests.cs

示例4: Test_Where_Error

        public void Test_Where_Error()
        {
            var exception = new Exception();
            var scheduler = new TestScheduler();

            var obs = scheduler.CreateHotObservable<string>(
                OnNext(150, "Erik"),
                OnNext(210, "Bart"),
                OnNext(220, "Matthew"),
                OnError<string>(230, exception)
            );

            var res = scheduler.Start(() =>
            {
                return obs.Where(x => x.Length > 4);
            });

            res.Messages.AssertEqual(
                OnNext(220, "Matthew"),
                OnError<string>(230, exception)
            );

            obs.Subscriptions.AssertEqual(
                Subscribe(200, 230)
            );
        }
开发者ID:Reactive-Extensions,项目名称:NDC-Oslo-2014,代码行数:26,代码来源:Rxtests.cs

示例5: CompletelyDefaultReactiveCommandShouldFire

        public void CompletelyDefaultReactiveCommandShouldFire()
        {
            var sched = new TestScheduler();
            var fixture = createCommand(null, sched);
            Assert.True(fixture.CanExecute(null));

            string result = null;
            fixture.Subscribe(x => result = x as string);

            fixture.Execute("Test");
            sched.Start();
            Assert.Equal("Test", result);
            fixture.Execute("Test2");
            sched.Start();
            Assert.Equal("Test2", result);
        }
开发者ID:gluck,项目名称:ReactiveUI,代码行数:16,代码来源:ReactiveCommandTest.cs

示例6: ConnectableObservable_Connected

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

            var xs = scheduler.CreateHotObservable<int>(
                OnNext(210, 1),
                OnNext(220, 2),
                OnNext(230, 3),
                OnNext(240, 4),
                OnCompleted<int>(250)
            );

            var subject = new MySubject();

            var conn = new ConnectableObservable<int>(xs, subject);
            var disconnect = conn.Connect();

            var res = scheduler.Start(() => conn);

            res.Messages.AssertEqual(
                OnNext(210, 1),
                OnNext(220, 2),
                OnNext(230, 3),
                OnNext(240, 4),
                OnCompleted<int>(250)
            );
        }
开发者ID:jamilgeor,项目名称:rx,代码行数:27,代码来源:ConnectableObservableTest.cs

示例7: SameAsRetry_OnCompleted

        public void SameAsRetry_OnCompleted()
        {
            var scheduler = new TestScheduler();
            var source = scheduler.CreateHotObservable<int>(
                OnNext(0, 1),
                OnNext(0, 2),
                OnCompleted<int>(0),
                OnNext(0, 3));

            var called = 0;
            var retryRecorder = scheduler.CreateObserver<int>();
            source.Retry().Subscribe(retryRecorder);
            var onErrorRecorder = scheduler.CreateObserver<int>();
            source.OnErrorRetry((Exception e) => { ++called; }).Subscribe(onErrorRecorder);

            scheduler.Start();

            retryRecorder.Messages.Is(
                OnNext(1, 1),
                OnNext(1, 2),
                OnCompleted<int>(1));

            onErrorRecorder.Messages.Is(retryRecorder.Messages);
            called.Is(0);
        }
开发者ID:ailen0ada,项目名称:ReactiveProperty,代码行数:25,代码来源:RetryObservableExtensionsTest.cs

示例8: SameAsRetry_OnError

        public void SameAsRetry_OnError()
        {
            var scheduler = new TestScheduler();
            var ex = new Exception();
            var source = scheduler.CreateColdObservable<int>(
                OnNext(0, 1),
                OnNext(0, 2),
                OnError<int>(0, ex));

            var called = 0;
            var retryRecorder = scheduler.CreateObserver<int>();
            source.Retry().Take(5).Subscribe(retryRecorder);
            var onErrorRecorder = scheduler.CreateObserver<int>();
            source.OnErrorRetry((Exception e) => { ++called; }).Take(5).Subscribe(onErrorRecorder);

            scheduler.Start();

            retryRecorder.Messages.Is(
                OnNext(1, 1),
                OnNext(1, 2),
                OnNext(2, 1),
                OnNext(2, 2),
                OnNext(3, 1),
                OnCompleted<int>(3));

            var retryResult = retryRecorder.Messages.ToArray();

            onErrorRecorder.Messages.Is(retryRecorder.Messages);
            called.Is(2);
        }
开发者ID:ailen0ada,项目名称:ReactiveProperty,代码行数:30,代码来源:RetryObservableExtensionsTest.cs

示例9: AddRangeNotifiesAsResetInsteadOfIndividualItemsWhenItemCountAboveThresholdTest

        public void AddRangeNotifiesAsResetInsteadOfIndividualItemsWhenItemCountAboveThresholdTest(int lowerLimit, int upperLimit)
        {
            // given
            var rangeToAdd = Enumerable.Range(lowerLimit, upperLimit - lowerLimit + 1).ToList();
            var testScheduler = new TestScheduler();
            var testObserverCollectionChanges = testScheduler.CreateObserver<IObservableCollectionChange<int>>();
            var testObserverResets = testScheduler.CreateObserver<Unit>();

            using (var observableList = new ObservableList<int>())
            {
                // when
                observableList.ThresholdAmountWhenChangesAreNotifiedAsReset = 0;

                observableList.CollectionChanges.Subscribe(testObserverCollectionChanges);
                observableList.Resets.Subscribe(testObserverResets);

                testScheduler.Schedule(TimeSpan.FromTicks(100), () => { observableList.AddRange(rangeToAdd); });
                testScheduler.Start();

                // then
                var shouldBeReset = rangeToAdd.Count >= observableList.ThresholdAmountWhenChangesAreNotifiedAsReset;
                testObserverCollectionChanges.Messages.Count.Should().Be(shouldBeReset ? 1 : rangeToAdd.Count);
                testObserverCollectionChanges.Messages.Should()
                    .Match(recordedMessages =>
                        recordedMessages.All(message => message.Value.Value.ChangeType == (shouldBeReset ? ObservableCollectionChangeType.Reset : ObservableCollectionChangeType.ItemAdded)));

                testObserverResets.Messages.Count.Should().Be(shouldBeReset ? 1 : 0);
            }
        }
开发者ID:jbattermann,项目名称:JB.Common,代码行数:29,代码来源:ObservableListAddMultipleItemsTests.cs

示例10: Bug_1283

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

            var xs = scheduler.CreateHotObservable(
                OnNext(100, 1),
                OnNext(220, 2),
                OnNext(240, 3),
                OnNext(300, 4),
                OnNext(310, 5),
                OnCompleted<int>(350)
            );

            var results = scheduler.Start(() =>
                xs.Window(TimeSpan.FromTicks(100), scheduler).Select((x, i) => x.Select(y => i.ToString() + " " + y.ToString()).Concat(Observable.Return(i.ToString() + " end", scheduler))).Merge()
            );

            results.Messages.AssertEqual(
                OnNext(220, "0 2"),
                OnNext(240, "0 3"),
                OnNext(300, "0 4"),
                OnNext(301, "0 end"),
                OnNext(310, "1 5"),
                OnNext(351, "1 end"),
                OnCompleted<string>(351)
            );
        }
开发者ID:Ziriax,项目名称:Rx.NET,代码行数:27,代码来源:RegressionTest.cs

示例11: Test

        public void Test()
        {
            var testScheduler = new TestScheduler();
            var recorder = testScheduler.CreateObserver<int>();

            var notifier = new ScheduledNotifier<int>(testScheduler);
            notifier.Subscribe(recorder);

            notifier.Report(1);
            notifier.Report(2);
            notifier.Report(3, TimeSpan.FromMinutes(10));
            notifier.Report(4, TimeSpan.FromMinutes(1));
            notifier.Report(5, TimeSpan.FromMinutes(5));
            notifier.Report(6);

            testScheduler.Start();

            recorder.Messages.Is(
                OnNext(1, 1),
                OnNext(1, 2),
                OnNext(1, 6),
                OnNext(TimeSpan.FromMinutes(1).Ticks, 4),
                OnNext(TimeSpan.FromMinutes(5).Ticks, 5),
                OnNext(TimeSpan.FromMinutes(10).Ticks, 3));
        }
开发者ID:ailen0ada,项目名称:ReactiveProperty,代码行数:25,代码来源:ScheduledNotifierTest.cs

示例12: TestOffset

        public void TestOffset()
        {
            var testScheduler = new TestScheduler();
            var recorder = testScheduler.CreateObserver<int>();

            var notifier = new ScheduledNotifier<int>(testScheduler);
            notifier.Subscribe(recorder);

            var origin = new DateTimeOffset(1999, 1, 1, 1, 1, 1, TimeSpan.Zero);

            notifier.Report(1);
            notifier.Report(2);
            notifier.Report(3, origin);
            notifier.Report(4, origin.AddDays(10));
            notifier.Report(5, origin.AddYears(1));
            notifier.Report(6);

            testScheduler.Start();

            recorder.Messages.Is(
                OnNext(1, 1),
                OnNext(1, 2),
                OnNext(1, 6),
                OnNext(origin.Ticks, 3),
                OnNext(origin.AddDays(10).Ticks, 4),
                OnNext(origin.AddYears(1).Ticks, 5));
        }
开发者ID:ailen0ada,项目名称:ReactiveProperty,代码行数:27,代码来源:ScheduledNotifierTest.cs

示例13: CreatColdObservable_LongWay

        public void CreatColdObservable_LongWay()
        {
            var testScheduler = new TestScheduler();

            ITestableObservable<int> coldObservable = testScheduler.CreateColdObservable<int>(
                // This is the long way to configure emissions. see below for a shorter one
                new Recorded<Notification<int>>(20, Notification.CreateOnNext<int>(1)),
                new Recorded<Notification<int>>(40, Notification.CreateOnNext<int>(2)),
                new Recorded<Notification<int>>(60, Notification.CreateOnCompleted<int>())
                );

            // Creating an observer that captures the emission it recieves
            var testableObserver = testScheduler.CreateObserver<int>();

            // Subscribing the observer, but until TestSchduler is started, emissions
            // are not be emitted
            coldObservable
                .Subscribe(testableObserver);

            // Starting the TestScheduler means that only now emissions that were configured
            // will be emitted
            testScheduler.Start();

            // Asserting that every emitted value was recieved by the observer at the
            // same time it was emitted
            coldObservable.Messages
                .AssertEqual(testableObserver.Messages);

            // Asserting that the observer was subscribed at Scheduler inital time
            coldObservable.Subscriptions.AssertEqual(
                Subscribe(0));
        }
开发者ID:tamirdresher,项目名称:RxInAction,代码行数:32,代码来源:ColdObservable.cs

示例14: CreatColdObservable_ShortWay

        public void CreatColdObservable_ShortWay()
        {
            var testScheduler = new TestScheduler();
            ITestableObservable<int> coldObservable =
                testScheduler.CreateColdObservable<int>(
                    // Inheritting your test class from ReactiveTest opens the following
                    // factory methods that make your code much more fluent
                    OnNext(20, 1),
                    OnNext(40, 2),
                    OnNext(60, 2),
                    OnCompleted<int>(900)
                    );

            // Creating an observer that captures the emission it recieves
            var testableObserver = testScheduler.CreateObserver<int>();

            // Subscribing the observer, but until TestSchduler is started, emissions
            // are not be emitted
            coldObservable
                .Subscribe(testableObserver);

            // Starting the TestScheduler means that only now emissions that were configured
            // will be emitted
            testScheduler.Start();

            // Asserting that every emitted value was recieved by the observer at the
            // same time it was emitted
            coldObservable.Messages
                .AssertEqual(testableObserver.Messages);

            // Asserting that the observer was subscribed at Scheduler inital time
            coldObservable.Subscriptions.AssertEqual(
                Subscribe(0));
        }
开发者ID:tamirdresher,项目名称:RxInAction,代码行数:34,代码来源:ColdObservable.cs

示例15: TaskToObservable_NonVoid_Complete_BeforeCreate

        public void TaskToObservable_NonVoid_Complete_BeforeCreate()
        {
            var taskScheduler = new TestTaskScheduler();
            var taskFactory = new TaskFactory(taskScheduler);
            var res = default(ITestableObserver<int>);

            taskFactory.StartNew(() =>
            {
                var scheduler = new TestScheduler();

                var taskSource = new TaskCompletionSource<int>();
                taskSource.Task.ContinueWith(t => { var e = t.Exception; });

                scheduler.ScheduleAbsolute(10, () => taskSource.SetResult(42));

                res = scheduler.Start(() =>
                    taskSource.Task.ToObservable()
                );
            });

            res.Messages.AssertEqual(
                OnNext(200, 42),
                OnCompleted<int>(200)
            );
        }
开发者ID:Ziriax,项目名称:Rx.NET,代码行数:25,代码来源:TaskObservableExtensionsTest.cs


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