本文整理汇总了C#中TestScheduler.CreateHotObservable方法的典型用法代码示例。如果您正苦于以下问题:C# TestScheduler.CreateHotObservable方法的具体用法?C# TestScheduler.CreateHotObservable怎么用?C# TestScheduler.CreateHotObservable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TestScheduler
的用法示例。
在下文中一共展示了TestScheduler.CreateHotObservable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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)));
}
示例2: 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));
}
示例3: Bug_1283
public void Bug_1283()
{
var scheduler = new TestScheduler();
var xs = scheduler.CreateHotObservable(
OnNext(100, 1),
OnNext(220, 2),
OnNext(240, 3),
OnNext(300, 4),
OnNext(310, 5),
OnCompleted<int>(350)
);
var results = scheduler.Start(() =>
xs.Window(TimeSpan.FromTicks(100), scheduler).Select((x, i) => x.Select(y => i.ToString() + " " + y.ToString()).Concat(Observable.Return(i.ToString() + " end", scheduler))).Merge()
);
results.Messages.AssertEqual(
OnNext(220, "0 2"),
OnNext(240, "0 3"),
OnNext(300, "0 4"),
OnNext(301, "0 end"),
OnNext(310, "1 5"),
OnNext(351, "1 end"),
OnCompleted<string>(351)
);
}
示例4: 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);
}
示例5: InputHasADelayBetweenCharactersOfLongerThanFiveSecondsDuringSequence
public void InputHasADelayBetweenCharactersOfLongerThanFiveSecondsDuringSequence()
{
var scheduler = new TestScheduler();
var inputSequence = scheduler.CreateHotObservable(
OnNextForAll(1.0.Seconds(), "a^hello"),
OnNextForAll(6.1.Seconds(), "world$"),
OnNextForAll(7.0.Seconds(), "^Rx$"),
OnCompleted<char>(7.5.Seconds())
);
var results = scheduler.Run(() => inputSequence.ToBarcodeReadings(scheduler),
0.0.Seconds().Ticks,
0.5.Seconds().Ticks,
10.Seconds().Ticks
);
results.AssertEqual(EnumerableEx.Concat(
OnNext(7.Seconds(), "Rx"),
OnCompleted<string>(7.5.Seconds())
));
inputSequence.Subscriptions.AssertEqual(
Subscribe(0.5.Seconds(), 7.5.Seconds())
);
}
示例6: Bug_1261
public void Bug_1261()
{
var scheduler = new TestScheduler();
var xs = scheduler.CreateHotObservable(
OnNext(205, 1),
OnNext(210, 2),
OnNext(215, 3),
OnNext(220, 4),
OnNext(225, 5),
OnNext(230, 6),
OnCompleted<int>(230));
var results = scheduler.Start(() =>
xs.Window(TimeSpan.FromTicks(10), scheduler).Select((x, i) => x.Select(y => i.ToString() + " " + y.ToString()).Concat(Observable.Return(i.ToString() + " end", scheduler))).Merge()
);
results.Messages.AssertEqual(
OnNext(205, "0 1"),
OnNext(210, "0 2"),
OnNext(211, "0 end"),
OnNext(215, "1 3"),
OnNext(220, "1 4"),
OnNext(221, "1 end"),
OnNext(225, "2 5"),
OnNext(230, "2 6"),
OnNext(231, "2 end"),
OnCompleted<string>(231)
);
}
示例7: FilterBursts_TwoBurstAndGapInEachBurst_FirstInEachBurstEmitted
public void FilterBursts_TwoBurstAndGapInEachBurst_FirstInEachBurstEmitted()
{
var scheduler = new TestScheduler();
var xs = scheduler.CreateHotObservable(
OnNext(250, 1),
OnNext(260, 2),
OnNext(270, 3),
OnNext(400, -1),
OnNext(401, -2),
OnNext(405, -3),
OnCompleted<int>(500)
);
var res = scheduler.Start(() => xs.FilterBursts(3));
res.Messages.AssertEqual(
OnNext(250, 1),
OnNext(400, -1),
OnCompleted<int>(500));
xs.Subscriptions.AssertEqual(
Subscribe(Subscribed, 500));
}
示例8: Await
public void Await()
{
var scheduler = new TestScheduler();
var xs = scheduler.CreateHotObservable(
OnNext(20, -1),
OnNext(150, 0),
OnNext(220, 1),
OnNext(290, 2),
OnNext(340, 3),
OnCompleted<int>(410)
);
var awaiter = default(AsyncSubject<int>);
var result = default(int);
var t = long.MaxValue;
scheduler.ScheduleAbsolute(100, () => awaiter = xs.GetAwaiter());
scheduler.ScheduleAbsolute(200, () => awaiter.OnCompleted(() => { t = scheduler.Clock; result = awaiter.GetResult(); }));
scheduler.Start();
Assert.AreEqual(410, t);
Assert.AreEqual(3, result);
xs.Subscriptions.AssertEqual(
Subscribe(100)
);
}
示例9: 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));
}
示例10: 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)
);
}
示例11: Test_Where_Error
public void Test_Where_Error()
{
var exception = new Exception();
var scheduler = new TestScheduler();
var obs = scheduler.CreateHotObservable<string>(
OnNext(150, "Erik"),
OnNext(210, "Bart"),
OnNext(220, "Matthew"),
OnError<string>(230, exception)
);
var res = scheduler.Start(() =>
{
return obs.Where(x => x.Length > 4);
});
res.Messages.AssertEqual(
OnNext(220, "Matthew"),
OnError<string>(230, exception)
);
obs.Subscriptions.AssertEqual(
Subscribe(200, 230)
);
}
示例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)
);
}
示例13: 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(
);
}
示例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(AsyncSubject<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 AsyncSubject<int>(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(
);
results3.AssertEqual(
);
}
示例15: CombineLatest
public void CombineLatest()
{
var scheduler = new TestScheduler();
var first = scheduler.CreateHotObservable(
OnNext(10, 'a'),
OnNext(20, 'b'),
OnNext(40, 'c'),
OnCompleted<char>(70));
var second = scheduler.CreateHotObservable(
OnNext(30, 'd'),
OnNext(60, 'e'),
OnNext(100, 'f'),
OnCompleted<char>(110));
var third = scheduler.CreateHotObservable(
OnNext(50, 'g'),
OnNext(80, 'h'),
OnCompleted<char>(90));
var input = scheduler.CreateColdObservable(
OnNext(0, first),
OnNext(25, second),
OnNext(45, third),
OnCompleted<ITestableObservable<char>>(55));
var result = scheduler.Start(() => input.CombineLatest(), 0, 0, 200).Messages;
result.AssertEqual(
OnNext<IList<char>>(10, new[] { 'a' }.SequenceEqual),
OnNext<IList<char>>(20, new[] { 'b' }.SequenceEqual),
OnNext<IList<char>>(30, new[] { 'b', 'd' }.SequenceEqual),
OnNext<IList<char>>(40, new[] { 'c', 'd' }.SequenceEqual),
OnNext<IList<char>>(50, new[] { 'c', 'd', 'g' }.SequenceEqual),
OnNext<IList<char>>(60, new[] { 'c', 'e', 'g' }.SequenceEqual),
OnNext<IList<char>>(80, new[] { 'c', 'e', 'h' }.SequenceEqual),
OnNext<IList<char>>(100, new[] { 'c', 'f', 'h' }.SequenceEqual),
OnCompleted<IList<char>>(110));
}