public async Task <T> CalculateRunTime <T>(Func <Task <T> > testToRun, bool printResult, [CallerMemberName] string testName = "") { TestTimer timer = new TestTimer() { PrintResult = printResult }; T result = await testToRun(); timer.EndAndPrint(testName); return(result); }
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 static async Task RunTestIterations(Func <TestTimer, Task> testToRun, [CallerMemberName] string testName = "") { TestTimer timer = new TestTimer() { PrintResult = true }; for (int i = 0; i < TestRunner.Instance.NumberOfRuns; i++) { Console.WriteLine("Iteration Number: " + i); await testToRun(timer); } timer.Print(testName); }
public async Task ExecuteWithTimeout(TestTimer timer, int timeout, Func <Task <bool> > repeatedCode, TimeSpan?delay = null, [CallerMemberName] string testName = "") { while (true) { if (await repeatedCode()) { timer.EndAndPrint(testName); break; } if (timer.TotalMilliSecondsUntilNow >= timeout) { Assert.True(false, $"{testName} timed out after {timeout} milliseconds"); break; } if (delay.HasValue) { await Task.Delay(delay.Value); } } }
public static async Task RunTestIterations(Func <TestTimer, Task> testToRun, [CallerMemberName] string testName = "") { TestTimer timer = new TestTimer() { PrintResult = true }; for (int i = 0; i < TestRunner.Instance.NumberOfRuns; i++) { Console.WriteLine("Iteration Number: " + i); try { await testToRun(timer); } catch (Exception ex) { Console.WriteLine("Iteration Failed: " + ex.Message); } Thread.Sleep(5000); } timer.Print(testName); }