Пример #1
0
        public override void OnExit()
        {
            var stepStatus = _stepHelper.GetStepStatus();

            AllureLifecycle.Instance.UpdateStep(StepUuid, step => step.status = stepStatus);
            AllureLifecycle.Instance.StopStep(StepUuid);
        }
Пример #2
0
        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);
        }