public void RemoveParamatersRefactoring_RemoveOnlyParam()
        {
            //Input
            const string inputCode =
@"Private Sub Foo(ByVal arg1 As Integer)
End Sub";
            var selection = new Selection(1, 23, 1, 27); //startLine, startCol, endLine, endCol

            //Expectation
            const string expectedCode =
@"Private Sub Foo()
End Sub";

            //Arrange
            SetupProject(inputCode);
            var parseResult = new RubberduckParser().Parse(_project.Object);

            var qualifiedSelection = GetQualifiedSelection(selection);

            //Specify Params to remove
            var model = new RemoveParametersModel(parseResult, qualifiedSelection);
            model.Parameters.ForEach(arg => arg.IsRemoved = true);

            //SetupFactory
            var factory = SetupFactory(model);

            //Act
            var refactoring = new RemoveParametersRefactoring(factory.Object);
            refactoring.Refactor(qualifiedSelection);

            //Assert
            Assert.AreEqual(expectedCode, _module.Object.Lines());
        }
        public void QuickFix(VBProjectParseResult parseResult, QualifiedSelection selection)
        {
            _model = new RemoveParametersModel(parseResult, selection);
            var target = _model.Declarations.FindSelection(selection, new[] { DeclarationType.Parameter });

            // ReSharper disable once PossibleUnintendedReferenceComparison
            _model.Parameters.Find(param => param.Declaration == target).IsRemoved = true;
            RemoveParameters();
        }
Example #3
0
        public RemoveParametersPresenter Create()
        {
            var selection = _vbe.ActiveCodePane.GetQualifiedSelection();

            if (!selection.HasValue)
            {
                return(null);
            }

            var model = new RemoveParametersModel(_state, selection.Value, _messageBox);

            return(new RemoveParametersPresenter(_view, model, _messageBox));
        }
Example #4
0
        public RemoveParametersPresenter Create()
        {
            var selection = _editor.GetSelection();

            if (selection == null)
            {
                return(null);
            }

            var model = new RemoveParametersModel(_parseResult, selection.Value);

            return(new RemoveParametersPresenter(_view, model));
        }
        public void Refactor()
        {
            var presenter = _factory.Create();
            if (presenter == null)
            {
                return;
            }

            _model = presenter.Show();
            if (_model == null || !_model.Parameters.Any(item => item.IsRemoved))
            {
                return;
            }

            RemoveParameters();
        }
        public void Refactor()
        {
            var presenter = _factory.Create();

            if (presenter == null)
            {
                return;
            }

            _model = presenter.Show();
            if (_model == null || !_model.Parameters.Any(item => item.IsRemoved))
            {
                return;
            }

            RemoveParameters();
        }
        public void QuickFix(QualifiedSelection selection)
        {
            _model = new RemoveParametersModel(_declarationFinderProvider, selection);

            var target = _model.Parameters.SingleOrDefault(p => selection.Selection.Contains(p.Declaration.QualifiedSelection.Selection));

            Debug.Assert(target != null, "Target was not found");

            if (target != null)
            {
                _model.RemoveParameters.Add(target);
            }
            else
            {
                return;
            }
            RemoveParameters();
        }
        public void QuickFix(RubberduckParserState state, QualifiedSelection selection)
        {
            _model = new RemoveParametersModel(state, selection, new MessageBox());

            var target = _model.Parameters.SingleOrDefault(p => selection.Selection.Contains(p.Declaration.QualifiedSelection.Selection));

            Debug.Assert(target != null, "Target was not found");

            if (target != null)
            {
                _model.RemoveParameters.Add(target);
            }
            else
            {
                return;
            }
            RemoveParameters();
        }
 public RemoveParametersPresenter(IRemoveParametersView view, RemoveParametersModel model)
 {
     _view = view;
     _model = model;
 }
        private static Mock<IRefactoringPresenterFactory<IRemoveParametersPresenter>> SetupFactory(RemoveParametersModel model)
        {
            var presenter = new Mock<IRemoveParametersPresenter>();
            presenter.Setup(p => p.Show()).Returns(model);

            var factory = new Mock<IRefactoringPresenterFactory<IRemoveParametersPresenter>>();
            factory.Setup(f => f.Create()).Returns(presenter.Object);
            return factory;
        }
        public void RemoveParamatersRefactoring_ClientReferencesAreUpdated()
        {
            //Input
            const string inputCode =
@"Private Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
End Sub

Private Sub Bar()
    Foo 10, ""Hello""
End Sub
";
            var selection = new Selection(1, 23, 1, 27); //startLine, startCol, endLine, endCol

            //Expectation
            const string expectedCode =
@"Private Sub Foo(ByVal arg1 As Integer )
End Sub

Private Sub Bar()
 Foo 10 
End Sub
"; //note: The IDE strips out the extra whitespace, you can't see it but there's a space after "Foo 10 "

            //Arrange
            SetupProject(inputCode);
            var parseResult = new RubberduckParser().Parse(_project.Object);

            var qualifiedSelection = GetQualifiedSelection(selection);

            //Specify Param(s) to remove
            var model = new RemoveParametersModel(parseResult, qualifiedSelection);
            model.Parameters[1].IsRemoved = true;

            //SetupFactory
            var factory = SetupFactory(model);

            //Act
            var refactoring = new RemoveParametersRefactoring(factory.Object);
            refactoring.Refactor(qualifiedSelection);

            //Assert
            Assert.AreEqual(expectedCode, _module.Object.Lines());
        }
 public RemoveParametersPresenter(RemoveParametersDialog view, RemoveParametersModel model, IMessageBox messageBox)
 {
     _view       = view;
     _model      = model;
     _messageBox = messageBox;
 }
Example #13
0
 public RemoveParametersPresenter(IRemoveParametersView view, RemoveParametersModel model)
 {
     _view  = view;
     _model = model;
 }
Example #14
0
 public RemoveParametersPresenter(IRefactoringDialog <RemoveParametersViewModel> view, RemoveParametersModel model, IMessageBox messageBox)
 {
     _view       = view;
     _model      = model;
     _messageBox = messageBox;
 }
 public RemoveParametersPresenter(IRemoveParametersView view, RemoveParametersModel model, IMessageBox messageBox)
 {
     _view = view;
     _model = model;
     _messageBox = messageBox;
 }