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


C# TestScheduler.AdvanceBy方法代码示例

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


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

示例1: IsActive_is_true_when_subscription_is_made_and_false_when_disposed

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

            var result = false;

            var busyLatch = new BusyLatch();

            busyLatch.IsActive
                     .ObserveOn(testScheduler)
                     .Subscribe(x => result = x);

            var subscription = busyLatch
                .Subscribe(_ => { });

            testScheduler.AdvanceBy(1);

            Assert.That(result, Is.True);

            subscription.Dispose();

            testScheduler.AdvanceBy(1);

            Assert.That(result, Is.False);
        }
开发者ID:ganesum,项目名称:Naru,代码行数:25,代码来源:BusyLatchTests.cs

示例2: ReactiveCommandAllFlow

        public void ReactiveCommandAllFlow()
        {
            var testScheduler = new TestScheduler();
            var @null = (object)null;
            var recorder1 = testScheduler.CreateObserver<object>();
            var recorder2 = testScheduler.CreateObserver<object>();

            var cmd = new ReactiveCommand();
            cmd.Subscribe(recorder1);
            cmd.Subscribe(recorder2);

            cmd.CanExecute().Is(true);
            cmd.Execute(); testScheduler.AdvanceBy(10);
            cmd.Execute(); testScheduler.AdvanceBy(10);
            cmd.Execute(); testScheduler.AdvanceBy(10);

            cmd.Dispose();
            cmd.CanExecute().Is(false);

            cmd.Dispose(); // dispose again

            recorder1.Messages.Is(
                OnNext(0, @null),
                OnNext(10, @null),
                OnNext(20, @null),
                OnCompleted<object>(30));

            recorder2.Messages.Is(
                OnNext(0, @null),
                OnNext(10, @null),
                OnNext(20, @null),
                OnCompleted<object>(30));
        }
开发者ID:wada811,项目名称:ReactiveProperty,代码行数:33,代码来源:ReactiveCommandTest.cs

示例3: when_used_with_TakeUntil_IsActive_is_true_then_false

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

            var result = false;

            var busyLatch = new BusyLatch();

            busyLatch.IsActive
                     .ObserveOn(testScheduler)
                     .Subscribe(x => result = x);

            Observable.Range(0, 1)
                      .TakeUntil(busyLatch)
                      .Subscribe(x =>
                                 {

                                 });

            testScheduler.AdvanceBy(1);

            Assert.That(result, Is.True);

            testScheduler.AdvanceBy(1);

            Assert.That(result, Is.False);
        }
开发者ID:ganesum,项目名称:Naru,代码行数:27,代码来源:BusyLatchTests.cs

示例4: TimerTestStart2

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

            var timer = new ReactiveTimer(TimeSpan.FromSeconds(1), testScheduler);
            timer.Subscribe(recorder);

            timer.Start();

            testScheduler.AdvanceTo(TimeSpan.FromSeconds(3).Ticks + 1);

            recorder.Messages.Is(
                OnNext(TimeSpan.FromSeconds(0).Ticks + 1, 0L),
                OnNext(TimeSpan.FromSeconds(1).Ticks + 1, 1L),
                OnNext(TimeSpan.FromSeconds(2).Ticks + 1, 2L),
                OnNext(TimeSpan.FromSeconds(3).Ticks + 1, 3L));
            
            timer.Stop();
            recorder.Messages.Clear();

            testScheduler.AdvanceBy(TimeSpan.FromSeconds(5).Ticks);

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

示例5: CancelTest

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

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

            var noCancel1 = notifier.Report(10, TimeSpan.FromMinutes(1));
            var cancel1 = notifier.Report(20, TimeSpan.FromMinutes(3));
            cancel1.Dispose();

            recorder.Messages.Count.Is(0);
            testScheduler.AdvanceBy(TimeSpan.FromMinutes(5).Ticks);
            recorder.Messages.Count.Is(1);
            recorder.Messages[0].Is(OnNext(TimeSpan.FromMinutes(1).Ticks, 10));

            var lastTime = recorder.Messages.Last().Time;
            recorder.Messages.Clear();

            var origin = new DateTimeOffset(1999, 1, 1, 1, 1, 1, TimeSpan.Zero);
            var noCancel2 = notifier.Report(30, origin.AddMinutes(1));
            var cancel2 = notifier.Report(40, origin.AddMinutes(3));
            cancel2.Dispose();

            testScheduler.AdvanceTo(origin.AddMinutes(5).Ticks);
            recorder.Messages.Is(
                OnNext(origin.AddMinutes(1).Ticks, 30));
        }
