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


C# TestScheduler.Run方法代码示例

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


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

示例1: OAPHShouldRethrowErrors

        public void OAPHShouldRethrowErrors()
        {
            var input = new Subject<int>();
            var sched = new TestScheduler();

            var fixture = new ObservableAsPropertyHelper<int>(input,
                _ => { }, -5, sched);

            Assert.AreEqual(-5, fixture.Value);
            (new[] { 1, 2, 3, 4 }).Run(x => input.OnNext(x));

            sched.Run();

            Assert.AreEqual(4, fixture.Value);

            input.OnError(new Exception("Die!"));

            sched.Run();

            try {
                Assert.AreEqual(4, fixture.Value);
            } catch {
                return;
            }
            Assert.Fail("We should've threw there");
        }
开发者ID:charles-cai,项目名称:ReactiveXaml,代码行数:26,代码来源:ObservableAsPropertyHelperTest.cs

示例2: InputHasADelayBetweenCharactersOfLongerThanFiveSecondsDuringSequence

        public void InputHasADelayBetweenCharactersOfLongerThanFiveSecondsDuringSequence()
        {
            var scheduler = new TestScheduler();
            var inputSequence = scheduler.CreateHotObservable(
                OnNextForAll(1.0.Seconds(), "a^hello"),
                OnNextForAll(6.1.Seconds(), "world$"),
                OnNextForAll(7.0.Seconds(), "^Rx$"),
                OnCompleted<char>(7.5.Seconds())
                );

            var results = scheduler.Run(() => inputSequence.ToBarcodeReadings(scheduler),
                0.0.Seconds().Ticks,
                0.5.Seconds().Ticks,
                10.Seconds().Ticks
                );

            results.AssertEqual(EnumerableEx.Concat(
                OnNext(7.Seconds(), "Rx"),
                OnCompleted<string>(7.5.Seconds())
                ));

            inputSequence.Subscriptions.AssertEqual(
                Subscribe(0.5.Seconds(), 7.5.Seconds())
                );
        }
开发者ID:caleb-vear,项目名称:BarcodeScannerRxSample,代码行数:25,代码来源:BarcodeReaderOperatorTests.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: OAPHShouldProvideLatestValue

        public void OAPHShouldProvideLatestValue()
        {
            var sched = new TestScheduler();
            var input = new Subject<int>();

            var fixture = new ObservableAsPropertyHelper<int>(input,
                _ => { }, -5, sched);

            Assert.AreEqual(-5, fixture.Value);
            (new[] { 1, 2, 3, 4 }).Run(x => input.OnNext(x));

            sched.Run();
            Assert.AreEqual(4, fixture.Value);

            input.OnCompleted();
            sched.Run();
            Assert.AreEqual(4, fixture.Value);
        }
开发者ID:charles-cai,项目名称:ReactiveXaml,代码行数:18,代码来源:ObservableAsPropertyHelperTest.cs

示例5: ToObservable_Empty

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

            var res = scheduler.Run(() => new Notification<int>.OnCompleted().ToObservable(scheduler)).ToArray();
            res.AssertEqual(
                OnCompleted<int>(201)
            );
        }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:9,代码来源:NotificationTest.cs

示例6: ToObservable_Throw

        public void ToObservable_Throw()
        {
            var ex = new Exception();

            var scheduler = new TestScheduler();

            var res = scheduler.Run(() => new Notification<int>.OnError(ex).ToObservable(scheduler)).ToArray();
            res.AssertEqual(
                OnError<int>(201, ex)
            );
        }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:11,代码来源:NotificationTest.cs

示例7: OAPHShouldFireChangeNotifications

        public void OAPHShouldFireChangeNotifications()
        {
            var sched = new TestScheduler();
            var output = new List<int>();

            var input = new[] { 1, 2, 3, 3, 4 }.ToObservable();
            var fixture = new ObservableAsPropertyHelper<int>(input,
                x => output.Add(x), -5, sched);

            // Note: Why doesn't the list match the above one? We're supposed
            // to suppress duplicate notifications, of course :)
            sched.Run();
            (new[] { 1, 2, 3, 4 }).AssertAreEqual(output);
        }
开发者ID:charles-cai,项目名称:ReactiveXaml,代码行数:14,代码来源:ObservableAsPropertyHelperTest.cs

示例8: Then1

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

            var xs = scheduler.CreateHotObservable(
                OnNext(210, 1),
                OnCompleted<int>(220)
            );

            var results = scheduler.Run(() => Observable.Join(xs.Then(a => a))).ToArray();
            results.AssertEqual(
                OnNext(210, 1),
                OnCompleted<int>(220)
            );
        }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:15,代码来源:ObservableJoinsTest.cs

示例9: GuidsShouldBeUniqueForContent

        public void GuidsShouldBeUniqueForContent(string[] setters)
        {
            PexAssume.IsNotNull(setters);
            PexAssume.AreElementsNotNull(setters);

            var sched = new TestScheduler();
            var fixture = sched.With(_ => new ModelTestFixture());
            var output = new Dictionary<string, Guid>();

            setters.ToObservable(sched).Subscribe(x => {
                fixture.TestString = x;
                output[x] = fixture.ContentHash;
            });

            sched.Run();

            PexAssert.AreDistinctValues(output.Values.ToArray());
        }
开发者ID:charles-cai,项目名称:ReactiveXaml,代码行数:18,代码来源:ModelBaseTest.cs

示例10: time_shifted_values_make_it_into_the_next_window

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

            var source = scheduler.CreateColdObservable(
                // start #1 (@0)
                // start #2 (@10) <-- happens before subscribe so its before the first value
                new Recorded<Notification<int>>(10, OnNext(1)),
                new Recorded<Notification<int>>(12, OnNext(2)),
                // end #1 (@15)
                // start #3 (@20)
                // end #2 (@25)
                // start #4 (@30)
                // end #3 (@35)
                new Recorded<Notification<int>>(40, OnNext(3)),
                // start #5 (@40)
                // end #4 (@45)
                new Recorded<Notification<int>>(50, OnNext(4)),
                // start #6 (@50)
                new Recorded<Notification<int>>(51, OnCompleted())
            );

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

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

            scheduler.Run();

            Assert.AreEqual(6, stats.NextCount);
            Assert.AreEqual(2, stats.NextValues[0].Count);
            Assert.AreEqual(2, stats.NextValues[1].Count);
            Assert.AreEqual(0, stats.NextValues[2].Count);
            Assert.AreEqual(1, stats.NextValues[3].Count);
            Assert.AreEqual(1, stats.NextValues[4].Count);
            Assert.AreEqual(0, stats.NextValues[5].Count);

            Assert.IsTrue(stats.NextValues[0].SequenceEqual(new int[] { 1, 2 }));
            Assert.IsTrue(stats.NextValues[1].SequenceEqual(new int[] { 1, 2 }));
            Assert.IsTrue(stats.NextValues[3].SequenceEqual(new int[] { 3 }));
            Assert.IsTrue(stats.NextValues[4].SequenceEqual(new int[] { 4 }));
        }
开发者ID:richardszalay,项目名称:raix,代码行数:42,代码来源:BufferWithTimeFixture.cs

示例11: ItemsChangedShouldFire

        public void ItemsChangedShouldFire(string[] setters)
        {
            PexAssume.IsNotNull(setters);
            PexAssume.AreElementsNotNull(setters);

            var sched = new TestScheduler();
            var output_changed = new List<object>();
            var output_changing = new List<object>();
            var fixture = sched.With(_ => new ModelTestFixture());

            fixture.Changing.Subscribe(output_changing.Add);
            fixture.Changed.Subscribe(output_changed.Add);

            setters.Run(x => fixture.TestString = x);

            sched.Run();

            PexAssert.AreEqual(setters.Distinct().Count(), output_changed.Count);
            PexAssert.AreEqual(setters.Distinct().Count(), output_changing.Count);
        }
开发者ID:charles-cai,项目名称:ReactiveXaml,代码行数:20,代码来源:ModelBaseTest.cs

