本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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)
);
}
示例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));
}
示例6: MyTestInitialize
public void MyTestInitialize()
{
_scheduler = new TestScheduler();
_source = new SourceList<Person>();
_results = _source.Connect().Buffer(TimeSpan.FromMinutes(1),_scheduler).FlattenBufferResult().AsAggregator();
}
示例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));
}
示例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));
}
示例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();
}
}
示例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();
}
示例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)));
}
示例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: 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();
}
示例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));
}
示例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)
);
}