/// <summary>
        /// Execute
        /// </summary>
        /// <param name="actionSetting"></param>
        /// <param name="argument"></param>
        /// <returns></returns>
        public async Task <ActionExecuteResult> Execute(string actionSetting, ArgumentProvider argument)
        {
            var setting      = JsonConvert.DeserializeObject <UnitTestActionSetting>(actionSetting);
            var key          = setting.Key;
            var currentCount = 0;

            if (executionCounts.ContainsKey(key))
            {
                currentCount = executionCounts[key] + 1;
            }
            executionCounts[key] = currentCount;
            bool result = true;

            if (setting?.ResultSequence?.Any() != true)
            {
                result = true;
            }
            if (setting.ResultSequence.Count < currentCount)
            {
                result = true;
            }
            else
            {
                result = setting.ResultSequence[currentCount];
            }
            var res = new ActionExecuteResult
            {
                Output = new Dictionary <string, string> {
                    { "result", $"{result}" }
                },
                Data = $"{result}"
            };

            if (result || setting.DirectFail)
            {
                res.Success = result;
                res.Fail    = !result;
            }

            return(res);
        }
Пример #2
0
        /// <summary>
        /// execute call
        /// </summary>
        /// <param name="argument"></param>
        /// <returns></returns>
        public async Task <ActionExecuteResult> Execute(ArgumentProvider argument)
        {
            try
            {
                if (Settings == null)
                {
                    return(new ActionExecuteResult {
                        Success = false
                    });
                }

                var result = await CallHttp(argument);

                if (result?.Success != true)
                {
                    return(new ActionExecuteResult {
                        Success = result?.Success ?? false, Message = result?.Message, Data = result?.Message
                    });
                }

                var resultBody = result.Data;
                if (!string.IsNullOrEmpty(resultBody))
                {
                    argument.PutPrivate("result", resultBody);
                }
                ActionExecuteResult actionExecuteResult = new ActionExecuteResult {
                    Data = resultBody
                };
                if (Settings.ResultIndicators?.Any() == true)
                {
                    foreach (var indicator in Settings.ResultIndicators)
                    {
                        var res = indicator.Indicate(argument);
                        if (res == null)
                        {
                            continue;
                        }
                        if (res == true)
                        {
                            actionExecuteResult.Success = true;
                            break;
                        }
                        else
                        {
                            actionExecuteResult.Fail = true;
                            break;
                        }
                    }
                }
                else
                {
                    actionExecuteResult.Success = true;
                    actionExecuteResult.Fail    = false;
                }

                return(actionExecuteResult);
            }
            catch (Exception ex)
            {
                return(new ActionExecuteResult {
                    Success = false, Message = ex.Message
                });
            }
        }