开发者ID:ailen0ada,项目名称:ReactiveProperty,代码行数:29,代码来源:ScheduledNotifierTest.cs

示例6: LimitSizeTo

        public void LimitSizeTo()
        {
            var subject = new Subject<Person>();
            var scheduler = new TestScheduler();
            var results = subject.ToObservableChangeSet<Person>(limitSizeTo: 100,scheduler: scheduler).AsAggregator();

            var items = Enumerable.Range(1, 200).Select(i => new Person("p" +  i.ToString("000"), i)).ToArray();
            foreach (var person in items)
            {
                subject.OnNext(person);

            }

            scheduler.AdvanceBy(100000);


            Assert.AreEqual(300, results.Messages.Count, "Should be 300 messages");
            Assert.AreEqual(200, results.Messages.Sum(x => x.Adds), "Should be 200 adds");
            Assert.AreEqual(100, results.Messages.Sum(x => x.Removes), "Should be 100 removes");
            Assert.AreEqual(100, results.Data.Count, "Should be 1 item in the cache");


            var expected = items.Skip(100).ToArray().OrderBy(p => p.Name).ToArray();
             var actual = results.Data.Items.OrderBy(p => p.Name).ToArray();
             CollectionAssert.AreEqual(expected, actual,"Only second hundred should be in the cache");
        }
开发者ID:oysteinkrog,项目名称:DynamicData,代码行数:26,代码来源:ObservableToObservableChangeSetFixture.cs

示例7: ReceiveItemsAfterAnExceptionIsEncountered

            public void ReceiveItemsAfterAnExceptionIsEncountered()
            {
                TestScheduler scheduler = new TestScheduler();
                IObservable<int> observableA = scheduler.CreateColdObservable<int>(new[] {
                    new Recorded<Notification<int>>(10, Notification.CreateOnError<int>(new InvalidOperationException()))
                });

                IObservable<int> observableB = scheduler.CreateColdObservable<int>(new[] {
                    new Recorded<Notification<int>>(10, Notification.CreateOnNext<int>(314))
                });

                Queue<IObservable<int>> observables = new Queue<IObservable<int>>(new [] { observableA, observableB });

                IObservable<int> observable = A.Fake<IObservable<int>>();
                A.CallTo(() => observable.Subscribe(A<IObserver<int>>.Ignored))
                 .Invokes(call => observables.Dequeue().Subscribe(call.GetArgument<IObserver<int>>(0)));

                IObserver<Exception> errors = A.Fake<IObserver<Exception>>();
                IObserver<int> values = A.Fake<IObserver<int>>();

                observable.Retry(errors).Subscribe(values);

                scheduler.AdvanceBy(20);

                A.CallTo(() => values.OnNext(314)).MustHaveHappened(Repeated.Exactly.Once);
            }
开发者ID:yonglehou,项目名称:OneCog.Spark.Sparkles,代码行数:26,代码来源:ObservableExtensionsTestFixture.cs

示例8: WhenAHandleToTheFileCannotBeObtainedCallFailureMethod

        public void WhenAHandleToTheFileCannotBeObtainedCallFailureMethod()
        {
            //Arrange
            var testFolder = Environment.CurrentDirectory;
            var scheduler = new TestScheduler();
            var fileHandlerMock = new Mock<IFileHandler>();
            var monitorMock = new Mock<FolderMonitor>(testFolder, fileHandlerMock.Object) { CallBase = true };

            var service = monitorMock.Object;
            service.Interval = TimeSpan.FromSeconds(1);
            service.RetryCount = 3;
            service.WatcherObservable = scheduler
                .CreateHotObservable(
                    OnNext(10, new EventPattern<FileSystemEventArgs>(
                                   null,
                                   new FileSystemEventArgs(WatcherChangeTypes.Created, testFolder, "test.file"))));
            service.RetryScheduler = scheduler;
            service.StartMonitoring();

            //Act
            scheduler.AdvanceBy(TimeSpan.FromMinutes(1).Ticks);
            
            //Assert
            fileHandlerMock.Verify(
                handler =>
                handler.ReportError(It.Is<string>(v => v == Path.Combine(testFolder, "test.file")),
                                    It.Is<Exception>(e => e is FileNotFoundException)));
        }
