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


C# TestScheduler.Schedule方法代码示例

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


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

示例3: Initialize

 public void Initialize()
 {
     _scheduler = new TestScheduler();
     // Any time after 1/1/1970 will do for startDate. CouchIds go wrong before that date as they are microseconds since 1/1/1970.
     _startDate = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc);
     // Dispose of the generator after 10 minutes. (res disposes of its subscription to generator, but generator itself also has to be disposed of otherwise the test never terminates.)
     _scheduler.Schedule(new DateTimeOffset(_startDate.AddMinutes(10)), () => _generator.Dispose());
 }
开发者ID:NorthNick,项目名称:hydra,代码行数:8,代码来源:ObservableGeneratorTest.cs

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

示例5: TwoStockTicksWithSmallChangeAndOneWithDrasticChange_OnlyOneDrasticChangeEmitted

        public void TwoStockTicksWithSmallChangeAndOneWithDrasticChange_OnlyOneDrasticChangeEmitted()
        {
            var testScheduler = new TestScheduler();
            var testableObserver = testScheduler.CreateObserver<DrasticChange>();
            var stockTicker = Substitute.For<IStockTicker>();
            var rxStockMonitor = new StockMonitor(stockTicker);

            testScheduler.Schedule(TimeSpan.FromTicks(1), () => { stockTicker.StockTick += Raise.Event<EventHandler<StockTick>>(stockTicker,new StockTick{Price=100,QuoteSymbol="MSFT"}); });
            testScheduler.Schedule(TimeSpan.FromTicks(2), () => { stockTicker.StockTick += Raise.Event<EventHandler<StockTick>>(stockTicker, new StockTick{Price=101,QuoteSymbol="MSFT"}); });
            testScheduler.Schedule(TimeSpan.FromTicks(3), () => { stockTicker.StockTick += Raise.Event<EventHandler<StockTick>>(stockTicker, new StockTick{Price=200,QuoteSymbol="MSFT"}); });

            rxStockMonitor.DrasticChanges.Subscribe(testableObserver);

            testScheduler.Start();

            testableObserver.Messages.AssertEqual(
                OnNext(3,(DrasticChange drasticChange)=>drasticChange.Symbol=="MSFT")
                );
        }
开发者ID:tamirdresher,项目名称:RxInAction,代码行数:19,代码来源:StockMonitorTests.cs

示例6: SendNotification_1EventAfter0SecondThen1After3Minutes_Expect1NotificationSentAfter5Minutes

        public void SendNotification_1EventAfter0SecondThen1After3Minutes_Expect1NotificationSentAfter5Minutes()
        {
            //Arrange
            var eventEmitter = new MvvmLightMessenger();

            var robot = Substitute.For<IRobot>();
            robot.EventEmitter.Returns(eventEmitter);

            var scheduler = new TestScheduler();
            var jiraAggregator = new JiraAggregatorSut(robot, scheduler);

            var user = new User { displayName = "Laurent Kempé", name = "laurent" };

            var addCommentEvent1 = new JiraModel
            {
                issue = new Issue { key = "LK-10", fields = new Fields { reporter = user, assignee = user } },
                webhookEvent = "jira:issue_created",
                comment = new CommentDetails(),
                user = user
            };

            var addCommentEvent2 = new JiraModel
            {
                issue = new Issue { key = "LK-10", fields = new Fields { reporter = user, assignee = user } },
                webhookEvent = "jira:issue_updated",
                comment = new CommentDetails(),
                user = user
            };

            //Act
            scheduler.Schedule(TimeSpan.FromSeconds(0), () => eventEmitter.Emit("JiraEvent", addCommentEvent1));
            scheduler.Schedule(TimeSpan.FromSeconds(120), () => eventEmitter.Emit("JiraEvent", addCommentEvent2));

            scheduler.AdvanceTo(TimeSpan.FromSeconds(181).Ticks);
            robot.Received(0).SendNotification("", "", "Message", true);

            scheduler.AdvanceTo(TimeSpan.FromMinutes(5).Ticks);

            //Assert
            robot.Received(1).SendNotification(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(), true);
        }
