0

I can assert that a task should complete within a specified maximum time like this:

await obj.Awaiting( o => o.DoSomethingAsync() ).Should().CompleteWithinAsync( 1.Second() );

But how can I also require that the task also takes at least a certain amount of time to complete? For example, I want to assert that the task should take between 1 and 2 seconds to complete, such that taking less than 1 second or more than 2 seconds indicates failure?

I'm aware of NotCompleteWithinAsync, but I can't work out how to combine both CompleteWithinAsync and NotCompleteWithinAsync in one assertion.

tg73
  • 415
  • 3
  • 10

1 Answers1

0

You could use the ExecutionTime extension method and combine it with BeCloseTo. Something like

Awaiting(() => DoSomethingAsync()).ExecutionTime().Should().BeCloseTo(1.Minutes(), 5.Seconds());



Dennis Doomen
  • 8,368
  • 1
  • 32
  • 44