public void ShouldRefactorAttributeText() { var sandbox = SandboxFactory.Create(AppDomain.CurrentDomain.SetupInformation); var methodInfo = sandbox.GetStepMethods().First(info => info.Name == "RefactoringContext"); RefactorHelper.Refactor(methodInfo, new List <ParameterPosition>(), new List <string>(), "foo"); AssertStepAttributeWithTextExists(methodInfo.Name, "foo"); }
public void ShouldRefactorAndReturnFilesChanged() { var sandbox = SandboxFactory.Create(AppDomain.CurrentDomain.SetupInformation); var methodInfo = sandbox.GetStepMethods().First(info => info.Name == "RefactoringContext"); var expectedPath = Path.GetFullPath(Path.Combine(_testProjectPath, "RefactoringSample.cs")); var filesChanged = RefactorHelper.Refactor(methodInfo, new List <ParameterPosition>(), new List <string>(), "foo").ToList(); Assert.AreEqual(1, filesChanged.Count); Assert.AreEqual(expectedPath, filesChanged.First()); }
public void ShouldRefactorAttributeText() { var gaugeMethod = new GaugeMethod { Name = "RefactoringContext", ClassName = "RefactoringSample", FileName = Path.Combine(_testProjectPath, "RefactoringSample.cs") }; var changes = RefactorHelper.Refactor(gaugeMethod, new List <Tuple <int, int> >(), new List <string>(), "foo"); AssertStepAttributeWithTextExists(changes, gaugeMethod.Name, "foo"); }
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" }); }
public Message Process(Message request) { var newStep = request.RefactorRequest.NewStepValue; var newStepValue = newStep.ParameterizedStepValue; var parameterPositions = request.RefactorRequest.ParamPositions .Select(position => new Tuple <int, int>(position.OldPosition, position.NewPosition)).ToList(); var response = new RefactorResponse(); try { var gaugeMethod = GetGaugeMethod(request.RefactorRequest.OldStepValue); if (gaugeMethod.HasAlias) { throw new Exception("Steps with aliases can not be refactored."); } var fileChanges = RefactorHelper.Refactor(gaugeMethod, parameterPositions, newStep.Parameters.ToList(), newStepValue); if (request.RefactorRequest.SaveChanges) { File.WriteAllText(fileChanges.FileName, fileChanges.FileContent); } response.Success = true; response.FilesChanged.Add(gaugeMethod.FileName); response.FileChanges.Add(ConvertToProtoFileChanges(fileChanges)); } catch (AggregateException ex) { response.Success = false; response.Error = ex.InnerExceptions.Select(exception => exception.Message).Distinct() .Aggregate((s, s1) => string.Concat(s, "; ", s1)); } catch (Exception ex) { response.Success = false; response.Error = ex.Message; } return(new Message { MessageId = request.MessageId, MessageType = Message.Types.MessageType.RefactorResponse, RefactorResponse = response }); }
public void ShouldRemoveParameters() { var gaugeMethod = new GaugeMethod { Name = "RefactoringSaySomething", ClassName = "RefactoringSample", FileName = Path.Combine(_testProjectPath, "RefactoringSample.cs") }; var parameterPositions = new[] { new Tuple <int, int>(0, 0) }; var changes = RefactorHelper.Refactor(gaugeMethod, parameterPositions, new List <string>(), "Refactoring Say <what> to someone"); AssertParametersExist(changes, gaugeMethod.Name, new[] { "what" }); }
public void ShouldRefactorAndReturnFilesChanged() { var gaugeMethod = new GaugeMethod { Name = "RefactoringContext", ClassName = "RefactoringSample", FileName = Path.Combine(_testProjectPath, "RefactoringSample.cs") }; var expectedPath = Path.GetFullPath(Path.Combine(_testProjectPath, "RefactoringSample.cs")); var changes = RefactorHelper.Refactor(gaugeMethod, new List <Tuple <int, int> >(), new List <string>(), "foo"); Assert.AreEqual(expectedPath, changes.FileName); }
public void ShouldRemoveParametersInAnyOrder() { var gaugeMethod = new GaugeMethod { Name = "RefactoringSaySomething", ClassName = "RefactoringSample", FileName = Path.Combine(_testProjectPath, "RefactoringSample.cs") }; var parameterPositions = new[] { new Tuple <int, int>(1, 0) }; RefactorHelper.Refactor(gaugeMethod, parameterPositions, new List <string>(), "Refactoring Say something to <who>"); AssertParametersExist(gaugeMethod.Name, new[] { "who" }); }
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" }); }
public void ShouldAddParametersWhenNoneExisted() { const string newStepValue = "Refactoring this is a test step <foo>"; var gaugeMethod = new GaugeMethod { Name = "RefactoringSampleTest", ClassName = "RefactoringSample", FileName = Path.Combine(_testProjectPath, "RefactoringSample.cs") }; var parameterPositions = new[] { new Tuple <int, int>(-1, 0) }; RefactorHelper.Refactor(gaugeMethod, parameterPositions, new List <string> { "foo" }, newStepValue); AssertStepAttributeWithTextExists(gaugeMethod.Name, newStepValue); AssertParametersExist(gaugeMethod.Name, new[] { "foo" }); }
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 void ShouldAddParametersWithReservedKeywordName() { const string newStepValue = "Refactoring this is a test step <class>"; var gaugeMethod = new GaugeMethod { Name = "RefactoringSampleTest", ClassName = "RefactoringSample", FileName = Path.Combine(_testProjectPath, "RefactoringSample.cs") }; var parameterPositions = new[] { new Tuple <int, int>(-1, 0) }; var changes = RefactorHelper.Refactor(gaugeMethod, parameterPositions, new List <string> { "class" }, newStepValue); AssertStepAttributeWithTextExists(changes, gaugeMethod.Name, newStepValue); AssertParametersExist(changes, gaugeMethod.Name, new[] { "@class" }); }
public void ShouldReorderParameters() { const string newStepValue = "Refactoring Say <who> to <what>"; var gaugeMethod = new GaugeMethod { Name = "RefactoringSaySomething", ClassName = "RefactoringSample", FileName = Path.Combine(_testProjectPath, "RefactoringSample.cs") }; var parameterPositions = new[] { new Tuple <int, int>(0, 1), new Tuple <int, int>(1, 0) }; RefactorHelper.Refactor(gaugeMethod, parameterPositions, new List <string> { "who", "what" }, newStepValue); AssertStepAttributeWithTextExists(gaugeMethod.Name, newStepValue); AssertParametersExist(gaugeMethod.Name, new[] { "who", "what" }); }
public Message Process(Message request) { var newStep = request.RefactorRequest.NewStepValue; var newStepValue = newStep.ParameterizedStepValue; var parameterPositions = request.RefactorRequest.ParamPositions .Select(position => new Tuple <int, int>(position.OldPosition, position.NewPosition)).ToList(); var response = new RefactorResponse(); try { var gaugeMethod = GetGaugeMethod(request.RefactorRequest.OldStepValue); var changedFile = RefactorHelper.Refactor(gaugeMethod, parameterPositions, newStep.Parameters.ToList(), newStepValue); response.Success = true; response.FilesChanged.Add(changedFile); } catch (AggregateException ex) { response.Success = false; response.Error = ex.InnerExceptions.Select(exception => exception.Message).Distinct() .Aggregate((s, s1) => string.Concat(s, "; ", s1)); } catch (Exception ex) { response.Success = false; response.Error = ex.Message; } return(new Message { MessageId = request.MessageId, MessageType = Message.Types.MessageType.RefactorResponse, RefactorResponse = response }); }
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()); }