开发者ID:martinskuta,项目名称:Nubot,代码行数:41,代码来源:JiraAggregatorTests.cs

示例7: TestHotObservable

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

            var xs = scheduler.CreateHotObservable (
                scheduler.OnNextAt(100, "a"), // only works in Visual Studio
                scheduler.OnNextAt(200, "b"),
                scheduler.OnCompletedAt<string>(300)
            );

            var observer = scheduler.CreateObserver<string>();
            scheduler.Schedule(TimeSpan.FromTicks(220),
                (sched, state) => xs.Subscribe(observer));

            scheduler.Start();

            observer.Messages.AssertEqual (
                new Recorded<Notification<string>>(250, Notification.CreateOnCompleted<string>())
            );
        }
开发者ID:benoitjadinon,项目名称:RxTests,代码行数:20,代码来源:ViewModelTest.cs

示例8: AddRangeIncreasesCountTest

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

            using (var observableList = new ObservableList<int>())
            {
                // when
                observableList.ThresholdAmountWhenChangesAreNotifiedAsReset = rangeToAdd.Count + 1;
                observableList.CountChanges.Subscribe(testObserver);

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

                // then
                observableList.Count.Should().Be(rangeToAdd.Count);
            }
        }
开发者ID:jbattermann,项目名称:JB.Common,代码行数:20,代码来源:ObservableListAddMultipleItemsTests.cs

示例9: Create_Dispose

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

            var res = scheduler.Start(() =>
                Observable.Create<int>(o =>
                {
                    var stopped = false;

                    o.OnNext(1);
                    o.OnNext(2);
                    scheduler.Schedule(TimeSpan.FromTicks(600), () =>
                    {
                        if (!stopped)
                            o.OnNext(3);
                    });
                    scheduler.Schedule(TimeSpan.FromTicks(700), () =>
                    {
                        if (!stopped)
                            o.OnNext(4);
                    });
                    scheduler.Schedule(TimeSpan.FromTicks(900), () =>
                    {
                        if (!stopped)
                            o.OnNext(5);
                    });
                    scheduler.Schedule(TimeSpan.FromTicks(1100), () =>
                    {
                        if (!stopped)
                            o.OnNext(6);
                    });

                    return () => { stopped = true; };
                })
            );

            res.Messages.AssertEqual(
                OnNext(200, 1),
                OnNext(200, 2),
                OnNext(800, 3),
                OnNext(900, 4)
            );
        }
开发者ID:Balharmander123,项目名称:Rx.NET,代码行数:43,代码来源:ObservableCreationTest.cs

示例10: CreateWithDisposable_Dispose

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

            var res = scheduler.Start(() =>
                Observable.Create<int>(o =>
                {
                    var d = new BooleanDisposable();

                    o.OnNext(1);
                    o.OnNext(2);
                    scheduler.Schedule(TimeSpan.FromTicks(600), () =>
                    {
                        if (!d.IsDisposed)
                            o.OnNext(3);
                    });
                    scheduler.Schedule(TimeSpan.FromTicks(700), () =>
                    {
                        if (!d.IsDisposed)
                            o.OnNext(4);
                    });
                    scheduler.Schedule(TimeSpan.FromTicks(900), () =>
                    {
                        if (!d.IsDisposed)
                            o.OnNext(5);
                    });
                    scheduler.Schedule(TimeSpan.FromTicks(1100), () =>
                    {
                        if (!d.IsDisposed)
                            o.OnNext(6);
                    });

                    return d;
                })
            );

            res.Messages.AssertEqual(
                OnNext(200, 1),
                OnNext(200, 2),
                OnNext(800, 3),
                OnNext(900, 4)
            );
        }
开发者ID:Balharmander123,项目名称:Rx.NET,代码行数:43,代码来源:ObservableCreationTest.cs

