Inheritance: IRubberduckParser
        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());
        }
Beispiel #2
0
        public void Initialize(VBE vbe)
        {
            if (_parser != null)
            {
                throw new InvalidOperationException("ParserState is already initialized.");
            }

            _parser = new RubberduckParser(vbe, _state, _attributeParser);
        }
        public void TodoPresenter_RefreshUpdatesViewItems()
        {
            var code = @"
Public Sub Bazzer()
    'Todo: Fix the foobarred bazzer.
End Sub";

            var codeModule = RdMockFacotry.CreateCodeModuleMock(code);

            var component = RdMockFacotry.CreateComponentMock("Module1", codeModule.Object, vbext_ComponentType.vbext_ct_StdModule);

            var project = RdMockFacotry.CreateProjectMock("VBAProject", vbext_ProjectProtection.vbext_pp_none);
            
            var componentList = new List<VBComponent>() { component.Object };
            var components = RdMockFacotry.CreateComponentsMock(componentList, project.Object);

            component.SetupGet(c => c.Collection).Returns(components.Object);

            var projectList = new List<VBProject>() {project.Object};

            var projects = RdMockFacotry.CreateProjectsMock(projectList);
            project.SetupGet(p => p.VBComponents).Returns(components.Object);

            _vbe = RdMockFacotry.CreateVbeMock(_windows, projects.Object);

            _view.SetupProperty(v => v.TodoItems);

            var parser = new RubberduckParser();

            var presenter = new ToDoExplorerDockablePresenter(parser, _markers, _vbe.Object, _addin.Object, _view.Object, _gridViewSorter);
          
            //act
            presenter.Refresh();

            //assert
            Assert.AreEqual("Todo: Fix the foobarred bazzer.", _view.Object.TodoItems.First().Description);
        }
        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());
        }