This class stores trace information for a code evaluation.
コード例 #1
0
 /// <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
     });
 }
コード例 #2
0
 /// <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
     });
 }
コード例 #3
0
        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);
        }
コード例 #4
0
        /// <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);
        }
コード例 #5
0
        internal static RunTrace GetAsyncTrace(Func <Task> awaitableMethod)
        {
            var result = new RunTrace();

            CaptureAsyncTrace(awaitableMethod, result);
            return(result);
        }
コード例 #6
0
 /// <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;
         }
     });
 }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
            }
        }
コード例 #9
0
 /// <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));
 }
コード例 #10
0
 /// <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));
 }
コード例 #11
0
 /// <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;
 }
コード例 #12
0
 /// <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));
 }
コード例 #13
0
 /// <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));
 }