示例11: KeepLoopingUntilHandleCanBeObtained

        public void KeepLoopingUntilHandleCanBeObtained()
        {
            //Arrange
            var scheduler = new TestScheduler();
            var filePath = Path.GetTempFileName();
            var testFolder = Path.GetDirectoryName(filePath);
            var fileHandlerMock = new Mock<IFileHandler>();
            var monitorMock = new Mock<FolderMonitor>(testFolder, fileHandlerMock.Object) { CallBase = true };
            var testFile = Path.GetFileName(filePath);
            Stream lockStream = File.Open(filePath, FileMode.Open);
            scheduler.Schedule(TimeSpan.FromSeconds(35), lockStream.Dispose);
            fileHandlerMock
                .Setup(handler => handler.ProcessFile(It.Is<string>(v => v == filePath), It.IsAny<Stream>()))
                .Callback((string path, Stream s) =>
                    {
                        s.Dispose();
                        File.Delete(path);
                    })
                .Verifiable();

            var service = monitorMock.Object;
            service.Interval = TimeSpan.FromSeconds(20);
            service.RetryCount = 5;
            service.WatcherObservable = scheduler
                .CreateHotObservable(
                    OnNext(30,
                           new EventPattern<FileSystemEventArgs>(null,
                                                                 new FileSystemEventArgs(
                                                                     WatcherChangeTypes.Created, testFolder,
                                                                     testFile)))
                );
            service.RetryScheduler = scheduler;
            service.StartMonitoring();

            //Act           
            scheduler.AdvanceBy(TimeSpan.FromMinutes(1).Ticks);
            
            //Assert
            fileHandlerMock.VerifyAll();
        }
开发者ID:Warrenn,项目名称:Carbon.MVC,代码行数:40,代码来源:FolderMonitorUnitTest.cs

示例12: AddRangeNotifiesCountAfterResetWhenItemCountAboveThresholdTest

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

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

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

                // then
                testObserver.Messages.Count.Should().Be(1);
                testObserver.Messages.Last().Should().NotBeNull();
                testObserver.Messages.Last().Value.Value.Should().Be(observableList.Count);
            }
        }
开发者ID:jbattermann,项目名称:JB.Common,代码行数:22,代码来源:ObservableListAddMultipleItemsTests.cs

示例13: MvvmLightMessenger

        public void SendNotification_5SuccessfulSameBuildEventSentInTimeThenMaxDurationTimePassed_ExpectOnly1SuccessNotificationSentWithCorrectMessage()
        {
            //Arrange
            var eventEmitter = new MvvmLightMessenger();

            var robot = Substitute.For<IRobot>();
            robot.EventEmitter.Returns(eventEmitter);

            var scheduler = new TestScheduler();
            var teamCityAggregator = new TeamCityAggregatorSut(robot, scheduler);

            var successful1TeamCityBuildModel = new TeamCityModel { build = new Build { buildNumber = "10", buildResult = "success" } };

            //Act
            scheduler.Schedule(TimeSpan.FromMinutes(0), () => eventEmitter.Emit("TeamCityBuild", successful1TeamCityBuildModel));
            scheduler.Schedule(TimeSpan.FromMinutes(2), () => eventEmitter.Emit("TeamCityBuild", successful1TeamCityBuildModel));
            scheduler.Schedule(TimeSpan.FromMinutes(4), () => eventEmitter.Emit("TeamCityBuild", successful1TeamCityBuildModel));
            scheduler.Schedule(TimeSpan.FromMinutes(5), () => eventEmitter.Emit("TeamCityBuild", successful1TeamCityBuildModel));
            scheduler.Schedule(TimeSpan.FromMinutes(5.5), () => eventEmitter.Emit("TeamCityBuild", successful1TeamCityBuildModel));

            scheduler.AdvanceBy(TimeSpan.FromMinutes(15).Ticks);

            //Assert
            robot.Received(1).SendNotification(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(), false);
        }