开发者ID:Warrenn,项目名称:Carbon.MVC,代码行数:28,代码来源:FolderMonitorUnitTest.cs

示例9: TestTargetComponent

        public void OnExecuteを動かしてみる2()
        {
            var comp = new TestTargetComponent();

            var testScheduler = new TestScheduler();
            var recorder = testScheduler.CreateObserver<ReturnCode_t>();

            comp.ExecutionContextScheduler = testScheduler;

            // コンポーネントを活性化
            comp.ActivateAsync().ToObservable().Subscribe(recorder);

            // 時間がたっていないので何も起きていない
            comp.ExecuteCounter.Is(0);
            recorder.Messages.Count.Is(0);

            // 時間を進める
            testScheduler.AdvanceBy(100);

            // 活性化に成功したことを確認
            recorder.Messages.Count.Is(2);
            recorder.Messages.First().Value.Value.Is(ReturnCode_t.RTC_OK);

            comp.ExecuteCounter.Is(0);

            // 時間を5秒進める
            testScheduler.AdvanceBy(TimeSpan.FromSeconds(5).Ticks);

            // OnExecuteは1秒に1回呼ばれる
            comp.ExecuteCounter.Is(5);
        }
开发者ID:zoetrope,项目名称:ReactiveRTM,代码行数:31,代码来源:ActivityTest.cs

示例10: TestScheduler

        public void TargetComponentの入出力チェック()
        {
            var scheduler = new TestScheduler();

            // OutPortから出力されたデータを蓄えるためのもの。
            var recorder = scheduler.CreateObserver<TimedLong>();

            // InPortにデータを入力するためのもの。1秒ごとにデータを送る。
            var publisher = scheduler.CreateHotObservable(
            OnNext(TimeSpan.FromSeconds(1).Ticks, new TimedLong() {Data = 1}),
            OnNext(TimeSpan.FromSeconds(2).Ticks, new TimedLong() {Data = 2}),
            OnNext(TimeSpan.FromSeconds(3).Ticks, new TimedLong() {Data = 3}),
            OnNext(TimeSpan.FromSeconds(4).Ticks, new TimedLong() {Data = 4}),
            OnNext(TimeSpan.FromSeconds(5).Ticks, new TimedLong() {Data = 5})
            );

            var comp = new TargetComponent();

            // コンポーネントのスケジューラをTestSchedulerに差し替える
            comp.ExecutionContextScheduler = scheduler;

            // 入出力ポートに接続
            comp.InPort.Connect(publisher);
            comp.OutPort.Connect(recorder);

            // コンポーネントを活性化
            var retRecorder = scheduler.CreateObserver<ReturnCode_t>();
            comp.ActivateAsync().ToObservable().Subscribe(retRecorder);
            scheduler.AdvanceBy(100);
            retRecorder.Messages.Count.Is(2);
            retRecorder.Messages.First().Value.Value.Is(ReturnCode_t.RTC_OK);

            // 時間を5秒進める
            scheduler.AdvanceBy(TimeSpan.FromSeconds(5).Ticks);

            // 入力データの値が2倍されて出力されていることを確認
            recorder.Messages.Count.Is(5);
            ReactiveAssert.AreElementsEqual(
            recorder.Messages.Select(x => x.Value.Value),
            new[] {
                    new TimedLong() {Data = 2},
                    new TimedLong() {Data = 4},
                    new TimedLong() {Data = 6},
                    new TimedLong() {Data = 8},
                    new TimedLong() {Data = 10}
                });
        }
开发者ID:zoetrope,项目名称:ReactiveRTM,代码行数:47,代码来源:ComponentTest.cs

示例11: TestScheduler_Usage

 public void TestScheduler_Usage()
 {
     var scheduler = new TestScheduler();
     var wasExecuted = false;
     scheduler.Schedule(() => wasExecuted = true);
     Assert.IsFalse(wasExecuted);
     scheduler.AdvanceBy(1); //execute 1 tick of queued actions
     Assert.IsTrue(wasExecuted);
 }
开发者ID:DamianReeves,项目名称:RxChangeTracker,代码行数:9,代码来源:ChangeTrackerTests.cs

