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


C# TestScheduler.CreateColdObservable方法代码示例

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


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

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

示例2: Iterate_Complete

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

            var xs = scheduler.CreateColdObservable(
                OnNext(10, 1),
                OnNext(20, 2),
                OnNext(30, 3),
                OnNext(40, 4),
                OnCompleted<int>(50)
            );

            var ys = scheduler.CreateColdObservable(
                OnNext(10, 1),
                OnNext(20, 2),
                OnCompleted<int>(30)
            );

            var zs = scheduler.CreateColdObservable(
                OnNext(10, 1),
                OnNext(20, 2),
                OnNext(30, 3),
                OnNext(40, 4),
                OnNext(50, 5),
                OnCompleted<int>(60)
            );

            var res = scheduler.Start(() => ObservableEx.Create<int>(observer => ToIterate_Complete(xs, ys, zs, observer)));

            res.Messages.AssertEqual(
                OnNext(200, 1),
                OnNext(250, 2),
                OnNext(280, 3),
                OnCompleted<int>(280)
            );

            xs.Subscriptions.AssertEqual(
                Subscribe(200, 250)
            );

            ys.Subscriptions.AssertEqual(
                Subscribe(250, 280)
            );

            zs.Subscriptions.AssertEqual(
                Subscribe(280, 280)
            );
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:48,代码来源:ObservableExTest.cs

示例3: SelectDisposableShouldWork

        public void SelectDisposableShouldWork()
        {
            var scheduler = new TestScheduler();
            var disposables = new List<BooleanDisposable>();
            var list = new CompositeDisposable();
            scheduler.CreateColdObservable(
                new Recorded<Notification<long>>(100, Notification.CreateOnNext(0L)),
                new Recorded<Notification<long>>(200, Notification.CreateOnNext(1L)),
                new Recorded<Notification<long>>(300, Notification.CreateOnNext(2L)),
                new Recorded<Notification<long>>(400, Notification.CreateOnNext(3L)),
                new Recorded<Notification<long>>(400, Notification.CreateOnCompleted<long>())
            )
            .SelectDisposable(list, i => {
                var d = new BooleanDisposable();
                disposables.Add(d);
                return d;
            }, (i, _) => i)
            .Subscribe()
            .DisposeWith(list);

            scheduler.AdvanceTo(300);

            disposables.Count.Should().Be(3);

            disposables.Select(d => d.IsDisposed).Should().NotContain(true);

            list.Dispose();

            disposables.Select(d => d.IsDisposed).Should().NotContain(false);

        }
开发者ID:Weingartner,项目名称:SolidworksAddinFramework,代码行数:31,代码来源:DisposableExtensionsSpec.cs

示例4: CreatColdObservable_ShortWay

        public void CreatColdObservable_ShortWay()
        {
            var testScheduler = new TestScheduler();
            ITestableObservable<int> coldObservable =
                testScheduler.CreateColdObservable<int>(
                    // Inheritting your test class from ReactiveTest opens the following
                    // factory methods that make your code much more fluent
                    OnNext(20, 1),
                    OnNext(40, 2),
                    OnNext(60, 2),
                    OnCompleted<int>(900)
                    );

            // Creating an observer that captures the emission it recieves
            var testableObserver = testScheduler.CreateObserver<int>();

            // Subscribing the observer, but until TestSchduler is started, emissions
            // are not be emitted
            coldObservable
                .Subscribe(testableObserver);

            // Starting the TestScheduler means that only now emissions that were configured
            // will be emitted
            testScheduler.Start();

            // Asserting that every emitted value was recieved by the observer at the
            // same time it was emitted
            coldObservable.Messages
                .AssertEqual(testableObserver.Messages);

            // Asserting that the observer was subscribed at Scheduler inital time
            coldObservable.Subscriptions.AssertEqual(
                Subscribe(0));
        }
开发者ID:tamirdresher,项目名称:RxInAction,代码行数:34,代码来源:ColdObservable.cs

示例5: values_are_buffered_in_specified_time

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

            var source = scheduler.CreateColdObservable(
                                                                // start #1 (@0)
                new Recorded<Notification<int>>(10, OnNext(1)),
                new Recorded<Notification<int>>(12, OnNext(2)),
                                                                // start #2 (@ 15)
                                                                // start #3 (@ 30)
                new Recorded<Notification<int>>(40, OnNext(3)),
                                                                // start #4 (@ 45)
                new Recorded<Notification<int>>(50, OnNext(4)),
                new Recorded<Notification<int>>(51, OnCompleted())
            );

            var stats = new StatsObserver<IList<int>>();

            source.BufferWithTime(new TimeSpan(15), scheduler)
                .Subscribe(stats);

            scheduler.Run();

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

