/// <inheritdoc /> public IConversion AddParameter(string parameter, ParameterPosition parameterPosition = ParameterPosition.PostInput) { _parameters.Add(new ConversionParameter { Parameter = $"{parameter.Trim()} ", Position = parameterPosition }); return(this); }
private string AcquireParameter(IReadOnlyList <string> commandArgs, ParameterPosition position, string defaultValue = null) { var index = (int)position; var result = index < commandArgs.Count ? commandArgs[index] : null; while (string.IsNullOrWhiteSpace(result)) { result = PromptParameter(position, defaultValue); } return(result); }
public IConversion AddSmartParameter(string parameter, ParameterPosition parameterPosition = ParameterPosition.PostInput, bool skip = true) { if (!skip) { _parameters.Add(new ConversionParameter { Parameter = $"{parameter.Trim()} ", Position = parameterPosition }); } return(this); }
public void ShouldRemoveParametersInAnyOrder() { var sandbox = SandboxFactory.Create(AppDomain.CurrentDomain.SetupInformation); var methodInfo = sandbox.GetStepMethods().First(info => info.Name == "RefactoringSaySomething"); var parameterPosition = ParameterPosition.CreateBuilder().SetNewPosition(0).SetOldPosition(1).Build(); RefactorHelper.Refactor(methodInfo, new List <ParameterPosition> { parameterPosition }, new List <string>(), "Refactoring Say something to <who>"); AssertParametersExist(methodInfo.Name, new[] { "who" }); }
/// <summary> /// Create parameters string /// </summary> /// <param name="forPosition">Position for parameters</param> /// <returns>Parameters</returns> private string BuildParameters(ParameterPosition forPosition) { IEnumerable <ConversionParameter> parameters = _parameters?.Where(x => x.Position == forPosition); if (parameters != null && parameters.Any()) { return(string.Join(string.Empty, parameters.Select(x => x.Parameter))); } else { return(string.Empty); } }
public void ShouldAddParametersWithReservedKeywordName() { const string newStepValue = "Refactoring this is a test step <class>"; var sandbox = SandboxFactory.Create(AppDomain.CurrentDomain.SetupInformation); var methodInfo = sandbox.GetStepMethods().First(info => info.Name == "RefactoringSampleTest"); var parameterPositions = new List <ParameterPosition> { ParameterPosition.CreateBuilder().SetNewPosition(0).SetOldPosition(-1).Build() }; RefactorHelper.Refactor(methodInfo, parameterPositions, new List <string> { "class" }, newStepValue); AssertStepAttributeWithTextExists(methodInfo.Name, newStepValue); AssertParametersExist(methodInfo.Name, new[] { "@class" }); }
private string PromptParameter(ParameterPosition position, string defaultValue = null) { // Since we have to prompt a parameter from user we are in the interactive mode now InteractiveMode = true; _console.Write(_parameterPrompts[position]); if (!string.IsNullOrWhiteSpace(defaultValue)) { _console.Write($" or ENTER to accept default ({defaultValue})"); } _console.Write(":"); var result = _console.ReadLine(); return(string.IsNullOrEmpty(result) ? defaultValue : result); }
public void ShouldReorderParameters() { const string newStepValue = "Refactoring Say <who> to <what>"; var sandbox = SandboxFactory.Create(AppDomain.CurrentDomain.SetupInformation); var methodInfo = sandbox.GetStepMethods().First(info => info.Name == "RefactoringSaySomething"); var parameterPosition = ParameterPosition.CreateBuilder().SetNewPosition(1).SetOldPosition(0).Build(); var parameterPosition1 = ParameterPosition.CreateBuilder().SetNewPosition(0).SetOldPosition(1).Build(); var parameterPositions = new List <ParameterPosition> { parameterPosition, parameterPosition1 }; RefactorHelper.Refactor(methodInfo, parameterPositions, new List <string> { "who", "what" }, newStepValue); AssertStepAttributeWithTextExists(methodInfo.Name, newStepValue); AssertParametersExist(methodInfo.Name, new[] { "who", "what" }); }
public Parameter(string name, Documentation documentation, VariableType type, ParameterPosition position, bool required) : base(name, documentation) { this.Type = type; this.Position = position; this.Required = required; }
/// <inheritdoc /> public IConversion AddParameter(string parameter, ParameterPosition parameterPosition = ParameterPosition.PostInput) { _userDefinedParameters[parameterPosition].Add(parameter); return(this); }
/// <inheritdoc /> public IVideoStream AddParameter(string parameter, ParameterPosition parameterPosition = ParameterPosition.PostInput) { _parameters.Add(new ConversionParameter(parameter, parameterPosition)); return(this); }
public ConversionParameter(string parameter, ParameterPosition position = ParameterPosition.PostInput) { Parameter = $"{parameter.Trim()} "; Key = parameter.Split(' ').First(); Position = position; }