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


C# TestScheduler类代码示例

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


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

示例1: TestInitialFalse

        public void TestInitialFalse()
        {
            var notifier = new BooleanNotifier(false);
            var recorder = new TestScheduler().CreateObserver<bool>();
            notifier.Subscribe(recorder);

            notifier.Value.Is(false);

            notifier.TurnOn();
            notifier.TurnOff();
            notifier.Value = true;
            notifier.Value = true;
            notifier.Value = false;
            notifier.TurnOn();
            notifier.SwitchValue();
            notifier.SwitchValue();

            recorder.Messages.Is(
                OnNext(0, true),
                OnNext(0, false),
                OnNext(0, true),
                OnNext(0, true),
                OnNext(0, false),
                OnNext(0, true),
                OnNext(0, false),
                OnNext(0, true));

            recorder.Messages.Clear();

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

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

示例3: AsyncCommandSmokeTest

        public void AsyncCommandSmokeTest()
        {
            var sched = new TestScheduler();
            IObservable<int> async_data;
            ReactiveAsyncCommand fixture;

            using (TestUtils.WithTestScheduler(sched)) {
                fixture = new ReactiveAsyncCommand(null, 1);
                async_data = fixture
                    .Delay(TimeSpan.FromSeconds(5), RxApp.TaskpoolScheduler)
                    .Select(_ => 5)
                    .Do(_ => fixture.AsyncCompletedNotification.OnNext(new Unit()));
            }

            var inflight_results = new List<int>();
            fixture.ItemsInflight.Subscribe(inflight_results.Add);

            var output = new List<int>();
            async_data.Subscribe(output.Add);

            Assert.IsTrue(fixture.CanExecute(null));

            fixture.Execute(null);

            sched.RunToMilliseconds(1005);
            Assert.IsFalse(fixture.CanExecute(null));

            sched.RunToMilliseconds(5005);
            Assert.IsTrue(fixture.CanExecute(null));

            new[] {0,1,0}.AssertAreEqual(inflight_results);
            new[] {5}.AssertAreEqual(output);
        }
开发者ID:charles-cai,项目名称:ReactiveXaml,代码行数:33,代码来源:ReactiveCommandTest.cs

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

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

示例6: MyTestInitialize

        public void MyTestInitialize()
        {
            _scheduler = new TestScheduler();
            _source = new SourceList<Person>();
            _results = _source.Connect().Buffer(TimeSpan.FromMinutes(1),_scheduler).FlattenBufferResult().AsAggregator();

        }
开发者ID:oysteinkrog,项目名称:DynamicData,代码行数:7,代码来源:BufferFixture.cs

示例7: FilterBurstsWithATestObserver

        public void FilterBurstsWithATestObserver()
        {
            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 testObserver = scheduler.CreateObserver<int>();
            scheduler.AdvanceTo(200);
            xs.FilterBursts(TimeSpan.FromTicks(10), scheduler)
                .Subscribe(testObserver);

            scheduler.Start();

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

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

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

示例9: TestSchedulerService

        public TestSchedulerService(bool singleUnderlyingScheduler = true)
        {
            this.hasSingleUnderlyingScheduler = singleUnderlyingScheduler;
            this.defaultScheduler = new TestScheduler();

            if (singleUnderlyingScheduler)
            {
                this.currentThreadScheduler =
                    this.immediateScheduler =
                    this.mainScheduler =
                    this.eventLoopScheduler =
                    this.newThreadScheduler =
                    this.taskPoolScheduler =
                    this.defaultScheduler;
            }
            else
            {
                this.currentThreadScheduler = new TestScheduler();
                this.immediateScheduler = new TestScheduler();
                this.mainScheduler = new TestScheduler();
                this.eventLoopScheduler = new TestScheduler();
                this.newThreadScheduler = new TestScheduler();
                this.taskPoolScheduler = new TestScheduler();
            }
        }
开发者ID:reactiveui-forks,项目名称:WorkoutWotch,代码行数:25,代码来源:TestSchedulerService.cs

示例10: WhenAHandleToTheFileCanBeObtainedCallSucessMethod

        public void WhenAHandleToTheFileCanBeObtainedCallSucessMethod()
        {
            //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);
            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(1);
            service.RetryCount = 3;
            service.WatcherObservable = scheduler
                .CreateHotObservable(
                    OnNext(10, 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,代码行数:35,代码来源:FolderMonitorUnitTest.cs

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

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

示例13: ScheduleTask_Should_Call_Sample_On_Scheduler

        public void ScheduleTask_Should_Call_Sample_On_Scheduler()
        {
            // Arrange
            const int count = 5;

            var scheduler = new TestScheduler();
            var settings = new TaskSchedulerSettings
            {
                RequestDelay = TimeSpan.FromMilliseconds(250)

            };
            ITaskScheduler taskScheduler = new DelayTaskScheduler(settings, scheduler);

            // Act
            var tasks = Enumerable.Range(0, count + 1)
                                  .Select(i => Task.Run(() => Task.FromResult(i)))
                                  .Select(t => taskScheduler.ScheduleTask(() => t))
                                  .ToArray();

            scheduler.AdvanceTo(settings.RequestDelay.Ticks * count);

            // Assert
            tasks.Count(t => t.IsCompleted).Should().Be(count);
            taskScheduler.Dispose();
        }
开发者ID:abatishchev,项目名称:ab,代码行数:25,代码来源:DelayTaskSchedulerTest.cs

示例14: TimeSource101

        public void TimeSource101()
        {
            TestScheduler scheduler = new TestScheduler();
            var xs = scheduler.CreateHotObservable(s_testData);

            var timeSource = new TimeSource<long>(xs, x => new DateTimeOffset(x, TimeSpan.Zero));
            timeSource.StartTime = new DateTimeOffset(101, TimeSpan.Zero);

            var counts = from window in timeSource.Window(TimeSpan.FromTicks(5), timeSource.Scheduler)
                         from Count in window.Count()
                         select Count;

            var list = new List<Timestamped<int>>();
            counts
                .Timestamp(timeSource.Scheduler)
                .Subscribe(ts => list.Add(ts));

            timeSource.Connect();
            scheduler.AdvanceTo(120);

            Assert.AreEqual(3, list.Count);
            list.AssertEqual(
                Result(106, 2),
                Result(111, 3),
                Result(115, 1));
        }
开发者ID:theperm,项目名称:RxM4A,代码行数:26,代码来源:TimeSourceTest.cs

示例15: asd

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

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

            Observable.Range(0, 3, Scheduler.Immediate)
                .Expand(i => (i < 300) ? Observable.Return(i + 100) : Observable.Empty<int>())
                .Subscribe(observer);

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


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