• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# TestScheduler类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: Setup

 public void Setup()
 {
     _settings = A.Fake<Settings.IValues>();
     _commandEndpointFactory = A.Fake<Subject.Network.Command.Endpoint.IFactory>();
     _packetEndpointFactory = A.Fake<Subject.Network.Packet.Endpoint.IFactory>();
     _commandScheduler = new TestScheduler();
 }
开发者ID:ibebbs,项目名称:OneCog.Io.Owl.Intuition,代码行数:7,代码来源:InstanceShould.cs


示例17: Notify

        public void Notify()
        {
            var file = Path.GetTempFileName();
            File.Delete(file);

            var info = new FileInfo(file);
            var scheduler = new TestScheduler();

            FileNotification result = null;

            using (info.WatchFile(TimeSpan.FromSeconds(1), scheduler).Subscribe(x => result = x))
            {
                scheduler.AdvanceBySeconds(1);
                result.NotificationType.Should().Be(FileNotificationType.Missing);

                File.AppendAllLines(file, Enumerable.Range(1, 10).Select(i => i.ToString()));
                scheduler.AdvanceBySeconds(1);
                result.NotificationType.Should().Be(FileNotificationType.Created);
                result.NotificationType.Should().NotBe(0);

                File.AppendAllLines(file, Enumerable.Range(11, 10).Select(i => i.ToString()));
                scheduler.AdvanceBySeconds(1);
                result.NotificationType.Should().Be(FileNotificationType.Changed);

                File.Delete(file);
                scheduler.AdvanceBySeconds(1);
                result.NotificationType.Should().Be(FileNotificationType.Missing);
            }
        }
开发者ID:WELL-E,项目名称:TailBlazer,代码行数:29,代码来源:FileWatchFixture.cs


示例18: TaskToObservable_NonVoid_Complete_BeforeSubscribe

        public void TaskToObservable_NonVoid_Complete_BeforeSubscribe()
        {
            var taskScheduler = new TestTaskScheduler();
            var taskFactory = new TaskFactory(taskScheduler);
            var res = default(ITestableObserver<int>);

            taskFactory.StartNew(() =>
            {
                var scheduler = new TestScheduler();

                var taskSource = new TaskCompletionSource<int>();
                taskSource.Task.ContinueWith(t => { var e = t.Exception; });

                scheduler.ScheduleAbsolute(110, () => taskSource.SetResult(42));

                res = scheduler.Start(() =>
                    taskSource.Task.ToObservable()
                );
            });

            res.Messages.AssertEqual(
                OnNext(200, 42),
                OnCompleted<int>(200)
            );
        }
开发者ID:Ziriax,项目名称:Rx.NET,代码行数:25,代码来源:TaskObservableExtensionsTest.cs


示例19: FilterBurstsInHotObservable

        public void FilterBurstsInHotObservable()
        {
            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 res = scheduler.Start(() => xs.FilterBursts(TimeSpan.FromTicks(10),scheduler));

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

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


示例20: ReadsSegmentsCorrectly

        public void ReadsSegmentsCorrectly()
        {
            var bytes = Encoding.UTF8.GetBytes(
                "<log4j:event logger=\"ConsoleApplication1.Program\" level=\"INFO\" timestamp=\"1361281966733\" thread=\"1\">" +
                "  <log4j:message>Istcua orojurf bysgurnl t.</log4j:message>" +
                "  <log4j:properties>" +
                "    <log4j:data name=\"log4japp\" value=\"ConsoleApplication1.exe(6512)\" />" +
                "    <log4j:data name=\"log4jmachinename\" value=\"user1\" />" +
                "  </log4j:properties>" +
                "</log4j:event>" +
                "<log4j:event logger=\"ConsoleApplication1.Program\" level=\"WARN\" timestamp=\"1361281966808\" thread=\"1\">" +
                "  <log4j:message>Ebo ohow aco inldrfb pameenegy.</log4j:message>" +
                "  <log4j:properties>" +
                "    <log4j:data name=\"log4japp\" value=\"ConsoleApplication1.exe(6512)\" />" +
                "    <log4j:data name=\"log4jmachinename\" value=\"user2\" />" +
                "  </log4j:properties>" +
                "</log4j:event>");

            var stream = new MemoryStream(bytes);
            var format = new Log4JXmlLogFormat();
            var testScheduler = new TestScheduler();
            var observer = testScheduler.CreateObserver<RecordSegment>();

            var offset = format.ReadSegments(observer, stream, CancellationToken.None).Result;

            Assert.Equal(2, observer.Messages.Count);

            var segments = observer.Messages.Select(x => x.Value.Value).ToArray();

            Assert.True(segments.Any(x => x.Offset == 0 && x.Length == 342));
            Assert.True(segments.Any(x => x.Offset == 342 && x.Length == 347));
            Assert.Equal(stream.Length, offset);
        }
开发者ID:SmartFire,项目名称:LogWatch,代码行数:33,代码来源:Log4JXmlFormatTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# TestSelector类代码示例发布时间:2022-05-24
下一篇:
C# TestRunner类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap