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)); }
public Message Process(Message request) { var stepToValidate = request.StepValidateRequest.StepText; var isValid = _stepMethodTable.ContainsStep(stepToValidate); var errorMessage = isValid ? string.Empty : string.Format("No implementation found for : {0}. Full Step Text :", stepToValidate); return(GetStepValidateResponseMessage(isValid, request, StepValidateResponse.Types.ErrorType.STEP_IMPLEMENTATION_NOT_FOUND, errorMessage)); }
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); }
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); }
public Message Process(Message request) { var parsedStepText = request.StepNameRequest.StepValue; var isValidStep = _stepRegistry.ContainsStep(parsedStepText); var stepText = _stepRegistry.GetStepText(parsedStepText); var hasAlias = _stepRegistry.HasAlias(stepText); var stepNameResponse = StepNameResponse.CreateBuilder() .SetHasAlias(hasAlias) .SetIsStepPresent(isValidStep) .AddStepName(stepText) .Build(); return(Message.CreateBuilder() .SetMessageId(request.MessageId) .SetMessageType(Message.Types.MessageType.StepNameResponse) .SetStepNameResponse(stepNameResponse) .Build()); }
public Message Process(Message request) { var stepToValidate = request.StepValidateRequest.StepText; var isValid = true; var errorMessage = ""; var errorType = StepValidateResponse.Types.ErrorType.StepImplementationNotFound; if (!_stepMethodTable.ContainsStep(stepToValidate)) { isValid = false; errorMessage = string.Format("No implementation found for : {0}. Full Step Text :", stepToValidate); } else if (_stepMethodTable.HasMultipleImplementations(stepToValidate)) { isValid = false; errorType = StepValidateResponse.Types.ErrorType.DuplicateStepImplementation; errorMessage = string.Format("Multiple step implementations found for : {0}", stepToValidate); } return(GetStepValidateResponseMessage(isValid, request, errorType, errorMessage)); }
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); }
public Message Process(Message request) { var parsedStepText = request.StepNameRequest.StepValue; var isValidStep = _stepRegistry.ContainsStep(parsedStepText); var stepText = _stepRegistry.GetStepText(parsedStepText); var hasAlias = _stepRegistry.HasAlias(stepText); var stepNameResponse = new StepNameResponse() { HasAlias = hasAlias, IsStepPresent = isValidStep, StepName = { stepText }, }; return(new Message() { MessageId = request.MessageId, MessageType = Message.Types.MessageType.StepNameResponse, StepNameResponse = stepNameResponse, }); }
public StepValidateResponse Process(StepValidateRequest request) { var stepToValidate = request.StepText; var isValid = true; var errorMessage = ""; var suggestion = ""; var errorType = StepValidateResponse.Types.ErrorType.StepImplementationNotFound; if (!_stepRegistry.ContainsStep(stepToValidate)) { isValid = false; errorMessage = string.Format("No implementation found for : {0}. Full Step Text :", stepToValidate); suggestion = GetSuggestion(request.StepValue); } else if (_stepRegistry.HasMultipleImplementations(stepToValidate)) { isValid = false; errorType = StepValidateResponse.Types.ErrorType.DuplicateStepImplementation; errorMessage = string.Format("Multiple step implementations found for : {0}", stepToValidate); } return(GetStepValidateResponseMessage(isValid, errorType, errorMessage, suggestion)); }
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)); }
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 }); }
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); }