/// <summary> /// Returns a <see cref="ICheck{T}" /> instance that will provide check methods to be executed on a lambda. /// </summary> /// <typeparam name="TU">Result type of the function.</typeparam> /// <param name="value">The code to be tested.</param> /// <returns> /// A <see cref="ICheck{RunTrace}" /> instance to use in order to assert things on the lambda. /// </returns> /// <remarks> /// Every method of the returned <see cref="ICheck{T}" /> instance will throw a <see cref="FluentCheckException" /> when failing. /// </remarks> public ICheck <RunTraceResult <TU> > ThatCode <TU>(Func <TU> value) { return(new FluentCheck <RunTraceResult <TU> >(RunTrace.GetTrace(value), this.reporter) { CustomMessage = this.message }); }
/// <summary> /// Returns a <see cref="ICheck{T}" /> instance that will provide check methods to be executed on a given value. /// </summary> /// <param name="value">The code to be tested.</param> /// <returns> /// A <see cref="ICheck{RunTrace}" /> instance to use in order to assert things on the given value. /// </returns> /// <remarks> /// Every method of the returned <see cref="ICheck{T}" /> instance will throw a <see cref="FluentCheckException" /> when failing. /// </remarks> public ICheck <RunTrace> ThatCode(Action value) { return(new FluentCheck <RunTrace>(RunTrace.GetTrace(value), this.reporter) { CustomMessage = this.message }); }
private static void CaptureAsyncTrace(Func <Task> awaitableMethod, RunTrace result) { var watch = new Stopwatch(); var cpu = Process.GetCurrentProcess().TotalProcessorTime; try { watch.Start(); // starts and waits the completion of the awaitable method awaitableMethod().Wait(); } catch (AggregateException agex) { result.RaisedException = agex.InnerException; } catch (Exception ex) { result.RaisedException = ex; } finally { watch.Stop(); result.TotalProcessorTime = Process.GetCurrentProcess().TotalProcessorTime - cpu; } // AFAIK, ObjectDisposedException should never happen here // ReSharper disable PossibleLossOfFraction result.ExecutionTime = TimeSpan.FromTicks(watch.ElapsedTicks); }
/// <summary> /// Execute the action to capture the run. /// </summary> /// <param name="action"> /// <see cref="Action"/> to be analyzed. /// </param> /// <returns> /// Return <see cref="RunTrace"/> describing the execution. /// </returns> internal static RunTrace GetTrace(Action action) { var result = new RunTrace(); CaptureTrace(action, result); return(result); }
internal static RunTrace GetAsyncTrace(Func <Task> awaitableMethod) { var result = new RunTrace(); CaptureAsyncTrace(awaitableMethod, result); return(result); }
/// <summary> /// Initializes a new instance of the <see cref="LambdaCheck" /> class. /// </summary> /// <param name="action">The action.</param> public LambdaCheck(Delegate action) { this.runTrace = CodeCheckExtensions.GetTrace(() => { try { action.DynamicInvoke(); } catch (Exception e) { throw e.InnerException; } }); }
internal static RunTrace GetAsyncTrace(Func <Task> awaitableMethod) { var result = new RunTrace(); CaptureTrace( () => { try { // starts and waits the completion of the awaitable method awaitableMethod().Wait(); } catch (AggregateException exception) { result.RaisedException = exception.InnerException; } }, result); return(result); }
private static void CaptureTrace(Action action, RunTrace result) { var watch = new Stopwatch(); var cpu = Process.GetCurrentProcess().TotalProcessorTime; watch.Start(); try { action(); } catch (Exception e) { result.RaisedException = e; } finally { watch.Stop(); result.TotalProcessorTime = Process.GetCurrentProcess().TotalProcessorTime - cpu; // ReSharper disable PossibleLossOfFraction result.ExecutionTime = TimeSpan.FromTicks(watch.ElapsedTicks); } }
/// <summary> /// Returns a <see cref="ICheck{T}" /> instance that will provide check methods to be executed on a lambda. /// </summary> /// <typeparam name="TU">Result type of the function.</typeparam> /// <param name="value">The code to be tested.</param> /// <returns> /// A <see cref="ICheck{RunTrace}" /> instance to use in order to assert things on the lambda. /// </returns> /// <remarks> /// Every method of the returned <see cref="ICheck{T}" /> instance will throw a <see cref="FluentCheckException" /> when failing. /// </remarks> public static ICheck <RunTraceResult <TU> > ThatCode <TU>(Func <TU> value) { return(new FluentCheck <RunTraceResult <TU> >(RunTrace.GetTrace(value), Reporter)); }
/// <summary> /// Returns a <see cref="ICheck{T}" /> instance that will provide check methods to be executed on a given value. /// </summary> /// <param name="value">The code to be tested.</param> /// <returns> /// A <see cref="ICheck{RunTrace}" /> instance to use in order to assert things on the given value. /// </returns> /// <remarks> /// Every method of the returned <see cref="ICheck{T}" /> instance will throw a <see cref="FluentCheckException" /> when failing. /// </remarks> public static ICheck <RunTrace> ThatCode(Action value) { return(new FluentCheck <RunTrace>(RunTrace.GetTrace(value), Reporter)); }
/// <summary> /// Initializes a new instance of the <see cref="LambdaCheck"/> class. /// </summary> /// <param name="runTrace">Trace of the initial run. /// </param> private LambdaCheck(RunTrace runTrace) { this.runTrace = runTrace; }
/// <summary> /// Returns a <see cref="ICheck{T}" /> instance that will provide check methods to be executed on a given async function (returning Task{TResult}). /// </summary> /// <typeparam name="TResult">The type of the result for this asynchronous function.</typeparam> /// <param name="awaitableFunction">The asynchronous function to be tested.</param> /// <returns> /// A <see cref="ICheck{RunTrace}" /> instance to use in order to assert things on the given value. /// </returns> /// <remarks> /// Every method of the returned <see cref="ICheck{T}" /> instance will throw a <see cref="FluentCheckException" /> when failing. /// </remarks> public static ICheck <RunTraceResult <TResult> > ThatAsyncCode <TResult>(Func <Task <TResult> > awaitableFunction) { return(new FluentCheck <RunTraceResult <TResult> >(RunTrace.GetAsyncTrace(awaitableFunction), Reporter)); }
/// <summary> /// Returns a <see cref="ICheck{T}" /> instance that will provide check methods to be executed on a given async code (returning Task). /// </summary> /// <param name="awaitableMethod">The async code to be tested.</param> /// <returns> /// A <see cref="ICheck{RunTrace}" /> instance to use in order to assert things on the given value. /// </returns> /// <remarks> /// Every method of the returned <see cref="ICheck{T}" /> instance will throw a <see cref="FluentCheckException" /> when failing. /// </remarks> public static ICheck <RunTrace> ThatAsyncCode(Func <Task> awaitableMethod) { return(new FluentCheck <RunTrace>(RunTrace.GetAsyncTrace(awaitableMethod), Reporter)); }