Esempio n. 1
0
        public Message Process(Message request)
        {
            var executeStepRequest = request.ExecuteStepRequest;

            if (!_stepRegistry.ContainsStep(executeStepRequest.ParsedStepText))
            {
                return(ExecutionError("Step Implementation not found", request));
            }

            var method = _stepRegistry.MethodFor(executeStepRequest.ParsedStepText);

            var parameters    = method.ParameterCount;
            var args          = new string[parameters];
            var stepParameter = executeStepRequest.Parameters;

            if (parameters != stepParameter.Count)
            {
                var argumentMismatchError = string.Format("Argument length mismatch for {0}. Actual Count: {1}, Expected Count: {2}",
                                                          executeStepRequest.ActualStepText,
                                                          stepParameter.Count, parameters);
                return(ExecutionError(argumentMismatchError, request));
            }

            var validTableParamTypes = new[] { Parameter.Types.ParameterType.Table, Parameter.Types.ParameterType.SpecialTable };

            for (var i = 0; i < parameters; i++)
            {
                args[i] = validTableParamTypes.Contains(stepParameter[i].ParameterType)
                    ? GetTableData(stepParameter[i].Table)
                    : stepParameter[i].Value;
            }
            var protoExecutionResult = _methodExecutor.Execute(method, args);

            return(WrapInMessage(protoExecutionResult, request));
        }
Esempio n. 2
0
 private GaugeMethod GetGaugeMethod(ProtoStepValue stepValue)
 {
     if (_stepRegistry.HasMultipleImplementations(stepValue.StepValue))
     {
         throw new Exception(string.Format("Multiple step implementations found for : {0}", stepValue.ParameterizedStepValue));
     }
     return(_stepRegistry.MethodFor(stepValue.StepValue));
 }
Esempio n. 3
0
        public IStepRegistry GetStepRegistry()
        {
            Logger.Debug("Building StepRegistry...");
            var infos = GetMethods(LibType.Step);

            Logger.Debug($"{infos.Count()} Step implementations found. Adding to registry...");
            foreach (var info in infos)
            {
                var stepTexts = info.GetCustomAttributes().Where(x => x.GetType().FullName == LibType.Step.FullName())
                                .SelectMany(x => x.GetType().GetProperty("Names").GetValue(x, null) as string[]);
                foreach (var stepText in stepTexts)
                {
                    var stepValue = GetStepValue(stepText);
                    if (_registry.ContainsStep(stepValue))
                    {
                        Logger.Debug($"'{stepValue}': implementation found in StepRegistry, setting reflected methodInfo");
                        _registry.MethodFor(stepValue).MethodInfo        = info;
                        _registry.MethodFor(stepValue).ContinueOnFailure = info.IsRecoverableStep(this);
                    }
                    else
                    {
                        Logger.Debug($"'{stepValue}': no implementation in StepRegistry, adding via reflection");
                        var hasAlias   = stepTexts.Count() > 1;
                        var stepMethod = new GaugeMethod
                        {
                            Name              = info.FullyQuallifiedName(),
                            ParameterCount    = info.GetParameters().Length,
                            StepText          = stepText,
                            HasAlias          = hasAlias,
                            Aliases           = stepTexts,
                            MethodInfo        = info,
                            ContinueOnFailure = info.IsRecoverableStep(this),
                            StepValue         = stepValue,
                            IsExternal        = true,
                        };
                        _registry.AddStep(stepValue, stepMethod);
                    }
                }
            }
            return(_registry);
        }
Esempio n. 4
0
        public IStepRegistry GetStepRegistry()
        {
            var infos = GetMethods(LibType.Step);

            foreach (var info in infos)
            {
                var stepTexts = info.GetCustomAttributes(GetLibType(LibType.Step))
                                .SelectMany(x => x.GetType().GetProperty("Names").GetValue(x, null) as string[]);
                foreach (var stepText in stepTexts)
                {
                    var stepValue = GetStepValue(stepText);
                    if (_registry.ContainsStep(stepValue))
                    {
                        _registry.MethodFor(stepValue).MethodInfo        = info;
                        _registry.MethodFor(stepValue).ContinueOnFailure = info.IsRecoverableStep(this);
                    }
                    else
                    {
                        var hasAlias   = stepTexts.Count() > 1;
                        var stepMethod = new GaugeMethod
                        {
                            Name              = info.FullyQuallifiedName(),
                            ParameterCount    = info.GetParameters().Length,
                            StepText          = stepText,
                            HasAlias          = hasAlias,
                            Aliases           = stepTexts,
                            MethodInfo        = info,
                            ContinueOnFailure = info.IsRecoverableStep(this),
                            StepValue         = stepValue,
                            IsExternal        = true,
                        };
                        _registry.AddStep(stepValue, stepMethod);
                    }
                }
            }
            return(_registry);
        }
        public Message Process(Message request)
        {
            var parsedStepText = request.StepNameRequest.StepValue;
            var isStepPresent  = _stepRegistry.ContainsStep(parsedStepText);
            var message        = new Message
            {
                MessageId        = request.MessageId,
                MessageType      = Message.Types.MessageType.StepNameResponse,
                StepNameResponse = new StepNameResponse
                {
                    IsStepPresent = isStepPresent
                }
            };

            if (!isStepPresent)
            {
                return(message);
            }

            var stepText = _stepRegistry.GetStepText(parsedStepText);
            var hasAlias = _stepRegistry.HasAlias(stepText);
            var info     = _stepRegistry.MethodFor(parsedStepText);

            message.StepNameResponse.HasAlias = hasAlias;
            message.StepNameResponse.FileName = info.FileName;
            message.StepNameResponse.Span     = new Span
            {
                Start     = info.Span.Span.Start.Line + 1,
                StartChar = info.Span.StartLinePosition.Character,
                End       = info.Span.EndLinePosition.Line + 1,
                EndChar   = info.Span.EndLinePosition.Character
            };

            if (hasAlias)
            {
                message.StepNameResponse.StepName.AddRange(info.Aliases);
            }
            else
            {
                message.StepNameResponse.StepName.Add(stepText);
            }

            return(message);
        }
