internal static TResult StepRunner <TResult>(string stepName, Delegate del, bool throwEx, Status stepStatusIfFailed, params object[] stepParams) { var stepStatus = Status.passed; Exception throwedEx = null; var stepHelper = new StepHelper(stepName); var resultFunc = default(TResult); var uuid = $"{Guid.NewGuid():N}"; var stepResult = new StepResult { name = stepName, start = ToUnixTimestamp(DateTimeOffset.Now) }; Instance.StartStep(uuid, stepResult); ReportHelper.AddStepParameters(stepParams, uuid); try { switch (del) { case Action action when resultFunc is bool: action.Invoke(); resultFunc = (TResult)(object)true; break; case Func <TResult> func: resultFunc = func.Invoke(); break; default: resultFunc = (TResult)del.DynamicInvoke(); break; } stepStatus = stepHelper.GetStepStatus(); } catch (Exception e) { bool needRethrow; (stepStatus, throwedEx, needRethrow) = stepHelper.ProceedException(e, stepStatusIfFailed); if (throwEx) { throwEx = needRethrow; } } finally { Instance.UpdateStep(step => step.status = stepStatus); Instance.StopStep(uuid); } if (throwEx && throwedEx != null) { ExceptionDispatchInfo.Capture(throwedEx).Throw(); } return(resultFunc); }
void ITestTracer.TraceError(Exception ex) { TraceError(ex); var stepText = ""; AllureLifecycle.Instance.UpdateStep(x => { stepText = x.name; }); var stepHelper = new StepHelper(stepText); stepHelper.ProceedException(ex); AllureLifecycle.Instance.StopStep(x => x.status = Status.failed); FailScenario(ex); }
public override void OnException(Exception e) { var(stepStatus, _, _) = _stepHelper.ProceedException(e); AllureLifecycle.Instance.UpdateStep(StepUuid, step => step.status = stepStatus); AllureLifecycle.Instance.StopStep(StepUuid); }