public async Task <T> CalculateRunTime <T>(Func <Task <T> > testToRun, TestTimer timer = null)
        {
            if (timer != null)
            {
                timer.Start();
            }
            T result = await testToRun();

            if (timer != null)
            {
                timer.End();
            }

            return(result);
        }
 public async Task ExecuteWithTimeout(TestTimer timer, int timeout, Func <Task <bool> > repeatedCode,
                                      TimeSpan?delay = null, [CallerMemberName] string testName = "")
 {
     timer.Start();
     while (true)
     {
         if (await repeatedCode())
         {
             timer.End();
             break;
         }
         if (timer.TotalMilliSecondsUntilNow >= timeout)
         {
             Assert.True(false, $"{testName} timed out after {timeout} milliseconds");
             break;
         }
         if (delay.HasValue)
         {
             await Task.Delay(delay.Value);
         }
     }
 }