示例6: Sut_ShouldReturnCorrectValue

		public void Sut_ShouldReturnCorrectValue(
			[Frozen]Mock<ISettingsService> settingsService,
			ConfigurationObservable sut,
			TestScheduler scheduler,
			MusicMirrorConfiguration expected)
		{
			//arrange
			settingsService.Setup(s => s.ObserveValue(ConfigurationObservable.SourcePathKey, It.IsAny<Func<string>>()))
						   .Returns(scheduler.CreateColdObservable(OnNext(0, expected.SourcePath.FullName)));
			settingsService.Setup(s => s.ObserveValue(ConfigurationObservable.TargetPathKey, It.IsAny<Func<string>>()))
						   .Returns(scheduler.CreateColdObservable(OnNext(0, expected.TargetPath.FullName)));
			//act
			var result = scheduler.Start(() => sut);
			//assert
			result.Values().First().Should().Be(expected);
		}
开发者ID:Galad,项目名称:musicmirror,代码行数:16,代码来源:ConfigurationObservableTests.cs

示例7: SameAsRetry_OnError

        public void SameAsRetry_OnError()
        {
            var scheduler = new TestScheduler();
            var ex = new Exception();
            var source = scheduler.CreateColdObservable<int>(
                OnNext(0, 1),
                OnNext(0, 2),
                OnError<int>(0, ex));

            var called = 0;
            var retryRecorder = scheduler.CreateObserver<int>();
            source.Retry().Take(5).Subscribe(retryRecorder);
            var onErrorRecorder = scheduler.CreateObserver<int>();
            source.OnErrorRetry((Exception e) => { ++called; }).Take(5).Subscribe(onErrorRecorder);

            scheduler.Start();

            retryRecorder.Messages.Is(
                OnNext(1, 1),
                OnNext(1, 2),
                OnNext(2, 1),
                OnNext(2, 2),
                OnNext(3, 1),
                OnCompleted<int>(3));

            var retryResult = retryRecorder.Messages.ToArray();

            onErrorRecorder.Messages.Is(retryRecorder.Messages);
            called.Is(2);
        }
开发者ID:ailen0ada,项目名称:ReactiveProperty,代码行数:30,代码来源:RetryObservableExtensionsTest.cs

示例8: values_can_be_triggered_by_time_or_count

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

            var source = scheduler.CreateColdObservable(
                // start #1 (@0)
                new Recorded<Notification<int>>(10, OnNext(1)),
                new Recorded<Notification<int>>(12, OnNext(2)),
                new Recorded<Notification<int>>(14, OnNext(3)),
                // start #2 (@ 15)
                new Recorded<Notification<int>>(16, OnNext(4)),
                new Recorded<Notification<int>>(20, OnNext(5)),
                new Recorded<Notification<int>>(24, OnNext(6)),
                new Recorded<Notification<int>>(28, OnNext(7)),
                // start #3 (@ 28)
                // start #4 (@ 43)
                new Recorded<Notification<int>>(50, OnNext(8)),
                new Recorded<Notification<int>>(51, OnCompleted())
            );

            var stats = new StatsObserver<IList<int>>();

            source.BufferWithTimeOrCount(new TimeSpan(15), 4, scheduler)
                .Subscribe(stats);

            scheduler.Run();

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

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

示例10: Should_Unsubscribe_From_Activator_When_All_Subscriptions_Disposed

        public void Should_Unsubscribe_From_Activator_When_All_Subscriptions_Disposed()
        {
            var scheduler = new TestScheduler();
            var activator1 = scheduler.CreateColdObservable<bool>();
            var activator2 = scheduler.CreateColdObservable<bool>();
            var activator = StyleActivator.And(new[] { activator1, activator2 });
            var target = new ActivatedValue(activator, 1, string.Empty);

            var subscription = target.Subscribe(_ => { });
            Assert.Equal(1, activator1.Subscriptions.Count);
            Assert.Equal(Subscription.Infinite, activator1.Subscriptions[0].Unsubscribe);

            subscription.Dispose();
            Assert.Equal(1, activator1.Subscriptions.Count);
            Assert.Equal(0, activator1.Subscriptions[0].Unsubscribe);
        }
开发者ID:CarlSosaDev,项目名称:Avalonia,代码行数:16,代码来源:ActivatedValueTests.cs

示例11: CreatColdObservable_LongWay

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

            ITestableObservable<int> coldObservable = testScheduler.CreateColdObservable<int>(
                // This is the long way to configure emissions. see below for a shorter one
                new Recorded<Notification<int>>(20, Notification.CreateOnNext<int>(1)),
                new Recorded<Notification<int>>(40, Notification.CreateOnNext<int>(2)),
                new Recorded<Notification<int>>(60, Notification.CreateOnCompleted<int>())
                );

            // Creating an observer that captures the emission it recieves
            var testableObserver = testScheduler.CreateObserver<int>();

            // Subscribing the observer, but until TestSchduler is started, emissions
            // are not be emitted
            coldObservable
                .Subscribe(testableObserver);

            // Starting the TestScheduler means that only now emissions that were configured
            // will be emitted
            testScheduler.Start();

            // Asserting that every emitted value was recieved by the observer at the
            // same time it was emitted
            coldObservable.Messages
                .AssertEqual(testableObserver.Messages);

            // Asserting that the observer was subscribed at Scheduler inital time
            coldObservable.Subscriptions.AssertEqual(
                Subscribe(0));
        }