示例12: AsyncGetTest

        public void AsyncGetTest()
        {
            var input = new[] { 1, 1, 1, 1, 1 };
            var sched = new TestScheduler();

            var delay = TimeSpan.FromSeconds(1.0);
            var fixture = new ObservableAsyncMRUCache<int, int>(x => Observable.Return(x*5).Delay(delay, sched), 5, 2);

            int result = 0;
            input.ToObservable(sched).SelectMany<int, int>(x => (IObservable<int>)fixture.AsyncGet(x)).Subscribe(x => result += x);

            sched.RunTo(sched.FromTimeSpan(TimeSpan.FromMilliseconds(500)));
            Assert.AreEqual(0, result);

            sched.RunTo(sched.FromTimeSpan(TimeSpan.FromMilliseconds(1200)));
            Assert.AreEqual(25, result);

            this.Log().Info("Running to end");
            sched.Run();
            Assert.AreEqual(25, result);
        }
开发者ID:charles-cai,项目名称:ReactiveXaml,代码行数:21,代码来源:ObservableAsyncMRUCacheTest.cs

示例13: AddingItemsShouldChangeTheContentHash

        public void AddingItemsShouldChangeTheContentHash(string[] toAdd)
        {
            PexAssume.IsNotNull(toAdd);
            PexAssume.AreElementsNotNull(toAdd);

            var sched = new TestScheduler();
            var fixture = sched.With(_ => new SerializedCollection<ModelTestFixture>());
            var hashes = new List<Guid>();
            int changeCount = 0;

            toAdd.ToObservable(sched).Subscribe(x => fixture.Add(new ModelTestFixture() {TestString = x}));
            fixture.ItemChanged.Subscribe(_ => {
                hashes.Add(fixture.ContentHash);
                changeCount++;
            });

            sched.Run();

            PexAssert.AreDistinctValues(hashes.ToArray());
            PexAssert.AreEqual(toAdd.Length, changeCount);
        }
开发者ID:charles-cai,项目名称:ReactiveXaml,代码行数:21,代码来源:SerializedCollectionTest.cs

示例14: recursively_expands_values_and_merges

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

            var observer = new MockObserver<int>(scheduler);

            scheduler.CreateColdObservable(
                OnNext(5, 0),
                OnNext(10, 1),
                OnNext(15, 2),
                OnCompleted(15)
            )
            .Expand(i => (i < 300)
                ? scheduler.CreateColdObservable(
                    OnNext(5, i + 100),
                    OnCompleted(5))
                : Observable.Empty<int>()
            )
            .Subscribe(observer);

            scheduler.Run();

            observer.AssertEqual(
                OnNext(5, 0),
                OnNext(10, 1),
                OnNext(10, 100),
                OnNext(15, 2),
                OnNext(15, 101),
                OnNext(15, 200),
                OnNext(20, 102),
                OnNext(20, 201),
                OnNext(20, 300),
                OnNext(25, 202),
                OnNext(25, 301),
                OnNext(30, 302),
                OnCompleted(30)
            );
        }
开发者ID:richardszalay,项目名称:raix,代码行数:38,代码来源:ExpandFixture.cs

示例15: InputHasADelayBetweenEachCharacterOfExaclyFiveSecondsDuringSequence

        public void InputHasADelayBetweenEachCharacterOfExaclyFiveSecondsDuringSequence()
        {
            var scheduler = new TestScheduler();
            var inputSequence = scheduler.CreateHotObservable(
                OnNextForAll(1.Seconds(), "a^helloworld$bc").TimeBetweenEach(5.Seconds()),
                OnCompleted<char>(100.Seconds())
                );

            var results = scheduler.Run(() => inputSequence.ToBarcodeReadings(scheduler),
                0.0.Seconds().Ticks,
                0.5.Seconds().Ticks,
                100.Seconds().Ticks
                );

            results.AssertEqual(EnumerableEx.Concat(
                OnNext(61.Seconds(), "helloworld"),
                OnCompleted<string>(100.Seconds())
                ));

            inputSequence.Subscriptions.AssertEqual(
                Subscribe(0.5.Seconds(), 100.Seconds())
                );
        }
开发者ID:caleb-vear,项目名称:BarcodeScannerRxSample,代码行数:23,代码来源:BarcodeReaderOperatorTests.cs


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