本文整理汇总了C#中TestScheduler.CreateObserver方法的典型用法代码示例。如果您正苦于以下问题:C# TestScheduler.CreateObserver方法的具体用法?C# TestScheduler.CreateObserver怎么用?C# TestScheduler.CreateObserver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TestScheduler
的用法示例。
在下文中一共展示了TestScheduler.CreateObserver方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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));
}
示例2: 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);
}
示例3: SameAsRetry_OnCompleted
public void SameAsRetry_OnCompleted()
{
var scheduler = new TestScheduler();
var source = scheduler.CreateHotObservable<int>(
OnNext(0, 1),
OnNext(0, 2),
OnCompleted<int>(0),
OnNext(0, 3));
var called = 0;
var retryRecorder = scheduler.CreateObserver<int>();
source.Retry().Subscribe(retryRecorder);
var onErrorRecorder = scheduler.CreateObserver<int>();
source.OnErrorRetry((Exception e) => { ++called; }).Subscribe(onErrorRecorder);
scheduler.Start();
retryRecorder.Messages.Is(
OnNext(1, 1),
OnNext(1, 2),
OnCompleted<int>(1));
onErrorRecorder.Messages.Is(retryRecorder.Messages);
called.Is(0);
}
示例4: 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);
}
}
示例5: 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(AsyncSubject<int>);
var subscription = default(IDisposable);
var results1 = scheduler.CreateObserver<int>();
var subscription1 = default(IDisposable);
var results2 = scheduler.CreateObserver<int>();
var subscription2 = default(IDisposable);
var results3 = scheduler.CreateObserver<int>();
var subscription3 = default(IDisposable);
scheduler.ScheduleAbsolute(100, () => subject = new AsyncSubject<int>());
scheduler.ScheduleAbsolute(200, () => subscription = xs.Subscribe(subject));
scheduler.ScheduleAbsolute(1000, () => subscription.Dispose());
scheduler.ScheduleAbsolute(300, () => subscription1 = subject.Subscribe(results1));
scheduler.ScheduleAbsolute(400, () => subscription2 = subject.Subscribe(results2));
scheduler.ScheduleAbsolute(900, () => subscription3 = subject.Subscribe(results3));
scheduler.ScheduleAbsolute(600, () => subscription1.Dispose());
scheduler.ScheduleAbsolute(700, () => subscription2.Dispose());
scheduler.ScheduleAbsolute(800, () => subscription1.Dispose());
scheduler.ScheduleAbsolute(950, () => subscription3.Dispose());
scheduler.Start();
results1.Messages.AssertEqual(
);
results2.Messages.AssertEqual(
);
results3.Messages.AssertEqual(
);
}
示例6: When_Path_Has_Null_Intermediary_Node_Then_Propagates_ProvertyValueChanged_With_HasValue_False
public void When_Path_Has_Null_Intermediary_Node_Then_Propagates_ProvertyValueChanged_With_HasValue_False()
{
// Arrange
var childOne = new TestObservableObject {Age = 5};
var childTwo = new TestObservableObject {Age = 17};
var obj = new TestObservableObject {ObservableChild = childOne};
var scheduler = new TestScheduler();
var observer = scheduler.CreateObserver<IPropertyValueChanged<int>>();
var expected = new[]
{
OnNext(000, PropertyValueChanged.CreateWithValue(childOne, "Age", childOne.Age)),
OnNext(000, PropertyValueChanged.CreateWithValue(childOne, "Age", 20)),
OnNext(100, PropertyValueChanged.CreateWithoutValue<TestObservableObject, int>(null, "Age")),
OnNext(300, PropertyValueChanged.CreateWithValue(childTwo, "Age", childTwo.Age)),
};
var sut = obj.When(x => x.ObservableChild.Age);
// Act
sut.Subscribe(observer);
obj.ObservableChild.Age = 20;
scheduler.AdvanceTo(100);
obj.ObservableChild = null;
scheduler.AdvanceTo(300);
obj.ObservableChild = childTwo;
// Assert
Assert.AreEqual(expected, observer.Messages);
}
示例7: TestOffset
public void TestOffset()
{
var testScheduler = new TestScheduler();
var recorder = testScheduler.CreateObserver<int>();
var notifier = new ScheduledNotifier<int>(testScheduler);
notifier.Subscribe(recorder);
var origin = new DateTimeOffset(1999, 1, 1, 1, 1, 1, TimeSpan.Zero);
notifier.Report(1);
notifier.Report(2);
notifier.Report(3, origin);
notifier.Report(4, origin.AddDays(10));
notifier.Report(5, origin.AddYears(1));
notifier.Report(6);
testScheduler.Start();
recorder.Messages.Is(
OnNext(1, 1),
OnNext(1, 2),
OnNext(1, 6),
OnNext(origin.Ticks, 3),
OnNext(origin.AddDays(10).Ticks, 4),
OnNext(origin.AddYears(1).Ticks, 5));
}
示例8: Test
public void Test()
{
var testScheduler = new TestScheduler();
var recorder = testScheduler.CreateObserver<int>();
var notifier = new ScheduledNotifier<int>(testScheduler);
notifier.Subscribe(recorder);
notifier.Report(1);
notifier.Report(2);
notifier.Report(3, TimeSpan.FromMinutes(10));
notifier.Report(4, TimeSpan.FromMinutes(1));
notifier.Report(5, TimeSpan.FromMinutes(5));
notifier.Report(6);
testScheduler.Start();
recorder.Messages.Is(
OnNext(1, 1),
OnNext(1, 2),
OnNext(1, 6),
OnNext(TimeSpan.FromMinutes(1).Ticks, 4),
OnNext(TimeSpan.FromMinutes(5).Ticks, 5),
OnNext(TimeSpan.FromMinutes(10).Ticks, 3));
}
示例9: 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));
}
示例10: 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));
}
示例11: When_Subscribe_With_Two_Node_Path_To_Property_And_Modify_Node_One_Then_OnNext_Changes
public void When_Subscribe_With_Two_Node_Path_To_Property_And_Modify_Node_One_Then_OnNext_Changes()
{
// Arrange
var obj = new TestObservableObject {ObservableChild = new TestObservableObject {Age = 3}};
var replacementChild = new TestObservableObject {Age = 5};
var scheduler = new TestScheduler();
var observer = scheduler.CreateObserver<IPropertyChanged<TestObservableObject>>();
var expected = new[]
{
OnNext(000, PropertyChanged.Create(obj.ObservableChild)),
OnNext(010, PropertyChanged.Create(replacementChild)),
OnNext(010, PropertyChanged.Create(replacementChild, "Age")),
};
var sut = obj.WhenAny(x => x.ObservableChild);
// Act
sut.Subscribe(observer);
scheduler.AdvanceTo(10);
obj.ObservableChild = replacementChild;
obj.ObservableChild.Age = 17;
// Assert
Assert.AreEqual(expected, observer.Messages);
}
示例12: 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);
}
示例13: When_Path_Has_Null_Intermediary_Node_Then_Skips_When_Invalid_Path
public void When_Path_Has_Null_Intermediary_Node_Then_Skips_When_Invalid_Path()
{
// Arrange
var childOne = new TestObservableObject {Age = 5};
var childTwo = new TestObservableObject {Age = 17};
var obj = new TestObservableObject {ObservableChild = childOne};
var scheduler = new TestScheduler();
var observer = scheduler.CreateObserver<int>();
var expected = new[]
{
OnNext(000, childOne.Age),
OnNext(000, 20),
OnNext(300, childTwo.Age),
};
var sut = obj.WhenValue(x => x.ObservableChild.Age);
// Act
sut.Subscribe(observer);
obj.ObservableChild.Age = 20;
scheduler.AdvanceTo(100);
obj.ObservableChild = null;
scheduler.AdvanceTo(300);
obj.ObservableChild = childTwo;
// Assert
Assert.AreEqual(expected, observer.Messages);
}
示例14: should_be_able_do_necessary_update_while_do_on_error_async
public async Task should_be_able_do_necessary_update_while_do_on_error_async()
{
var scheduler = new TestScheduler();
var count = 0;
var raw = Observable.Defer(() =>
{
count++;
if (count == 4)
{
return Observable.Throw<int>(new Exception("Count=4"));
}
return Observable.Return(count);
}).Repeat();
var observer = scheduler.CreateObserver<int>();
using (raw.DoOnErrorAsync(async ex =>
{
await TestTask(ex);
}).Subscribe(observer))
{
await Task.Delay(5000);
Assert.AreEqual(4, observer.Messages.Count);
Assert.AreEqual(3, observer.Messages.Where(m => m.Value.Kind == System.Reactive.NotificationKind.OnNext).Count());
Assert.AreEqual(1, observer.Messages.Where(m => m.Value.Kind == System.Reactive.NotificationKind.OnError).Count());
}
}
示例15: 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);
}