我有一个服务类,它在其构造函数中的新线程上调度递归方法。
ISchedulerProvider
接口在其测试实现中返回TestScheduler
类的实例。
如何替换Thread.Sleep调用以使其可测试?
public class MyServiceClass
{
public MyServiceClass(ISchedulerProvider schedulerProvider, IDeviceService device)
{
MySequence = Observable.Create<ControllerSample>(o =>
{
schedulerProvider.NewThread.Schedule(
(self) =>
{
// TODO: exception handling, etc.
MyData data = device.Query();
o.OnNext(data);
// TODO: this needs to be replaced
Thread.Sleep(1000);
self();
}
}
}
public IObservable<MyData> MySequence { get; }
}