Esempio n. 6
0
        public StepNameResponse Process(StepNameRequest request)
        {
            var parsedStepText = request.StepValue;
            var isStepPresent  = _stepRegistry.ContainsStep(parsedStepText);
            var response       = new StepNameResponse
            {
                IsStepPresent = isStepPresent
            };

            if (!isStepPresent)
            {
                return(response);
            }

            var stepText = _stepRegistry.GetStepText(parsedStepText);
            var hasAlias = _stepRegistry.HasAlias(stepText);
            var info     = _stepRegistry.MethodFor(parsedStepText);

            response.IsExternal = info.IsExternal;
            response.HasAlias   = hasAlias;
            if (!response.IsExternal)
            {
                response.FileName = info.FileName;
                response.Span     = new Span
                {
                    Start     = info.Span.Span.Start.Line + 1,
                    StartChar = info.Span.StartLinePosition.Character,
                    End       = info.Span.EndLinePosition.Line + 1,
                    EndChar   = info.Span.EndLinePosition.Character
                };
            }

            if (hasAlias)
            {
                response.StepName.AddRange(info.Aliases);
            }
            else
            {
                response.StepName.Add(stepText);
            }

            return(response);
        }
Esempio n. 7
0
        public Message Process(Message request)
        {
            var executeStepRequest = request.ExecuteStepRequest;

            if (!_stepRegistry.ContainsStep(executeStepRequest.ParsedStepText))
            {
                return(ExecutionError("Step Implementation not found", request));
            }

            var method = _stepRegistry.MethodFor(executeStepRequest.ParsedStepText);

            var parameters    = method.GetParameters();
            var args          = new object[parameters.Length];
            var stepParameter = executeStepRequest.ParametersList;

            if (parameters.Length != stepParameter.Count)
            {
                var argumentMismatchError = String.Format("Argument length mismatch for {0}. Actual Count: {1}, Expected Count: {2}",
                                                          executeStepRequest.ActualStepText,
                                                          stepParameter.Count, parameters.Length);
                return(ExecutionError(argumentMismatchError, request));
            }
            for (var i = 0; i < parameters.Length; i++)
            {
                var paramType = parameters[i].ParameterType;
                if (_paramConverters.ContainsKey(paramType.ToString()))
                {
                    args[i] = _paramConverters[paramType.ToString()].Convert(stepParameter[i], _sandbox);
                }
                else
                {
                    args[i] = stepParameter[i].Value;
                }
            }
            var protoExecutionResult = ExecuteMethod(method, args);

            return(WrapInMessage(protoExecutionResult, request));
        }
Esempio n. 8
0
        public ExecutionStatusResponse Process(ExecuteStepRequest request)
        {
            if (!_stepRegistry.ContainsStep(request.ParsedStepText))
            {
                return(ExecutionError("Step Implementation not found"));
            }

            var method = _stepRegistry.MethodFor(request.ParsedStepText);

            var parameters    = method.ParameterCount;
            var args          = new string[parameters];
            var stepParameter = request.Parameters;

            if (parameters != stepParameter.Count)
            {
                var argumentMismatchError = string.Format(
                    "Argument length mismatch for {0}. Actual Count: {1}, Expected Count: {2}",
                    request.ActualStepText,
                    stepParameter.Count, parameters);
                return(ExecutionError(argumentMismatchError));
            }

            var validTableParamTypes = new[]
            { Parameter.Types.ParameterType.Table, Parameter.Types.ParameterType.SpecialTable };

            for (var i = 0; i < parameters; i++)
            {
                args[i] = validTableParamTypes.Contains(stepParameter[i].ParameterType)
                    ? _tableFormatter.GetJSON(stepParameter[i].Table)
                    : stepParameter[i].Value;
            }
            var protoExecutionResult = _executionOrchestrator.ExecuteStep(method, args);

            return(new ExecutionStatusResponse {
                ExecutionResult = protoExecutionResult
            });
        }
Esempio n. 9
0
        public Message Process(Message request)
        {
            var oldStepValue = request.RefactorRequest.OldStepValue.StepValue;
            var newStep      = request.RefactorRequest.NewStepValue;

            var newStepValue       = newStep.ParameterizedStepValue;
            var parameterPositions = request.RefactorRequest.ParamPositionsList;

            var methodInfo = _stepRegistry.MethodFor(oldStepValue);

            var refactorResponseBuilder = RefactorResponse.CreateBuilder();

            try
            {
                var filesChanged = RefactorHelper.Refactor(methodInfo, parameterPositions, newStep.ParametersList, newStepValue);
                refactorResponseBuilder.SetSuccess(true).AddFilesChanged(filesChanged.First());
            }
            catch (AggregateException ex)
            {
                refactorResponseBuilder.SetSuccess(false)
                .SetError(ex.InnerExceptions.Select(exception => ex.Message).Aggregate((s, s1) => string.Concat(s, "; ", s1)));
            }
            catch (Exception ex)
            {
                refactorResponseBuilder.SetSuccess(false)
                .SetError(ex.Message);
            }

            var refactorResponse = refactorResponseBuilder.Build();

            return(Message.CreateBuilder()
                   .SetMessageId(request.MessageId)
                   .SetMessageType(Message.Types.MessageType.RefactorResponse)
                   .SetRefactorResponse(refactorResponse)
                   .Build());
        }