public async Task ShouldNotThrowIfNotCancelled( [Target] DefaultRequestWorker worker, CancellationToken cancellationToken ) { Func <Task> func = () => worker.StartAsync(cancellationToken); await func.Should().NotThrowAsync <OperationCanceledException>(); }
public async Task ShouldThrowIfCancelled( [Target] DefaultRequestWorker worker ) { var cancellationToken = new CancellationToken(true); Func <Task> func = () => worker.StartAsync(cancellationToken); await func.Should().ThrowAsync <OperationCanceledException>(); }
public async Task ShouldCreateAndStartANewTimer( [Frozen] RequestOptions options, [Frozen] ITimer timer, [Frozen] ITimerFactory timerFactory, [Target] DefaultRequestWorker worker, CancellationToken cancellationToken ) { await worker.StartAsync(cancellationToken); timerFactory.Received().CreateTimer(Is <AsyncTimerCallback>(worker.Run), Is(options.PollingInterval), Is(nameof(DefaultRequestWorker))); await timer.Received().Start(); }
public async Task ShouldStopTheTimer( [Frozen] RequestOptions options, [Frozen] ITimer timer, [Frozen] ITimerFactory timerFactory, [Target] DefaultRequestWorker worker, CancellationToken cancellationToken ) { await worker.StartAsync(cancellationToken); await worker.StopAsync(cancellationToken); await timer.Received().Stop(); }