开发者ID:tamirdresher,项目名称:RxInAction,代码行数:32,代码来源:ColdObservable.cs

示例12: RangeOneToThree

 private static IObservable<int> RangeOneToThree(TestScheduler scheduler)
 {
   return scheduler.CreateColdObservable(
     OnNext(100, 1),
     OnNext(100, 2),
     OnNext(100, 3),
     OnCompleted<int>(100));
 }
开发者ID:ibebbs,项目名称:Rxx,代码行数:8,代码来源:OrderByTests.cs

示例13: IntervalZeroToTwo

 private static IObservable<int> IntervalZeroToTwo(TestScheduler scheduler)
 {
   return scheduler.CreateColdObservable(
     OnNext(100, 0),
     OnNext(200, 1),
     OnNext(300, 2),
     OnCompleted<int>(300));
 }
开发者ID:ibebbs,项目名称:Rxx,代码行数:8,代码来源:OrderByTests.cs

示例14: when_user_login_fails_too_fast_then_locks_account

		public void when_user_login_fails_too_fast_then_locks_account ()
		{
			var seconds = TimeSpan.FromSeconds(1).Ticks;
			var events = new EventStream();

			// Here we use the test scheduler to simulate time passing by
			// because we have a dependency on time because of the Buffer
			// method.
			var scheduler = new TestScheduler();
			var observable = scheduler.CreateColdObservable(
				// Two users attempt to log in, 4 times in a row
				new Recorded<Notification<LoginFailure>>(10 * seconds, Notification.CreateOnNext(new LoginFailure { UserId = 1 })),
				new Recorded<Notification<LoginFailure>>(10 * seconds, Notification.CreateOnNext(new LoginFailure { UserId = 2 })),
				new Recorded<Notification<LoginFailure>>(20 * seconds, Notification.CreateOnNext(new LoginFailure { UserId = 1 })),
				new Recorded<Notification<LoginFailure>>(20 * seconds, Notification.CreateOnNext(new LoginFailure { UserId = 2 })),
				new Recorded<Notification<LoginFailure>>(30 * seconds, Notification.CreateOnNext(new LoginFailure { UserId = 1 })),
				new Recorded<Notification<LoginFailure>>(30 * seconds, Notification.CreateOnNext(new LoginFailure { UserId = 2 })),
				new Recorded<Notification<LoginFailure>>(40 * seconds, Notification.CreateOnNext(new LoginFailure { UserId = 1 })),
				new Recorded<Notification<LoginFailure>>(40 * seconds, Notification.CreateOnNext(new LoginFailure { UserId = 2 })),

				// User 2 attempts one more time within the 1' window
				new Recorded<Notification<LoginFailure>>(45 * seconds, Notification.CreateOnNext(new LoginFailure { UserId = 2 })),

				// User 1 pulls out the paper where he wrote his pwd ;), so he takes longer
				new Recorded<Notification<LoginFailure>>(75 * seconds, Notification.CreateOnNext(new LoginFailure { UserId = 1 }))
			);

			// This subscription bridges the scheduler-driven
			// observable with our event stream, causing us
			// to publish events as they are "raised" by the
			// test scheduler.
			observable.Subscribe (failure => events.Push (failure));

			var query = events.Of<LoginFailure>()
				// Sliding windows 1' long, every 10''
				.Buffer(TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(10), scheduler)
				// From all failure values
				.SelectMany(failures => failures
					// Group the failures by user
					.GroupBy(failure => failure.UserId)
					// Only grab those failures with more than 5 in the 1' window
					.Where(group => group.Count() >= 5)
					// Return the user id that failed to log in
					.Select(group => group.Key));

			var blocked = new List<int>();

			using (var subscription = query.Subscribe (userId => blocked.Add (userId))) {
				// Here we could advance the scheduler half way and test intermediate
				// state if needed. We go all the way past the end of our login failures.
				scheduler.AdvanceTo (100 * seconds);
			}

			// We should have only user # 2 in the list.
			Assert.False (blocked.Contains (1));
			Assert.True (blocked.Contains (2));
		}
开发者ID:MobileEssentials,项目名称:Merq,代码行数:57,代码来源:EventStreamSamples.cs

示例15: Activator_Should_Subscribe_To_Inputs_On_First_Subscription

        public void Activator_Should_Subscribe_To_Inputs_On_First_Subscription()
        {
            var scheduler = new TestScheduler();
            var source = scheduler.CreateColdObservable<bool>();
            var target = StyleActivator.And(new[] { source });

            Assert.Equal(0, source.Subscriptions.Count);
            target.Subscribe(_ => { });
            Assert.Equal(1, source.Subscriptions.Count);
        }
开发者ID:Arlorean,项目名称:Perspex,代码行数:10,代码来源:StyleActivatorTests.cs


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