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


C# TestScheduler.RunTo方法代码示例

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


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

示例1: immediate_actions_are_called_before_future_actions

        public void immediate_actions_are_called_before_future_actions()
        {
            var aWasCalled = false;
            var bWasCalled = false;
            var cWasCalled = false;
            Action actionA = () => aWasCalled = true;
            Action actionB = () => bWasCalled = true;
            Action actionC = () => cWasCalled = true;

            var scheduler = new TestScheduler();

            scheduler.Schedule(actionA, 10);

            scheduler.RunTo(10);
            Assert.IsTrue(aWasCalled);

            scheduler.Schedule(actionB, 10);
            scheduler.Schedule(actionC, 0);

            scheduler.RunTo(11);
            Assert.IsTrue(cWasCalled);
            Assert.IsFalse(bWasCalled);

            scheduler.RunTo(20);
            Assert.IsTrue(bWasCalled);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:26,代码来源:TestSchedulerFixture.cs

示例2: CacheShouldEatExceptionsAndMarshalThemToObservable

        public void CacheShouldEatExceptionsAndMarshalThemToObservable()
        {
            /* This is a bit tricky:
             *
             * 5,2 complete at t=1000 simultaneously
             * 10,0 get queued up, 0 fails immediately (delay() doesn't delay the OnError),
             *    so 10 completes at t=2000
             * The 7 completes at t=3000
             */
            var input = new[] { 5, 2, 10, 0/*boom!*/, 7 };
            var sched = new TestScheduler();

            Observable.Throw<int>(new Exception("Foo")).Subscribe(x => {
                Console.WriteLine(x);
            }, ex => {
                Console.WriteLine(ex);
            }, () => {
                Console.WriteLine("Completed");
            });

            var delay = TimeSpan.FromSeconds(1.0);
            var fixture = new ObservableAsyncMRUCache<int, int>(x =>
                (x == 0 ? Observable.Throw<int>(new Exception("Boom!")) : Observable.Return(10 * x)).Delay(delay, sched), 5, 2, sched);

            Exception exception = null;
            int completed = 0;
            input.ToObservable()
                .SelectMany(x => (IObservable<int>)fixture.AsyncGet(x))
                .Subscribe(x => {
                    this.Log().InfoFormat("Result = {0}", x);
                    completed++;
                }, ex => exception = exception ?? ex);

            sched.RunTo(sched.FromTimeSpan(TimeSpan.FromMilliseconds(500)));
            Assert.IsNull(exception);
            Assert.AreEqual(0, completed);

            sched.RunTo(sched.FromTimeSpan(TimeSpan.FromMilliseconds(1500)));
            Assert.IsNotNull(exception);
            Assert.AreEqual(2, completed);

            sched.RunTo(sched.FromTimeSpan(TimeSpan.FromMilliseconds(7500)));
            Assert.IsNotNull(exception);
            Assert.AreEqual(4, completed);
            this.Log().Info(exception);
        }
开发者ID:charles-cai,项目名称:ReactiveXaml,代码行数:46,代码来源:ObservableAsyncMRUCacheTest.cs

示例3: 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

示例4: CacheShouldQueueOnceWeHitOurConcurrentLimit

        public void CacheShouldQueueOnceWeHitOurConcurrentLimit()
        {
            var input = new[] { 1, 2, 3, 4, 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, null, sched);

            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.Equal(0, result);

            sched.RunTo(sched.FromTimeSpan(TimeSpan.FromMilliseconds(1500)));
            Assert.Equal(1*5 + 2*5 + 1*5, result);

            sched.RunTo(sched.FromTimeSpan(TimeSpan.FromMilliseconds(2500)));
            Assert.Equal(1*5 + 2*5 + 3*5 + 4*5 + 1*5, result);

            sched.RunTo(sched.FromTimeSpan(TimeSpan.FromMilliseconds(5000)));
            Assert.Equal(1*5 + 2*5 + 3*5 + 4*5 + 1*5, result);
        }
开发者ID:Lythix,项目名称:ReactiveUI,代码行数:23,代码来源:ObservableAsyncMRUCacheTest.cs

示例5: CachedValuesTest

        public void CachedValuesTest()
        {
            var input = new[] { 1, 2, 1, 3, 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), 2, 2);

            var results = input.ToObservable().SelectMany(fixture.AsyncGet).CreateCollection();
            sched.RunTo(sched.FromTimeSpan(TimeSpan.FromMilliseconds(500)));

            Assert.AreEqual(0, fixture.CachedValues().Count());

            sched.RunTo(sched.FromTimeSpan(TimeSpan.FromMilliseconds(1500)));

            var output = fixture.CachedValues().ToArray();
            Assert.IsTrue(output.Length == 2);
            Assert.AreEqual(input.Length, results.Count);
        }
开发者ID:charles-cai,项目名称:ReactiveXaml,代码行数:19,代码来源:ObservableAsyncMRUCacheTest.cs

示例6: GetTest

        public void GetTest()
        {
            var input = new[] {1, 1, 1, 1, 1};
            var sched = new TestScheduler();
            ObservableAsyncMRUCache<int, int> fixture;

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

            int result = 0;
            var t = new Thread(() => {
                foreach (int x in input.Select(x => fixture.Get(x))) {
                    result += x;
                }
            });
            t.Start();

            sched.RunTo(sched.FromTimeSpan(TimeSpan.FromMilliseconds(500)));

            Thread.Sleep(100);
            Assert.AreEqual(0, result);

            sched.RunTo(sched.FromTimeSpan(TimeSpan.FromMilliseconds(1200)));

            Thread.Sleep(100);
            Assert.AreEqual(25, result);

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

示例7: last_value_from_timeout_period_is_used

        public void last_value_from_timeout_period_is_used()
        {
            TestScheduler scheduler = new TestScheduler();

            Subject<int> subject = new Subject<int>();

            var stats = new StatsObserver<int>();

            subject.Sample(TimeSpan.FromSeconds(1), scheduler).Subscribe(stats);

            subject.OnNext(0);
            subject.OnNext(1);
            scheduler.RunTo(TimeSpan.FromMilliseconds(200).Ticks);

            subject.OnNext(2);
            subject.OnNext(3);
            scheduler.RunTo(TimeSpan.FromMilliseconds(1000).Ticks);

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

示例8: GetTest

        public void GetTest()
        {
            var input = new[] { 1, 1, 1, 1, 1 };
            var sched = new TestScheduler();
            QueuedAsyncMRUCache<int, int> fixture;

            var delay = TimeSpan.FromSeconds(1.0);
            using (TestUtils.WithTestScheduler(sched)) {
                fixture = new QueuedAsyncMRUCache<int, int>(x => Observable.Return(x*5).Delay(delay, sched).First(), 5, 2);
            }

            int result = 0;
            var t = new Task(() => {
                foreach (int i in input) {
                    this.Log().InfoFormat("Counter is {0}", result);
                    result += fixture.Get(i);
                }
            });
            t.Start();

            Thread.Sleep(200);

            this.Log().Info("Running to t=0");
            sched.RunTo(sched.FromTimeSpan(TimeSpan.FromMilliseconds(500)));
            Assert.AreEqual(0, result);
            this.Log().Info("Running to t=1200");
            sched.RunTo(sched.FromTimeSpan(TimeSpan.FromMilliseconds(1200)));

            Thread.Sleep(200);

            Assert.AreEqual(25, result);

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


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