示例12: delay_cancels_the_delay_if_subscription_is_disposed

        public void delay_cancels_the_delay_if_subscription_is_disposed()
        {
            var scheduler = new TestScheduler();
            var sut = new DelayServiceBuilder()
                .WithScheduler(scheduler)
                .Build();
            var executed = false;
            var delayResult = sut
                .Delay(TimeSpan.FromSeconds(5))
                .Subscribe(_ => executed = true);

            scheduler.AdvanceBy(TimeSpan.FromSeconds(1));
            Assert.False(executed);

            delayResult.Dispose();
            scheduler.AdvanceBy(TimeSpan.FromSeconds(5));
            Assert.False(executed);
        }
开发者ID:gregjones60,项目名称:WorkoutWotch,代码行数:18,代码来源:DelayServiceFixture.cs

示例13: Replay_SeveralPoints_ObservesSectionsAtCorrectIntervalThenCompletes

        public void Replay_SeveralPoints_ObservesSectionsAtCorrectIntervalThenCompletes()
        {
            bool completed = false;
            var scheduler = new TestScheduler();

            var testPoints = new[]
            {
                new GpxPoint(47.644548m, -122.326897m, 4.46m, DateTime.Parse("2009-10-17T18:37:26Z")),
                new GpxPoint(47.644548m, -122.326897m, 4.94m, DateTime.Parse("2009-10-17T18:37:31Z")),
                new GpxPoint(47.644548m, -122.326897m, 6.87m, DateTime.Parse("2009-10-17T18:37:34Z"))
            };

            var observedSections = new List<GpxSection>();

            testPoints.Replay(scheduler)
                      .Subscribe(onNext: observedSections.Add,
                                 onError: _ => Assert.Fail(),
                                 onCompleted: () => completed = true);

            scheduler.AdvanceBy(1);
            Assert.That(observedSections.Count, Is.EqualTo(1));
            Assert.That(observedSections[0].Start, Is.SameAs(testPoints[0]));
            Assert.That(observedSections[0].End, Is.SameAs(testPoints[1]));
            Assert.That(completed, Is.False);

            // Nothing for the time between the first two points
            scheduler.AdvanceBy(TimeSpan.TicksPerSecond * 4);
            Assert.That(observedSections.Count, Is.EqualTo(1));
            Assert.That(completed, Is.False);

            scheduler.AdvanceBy(TimeSpan.TicksPerSecond);
            Assert.That(observedSections.Count, Is.EqualTo(2));
            Assert.That(observedSections[1].Start, Is.SameAs(testPoints[1]));
            Assert.That(observedSections[1].End, Is.SameAs(testPoints[2]));
            Assert.That(completed, Is.False);

            // Waits for the time between the last two points before completing
            scheduler.AdvanceBy(TimeSpan.TicksPerSecond * 2);
            Assert.That(observedSections.Count, Is.EqualTo(2));
            Assert.That(completed, Is.False);

            scheduler.AdvanceBy(TimeSpan.TicksPerSecond);
            Assert.That(completed, Is.True);
        }
开发者ID:modulexcite,项目名称:TurboTrainer,代码行数:44,代码来源:GpxReplayTests.cs

示例14: Clock

 public void Clock()
 {
     var scheduler = new TestScheduler ();
     Assert.AreEqual (0, scheduler.Clock, "#1"); // default
     scheduler.AdvanceBy (TimeSpan.FromDays (1).Ticks);
     Assert.AreEqual (TimeSpan.FromDays (1).Ticks, scheduler.Clock, "#2");
     var dt = new DateTimeOffset (2012, 1, 1, 0, 0, 0, TimeSpan.Zero);
     scheduler.AdvanceTo (dt.Ticks);
     Assert.AreEqual (dt, new DateTimeOffset (scheduler.Clock, TimeSpan.Zero), "#3");
 }
开发者ID:jorik041,项目名称:mono-reactive,代码行数:10,代码来源:TestSchedulerTest.cs

示例15: elections_are_ran_shortly_after_node_startup

        public void elections_are_ran_shortly_after_node_startup()
        {
            var testScheduler = new TestScheduler();
            testScheduler.AdvanceTo(DateTimeOffset.UtcNow.Ticks);
            var nodes = TestNode.CreateCluster(scheduler: testScheduler);
            nodes.Start();

            testScheduler.AdvanceBy(TestNode.ElectionTimeout.Ticks);
            nodes.Should().ContainSingle(n => n.State == State.Leader || n.State == State.Candidate);
        }
开发者ID:jonsequitur,项目名称:JollyRaft,代码行数:10,代码来源:ElectionTests.cs


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