开发者ID:martinskuta,项目名称:Nubot,代码行数:25,代码来源:TeamCityAggregatorTests.cs

示例14: Infinite

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

            var xs = scheduler.CreateHotObservable(
                OnNext(70, 1),
                OnNext(110, 2),
                OnNext(220, 3),
                OnNext(270, 4),
                OnNext(340, 5),
                OnNext(410, 6),
                OnNext(520, 7),
                OnNext(630, 8),
                OnNext(710, 9),
                OnNext(870, 10),
                OnNext(940, 11),
                OnNext(1020, 12)
                );

            var subject = default(ReplaySubject<int>);
            var subscription = default(IDisposable);

            var results1 = new MockObserver<int>(scheduler);
            var subscription1 = default(IDisposable);

            var results2 = new MockObserver<int>(scheduler);
            var subscription2 = default(IDisposable);

            var results3 = new MockObserver<int>(scheduler);
            var subscription3 = default(IDisposable);

            scheduler.Schedule(() => subject = new ReplaySubject<int>(3, TimeSpan.FromTicks(100), scheduler), 100);
            scheduler.Schedule(() => subscription = xs.Subscribe(subject), 200);
            scheduler.Schedule(() => subscription.Dispose(), 1000);

            scheduler.Schedule(() => subscription1 = subject.Subscribe(results1), 300);
            scheduler.Schedule(() => subscription2 = subject.Subscribe(results2), 400);
            scheduler.Schedule(() => subscription3 = subject.Subscribe(results3), 900);

            scheduler.Schedule(() => subscription1.Dispose(), 600);
            scheduler.Schedule(() => subscription2.Dispose(), 700);
            scheduler.Schedule(() => subscription1.Dispose(), 800);
            scheduler.Schedule(() => subscription3.Dispose(), 950);

            scheduler.Run();

            results1.AssertEqual(
                OnNext(301, 3),
                OnNext(302, 4),
                OnNext(340, 5),
                OnNext(410, 6),
                OnNext(520, 7)
                );

            results2.AssertEqual(
                OnNext(401, 5),
                OnNext(410, 6),
                OnNext(520, 7),
                OnNext(630, 8)
                );

            results3.AssertEqual(
                OnNext(901, 10),
                OnNext(940, 11)
                );
        }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:66,代码来源:ReplaySubjectTest.cs

示例15: Canceled

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

            var xs = scheduler.CreateHotObservable(
                OnCompleted<int>(630),
                OnNext(640, 9),
                OnCompleted<int>(650),
                OnError<int>(660, new MockException(1))
                );

            var subject = default(ReplaySubject<int>);
            var subscription = default(IDisposable);

            var results1 = new MockObserver<int>(scheduler);
            var subscription1 = default(IDisposable);

            var results2 = new MockObserver<int>(scheduler);
            var subscription2 = default(IDisposable);

            var results3 = new MockObserver<int>(scheduler);
            var subscription3 = default(IDisposable);

            scheduler.Schedule(() => subject = new ReplaySubject<int>(3, TimeSpan.FromTicks(100), scheduler), 100);
            scheduler.Schedule(() => subscription = xs.Subscribe(subject), 200);
            scheduler.Schedule(() => subscription.Dispose(), 1000);

            scheduler.Schedule(() => subscription1 = subject.Subscribe(results1), 300);
            scheduler.Schedule(() => subscription2 = subject.Subscribe(results2), 400);
            scheduler.Schedule(() => subscription3 = subject.Subscribe(results3), 900);

            scheduler.Schedule(() => subscription1.Dispose(), 600);
            scheduler.Schedule(() => subscription2.Dispose(), 700);
            scheduler.Schedule(() => subscription1.Dispose(), 800);
            scheduler.Schedule(() => subscription3.Dispose(), 950);

            scheduler.Run();

            results1.AssertEqual(
                );

            results2.AssertEqual(
                OnCompleted<int>(630)
                );

            results3.AssertEqual(
                );
        }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:48,代码来源:ReplaySubjectTest.cs


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