using System; using System.Diagnostics; namespace Ocelot.UnitTests { public class Wait { public static Waiter WaitFor(int milliSeconds) { return new Waiter(milliSeconds); } } public class Waiter { private readonly int _milliSeconds; public Waiter(int milliSeconds) { _milliSeconds = milliSeconds; } public bool Until(Func condition) { var stopwatch = Stopwatch.StartNew(); var passed = false; while (stopwatch.ElapsedMilliseconds < _milliSeconds) { if (condition.Invoke()) { passed = true; break; } } return passed; } public bool Until(Func condition) { var stopwatch = Stopwatch.StartNew(); var passed = false; while (stopwatch.ElapsedMilliseconds < _milliSeconds) { if (condition.Invoke()) { passed = true; break; } } return passed; } } }