/// <summary> /// The last call to evaluate the result of calls made. /// </summary> /// <typeparam name="T">Type of the value represented when in a successful state.</typeparam> /// <param name="pipe">The state so far, containing the original exception or last returned result.</param> /// <param name="writeScenarioResult">Will output the result to console unless this optional handling is supplied.</param> /// <returns>Last returned type is returned from this function in the successful case, otherwise the exception previously raised is thrown.</returns> public static BddPipeResult <T> Run <T>(this Pipe <T> pipe, Action <ScenarioResult> writeScenarioResult = null) { var result = pipe.Match( ctnValue => ctnValue.ToResult(), ctnError => ctnError.ToResult() ); var logResult = writeScenarioResult ?? WriteOutput.ApplyLast(Console.WriteLine); logResult(result); return(pipe.Match( ctnValue => new BddPipeResult <T>(ctnValue.Content, result), ctnError => { var exceptionDispatchInfo = ctnError.Content; exceptionDispatchInfo.Throw(); throw new Exception("Could not throw exception dispatch info", exceptionDispatchInfo.SourceException); })); }