public void IntroduceParameterRefactoring_Properties_GetAndSet() { //Input const string inputCode = @"Property Get Foo(ByVal fizz As Boolean) As Variant Dim bar As Integer Foo = fizz End Property Property Set Foo(ByVal fizz As Boolean, ByVal buzz As Variant) End Property"; var selection = new Selection(2, 10, 2, 13); //Expectation const string expectedCode = @"Property Get Foo(ByVal fizz As Boolean, ByVal bar As Integer) As Variant Foo = fizz End Property Property Set Foo(ByVal fizz As Boolean, ByVal bar As Integer, ByVal buzz As Variant) End Property"; IVBComponent component; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out component, selection); var state = MockParser.CreateAndParse(vbe.Object); var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection); var refactoring = new IntroduceParameterRefactoring(vbe.Object, state, null); refactoring.Refactor(qualifiedSelection); Assert.AreEqual(expectedCode, component.CodeModule.Content()); }
public void IntroduceParameterRefactoring_DisplaysInvalidSelectionAndDoesNothingForInvalidSelection() { //Input const string inputCode = @"Private fizz As Boolean Private Sub Foo() End Sub"; var selection = new Selection(3, 16, 3, 16); IVBComponent component; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out component, selection); var state = MockParser.CreateAndParse(vbe.Object); var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection); var messageBox = new Mock <IMessageBox>(); messageBox.Setup(m => m.Show(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <MessageBoxButtons>(), It.IsAny <MessageBoxIcon>())).Returns(DialogResult.OK); var refactoring = new IntroduceParameterRefactoring(vbe.Object, state, messageBox.Object); refactoring.Refactor(qualifiedSelection); messageBox.Verify(m => m.Show(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <MessageBoxButtons>(), It.IsAny <MessageBoxIcon>()), Times.Once); Assert.AreEqual(inputCode, component.CodeModule.Content()); }
public void IntroduceParameterRefactoring_Properties_GetAndSet() { //Input const string inputCode = @"Property Get Foo(ByVal fizz As Boolean) As Variant Dim bar As Integer Foo = fizz End Property Property Set Foo(ByVal fizz As Boolean, ByVal buzz As Variant) End Property"; //Expectation const string expectedCode = @"Property Get Foo(ByVal fizz As Boolean, ByVal bar As Integer) As Variant Foo = fizz End Property Property Set Foo(ByVal fizz As Boolean, ByVal bar As Integer, ByVal buzz As Variant) End Property"; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out IVBComponent component); var(state, rewritingManager) = MockParser.CreateAndParseWithRewritingManager(vbe.Object); using (state) { var refactoring = new IntroduceParameterRefactoring(vbe.Object, state, null, rewritingManager); var target = state.AllUserDeclarations.SingleOrDefault(e => e.IdentifierName == "bar"); refactoring.Refactor(target); var actualCode = component.CodeModule.Content(); Assert.AreEqual(expectedCode, actualCode); } }
public void IntroduceParameterRefactoring_DisplaysInvalidSelectionAndDoesNothingForInvalidSelection() { //Input const string inputCode = @"Private fizz As Boolean Private Sub Foo() End Sub"; IVBComponent component; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out component); var state = MockParser.CreateAndParse(vbe.Object); var messageBox = new Mock <IMessageBox>(); messageBox.Setup(m => m.Show(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <MessageBoxButtons>(), It.IsAny <MessageBoxIcon>())).Returns(DialogResult.OK); var refactoring = new IntroduceParameterRefactoring(vbe.Object, state, messageBox.Object); var target = state.AllUserDeclarations.SingleOrDefault(e => e.IdentifierName == "fizz"); refactoring.Refactor(target); messageBox.Verify(m => m.Show(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <MessageBoxButtons>(), It.IsAny <MessageBoxIcon>()), Times.Once); var rewriter = state.GetRewriter(component); Assert.AreEqual(inputCode, rewriter.GetText()); }
public void IntroduceParameterRefactoring_PassInTarget_Nonvariable() { //Input const string inputCode = @"Private Sub Foo() Dim bar As Boolean End Sub"; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out IVBComponent component); var(state, rewritingManager) = MockParser.CreateAndParseWithRewritingManager(vbe.Object); using (state) { var messageBox = new Mock <IMessageBox>(); var refactoring = new IntroduceParameterRefactoring(vbe.Object, state, messageBox.Object, rewritingManager); refactoring.Refactor(state.AllUserDeclarations.First(d => d.DeclarationType != DeclarationType.Variable)); messageBox.Verify(m => m.NotifyWarn(It.IsAny <string>(), It.IsAny <string>()), Times.Once); const string expectedCode = inputCode; var actualCode = component.CodeModule.Content(); Assert.AreEqual(expectedCode, actualCode); } }
public void IntroduceParameterRefactoring_OneParamInList() { //Input const string inputCode = @"Private Sub Foo(ByVal buz As Integer) Dim bar As Boolean End Sub"; var selection = new Selection(2, 10, 2, 13); //Expectation const string expectedCode = @"Private Sub Foo(ByVal buz As Integer, ByVal bar As Boolean) End Sub"; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out IVBComponent component, selection); var(state, rewritingManager) = MockParser.CreateAndParseWithRewritingManager(vbe.Object); using (state) { var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection); var refactoring = new IntroduceParameterRefactoring(vbe.Object, state, null, rewritingManager); refactoring.Refactor(qualifiedSelection); var actualCode = component.CodeModule.Content(); Assert.AreEqual(expectedCode, actualCode); } }
public void IntroduceParameterRefactoring_DisplaysInvalidSelectionAndDoesNothingForInvalidSelection() { //Input const string inputCode = @"Private fizz As Boolean Private Sub Foo() End Sub"; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out var component); var(state, rewritingManager) = MockParser.CreateAndParseWithRewritingManager(vbe.Object); using (state) { var messageBox = new Mock <IMessageBox>(); var refactoring = new IntroduceParameterRefactoring(vbe.Object, state, messageBox.Object, rewritingManager); var target = state.AllUserDeclarations.SingleOrDefault(e => e.IdentifierName == "fizz"); refactoring.Refactor(target); messageBox.Verify(m => m.NotifyWarn(It.IsAny <string>(), It.IsAny <string>()), Times.Once); const string expectedCode = inputCode; var actualCode = component.CodeModule.Content(); Assert.AreEqual(expectedCode, actualCode); } }
public void IntroduceParameterRefactoring_OneParamInList_MultipleLines() { //Input const string inputCode = @"Private Sub Foo(ByVal buz As Integer) Dim _ bar _ As _ Boolean End Sub"; var selection = new Selection(2, 10, 2, 13); //Expectation const string expectedCode = @"Private Sub Foo(ByVal buz As Integer, ByVal bar As Boolean) End Sub"; IVBComponent component; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out component, selection); var state = MockParser.CreateAndParse(vbe.Object); var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection); var refactoring = new IntroduceParameterRefactoring(vbe.Object, state, null); refactoring.Refactor(qualifiedSelection); var rewriter = state.GetRewriter(component); Assert.AreEqual(expectedCode, rewriter.GetText()); }
public void IntroduceParameterRefactoring_MultipleParamsOnMultipleLines() { //Input const string inputCode = @"Private Sub Foo(ByVal buz As Integer, _ ByRef baz As Date) Dim bar As Boolean End Sub"; var selection = new Selection(3, 8, 3, 20); //Expectation const string expectedCode = @"Private Sub Foo(ByVal buz As Integer, _ ByRef baz As Date, ByVal bar As Boolean) End Sub"; // note: the VBE removes extra spaces IVBComponent component; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out component, selection); var state = MockParser.CreateAndParse(vbe.Object); var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection); var refactoring = new IntroduceParameterRefactoring(vbe.Object, state, null); refactoring.Refactor(qualifiedSelection); var rewriter = state.GetRewriter(component); Assert.AreEqual(expectedCode, rewriter.GetText()); }
public void IntroduceParameterRefactoring_MultipleVariablesInStatement_MoveLast() { //Input const string inputCode = @"Private Sub Foo(ByVal buz As Integer, _ ByRef baz As Date) Dim bar As Boolean, _ bat As Date, _ bap As Integer End Sub"; //Expectation const string expectedCode = @"Private Sub Foo(ByVal buz As Integer, _ ByRef baz As Date, ByVal bap As Integer) Dim bar As Boolean, _ bat As Date End Sub"; IVBComponent component; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out component); var state = MockParser.CreateAndParse(vbe.Object); var target = state.AllUserDeclarations.SingleOrDefault(e => e.IdentifierName == "bap"); var refactoring = new IntroduceParameterRefactoring(vbe.Object, state, null); refactoring.Refactor(target); var rewriter = state.GetRewriter(component); Assert.AreEqual(expectedCode, rewriter.GetText()); }
public void IntroduceParameterRefactoring_NoParamsInList_Function() { //Input const string inputCode = @"Private Function Foo() As Boolean Dim bar As Boolean Foo = True End Function"; var selection = new Selection(2, 10, 2, 13); //Expectation const string expectedCode = @"Private Function Foo(ByVal bar As Boolean) As Boolean Foo = True End Function"; IVBComponent component; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out component, selection); var state = MockParser.CreateAndParse(vbe.Object); var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection); var refactoring = new IntroduceParameterRefactoring(vbe.Object, state, null); refactoring.Refactor(qualifiedSelection); var rewriter = state.GetRewriter(component); Assert.AreEqual(expectedCode, rewriter.GetText()); }
public void IntroduceParameterRefactoring_MultipleVariablesInStatement_MoveFirst() { //Input const string inputCode = @"Private Sub Foo(ByVal buz As Integer, _ ByRef baz As Date) Dim bar As Boolean, _ bat As Date, _ bap As Integer End Sub"; var selection = new Selection(3, 10, 3, 13); //Expectation const string expectedCode = @"Private Sub Foo(ByVal buz As Integer, _ ByRef baz As Date, ByVal bar As Boolean) Dim bat As Date, _ bap As Integer End Sub"; // note: the VBE removes extra spaces var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out IVBComponent component, selection); var(state, rewritingManager) = MockParser.CreateAndParseWithRewritingManager(vbe.Object); using (state) { var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection); var refactoring = new IntroduceParameterRefactoring(vbe.Object, state, null, rewritingManager); refactoring.Refactor(qualifiedSelection); var actualCode = component.CodeModule.Content(); Assert.AreEqual(expectedCode, actualCode); } }
public void IntroduceParameterRefactoring_PassInTarget_Nonvariable() { //Input const string inputCode = @"Private Sub Foo() Dim bar As Boolean End Sub"; IVBComponent component; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out component); var state = MockParser.CreateAndParse(vbe.Object); var messageBox = new Mock <IMessageBox>(); messageBox.Setup(m => m.Show(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <MessageBoxButtons>(), It.IsAny <MessageBoxIcon>())) .Returns(DialogResult.OK); var refactoring = new IntroduceParameterRefactoring(vbe.Object, state, messageBox.Object); refactoring.Refactor(state.AllUserDeclarations.First(d => d.DeclarationType != DeclarationType.Variable)); messageBox.Verify(m => m.Show(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <MessageBoxButtons>(), It.IsAny <MessageBoxIcon>()), Times.Once); var rewriter = state.GetRewriter(component); Assert.AreEqual(inputCode, rewriter.GetText()); }
public void IntroduceParameterRefactoring_PassInTarget() { //Input const string inputCode = @"Private Sub Foo() Dim bar As Boolean End Sub"; var selection = new Selection(2, 10, 2, 13); //Expectation const string expectedCode = @"Private Sub Foo(ByVal bar As Boolean) End Sub"; IVBComponent component; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out component, selection); var state = MockParser.CreateAndParse(vbe.Object); var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection); var refactoring = new IntroduceParameterRefactoring(vbe.Object, state, null); refactoring.Refactor(state.AllUserDeclarations.FindVariable(qualifiedSelection)); Assert.AreEqual(expectedCode, component.CodeModule.Content()); }
public void IntroduceParameterRefactoring_MultipleVariablesInStatement_OnOneLine_MoveFirst() { //Input const string inputCode = @"Private Sub Foo(ByVal buz As Integer, _ ByRef baz As Date) Dim bar As Boolean, bat As Date, bap As Integer End Sub"; //Expectation const string expectedCode = @"Private Sub Foo(ByVal buz As Integer, _ ByRef baz As Date, ByVal bar As Boolean) Dim bat As Date, bap As Integer End Sub"; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out var component); var(state, rewritingManager) = MockParser.CreateAndParseWithRewritingManager(vbe.Object); using (state) { var target = state.AllUserDeclarations.SingleOrDefault(e => e.IdentifierName == "bar"); var refactoring = new IntroduceParameterRefactoring(vbe.Object, state, null, rewritingManager); refactoring.Refactor(target); var actualCode = component.CodeModule.Content(); Assert.AreEqual(expectedCode, actualCode); } }
public void IntroduceParameterRefactoring_Properties_GetAndLet() { //Input const string inputCode = @"Property Get Foo(ByVal fizz As Boolean) As Boolean Dim bar As Integer Foo = fizz End Property Property Let Foo(ByVal fizz As Boolean, ByVal buzz As Boolean) End Property"; //Expectation const string expectedCode = @"Property Get Foo(ByVal fizz As Boolean, ByVal bar As Integer) As Boolean Foo = fizz End Property Property Let Foo(ByVal fizz As Boolean, ByVal bar As Integer, ByVal buzz As Boolean) End Property"; IVBComponent component; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out component); var state = MockParser.CreateAndParse(vbe.Object); var refactoring = new IntroduceParameterRefactoring(vbe.Object, state, null); var target = state.AllUserDeclarations.SingleOrDefault(e => e.IdentifierName == "bar"); refactoring.Refactor(target); var rewriter = state.GetRewriter(component); Assert.AreEqual(expectedCode, rewriter.GetText()); }
public void IntroduceParameterRefactoring_PassInTarget() { //Input const string inputCode = @"Private Sub Foo() Dim bar As Boolean End Sub"; //Expectation const string expectedCode = @"Private Sub Foo(ByVal bar As Boolean) End Sub"; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out IVBComponent component); var(state, rewritingManager) = MockParser.CreateAndParseWithRewritingManager(vbe.Object); using (state) { var refactoring = new IntroduceParameterRefactoring(vbe.Object, state, null, rewritingManager); var target = state.AllUserDeclarations.SingleOrDefault(e => e.IdentifierName == "bar" && e.DeclarationType == DeclarationType.Variable); refactoring.Refactor(target); var actualCode = component.CodeModule.Content(); Assert.AreEqual(expectedCode, actualCode); } }
protected override CommandBase TestCommand(IVBE vbe, RubberduckParserState state, IRewritingManager rewritingManager, ISelectionService selectionService) { var msgBox = new Mock <IMessageBox>().Object; var selectedDeclarationProvider = new SelectedDeclarationProvider(selectionService, state); var refactoring = new IntroduceParameterRefactoring(state, msgBox, rewritingManager, selectionService, selectedDeclarationProvider); var notifier = new IntroduceParameterFailedNotifier(msgBox); return(new RefactorIntroduceParameterCommand(refactoring, notifier, state, selectionService, selectedDeclarationProvider)); }
public void IntroduceParameterRefactoring_ImplementsInterface_Reject() { //Input const string inputCode1 = @"Sub fizz(ByVal boo As Boolean) End Sub"; const string inputCode2 = @"Implements IClass1 Sub IClass1_fizz(ByVal boo As Boolean) Dim fizz As Date End Sub"; var selection = new Selection(4, 10, 4, 14); //Arrange var builder = new MockVbeBuilder(); var project = builder.ProjectBuilder("TestProject1", vbext_ProjectProtection.vbext_pp_none) .AddComponent("IClass1", vbext_ComponentType.vbext_ct_ClassModule, inputCode1) .AddComponent("Class1", vbext_ComponentType.vbext_ct_ClassModule, inputCode2) .Build(); var vbe = builder.AddProject(project).Build(); var component = project.Object.VBComponents.Item(1); vbe.Setup(v => v.ActiveCodePane).Returns(component.CodeModule.CodePane); var codePaneFactory = new CodePaneWrapperFactory(); var mockHost = new Mock <IHostApplication>(); mockHost.SetupAllProperties(); var parser = MockParser.Create(vbe.Object, new RubberduckParserState()); parser.Parse(); if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); } var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection); var module1 = project.Object.VBComponents.Item(0).CodeModule; var module2 = project.Object.VBComponents.Item(1).CodeModule; var messageBox = new Mock <IMessageBox>(); messageBox.Setup(m => m.Show(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <MessageBoxButtons>(), It.IsAny <MessageBoxIcon>())) .Returns(DialogResult.No); //Act var refactoring = new IntroduceParameterRefactoring(parser.State, new ActiveCodePaneEditor(vbe.Object, codePaneFactory), messageBox.Object); refactoring.Refactor(qualifiedSelection); //Assert Assert.AreEqual(inputCode1, module1.Lines()); Assert.AreEqual(inputCode2, module2.Lines()); }
public void IntroduceParameterRefactoring_ImplementsInterface() { //Input const string inputCode1 = @"Sub fizz(ByVal boo As Boolean) End Sub"; const string inputCode2 = @"Implements IClass1 Sub IClass1_fizz(ByVal boo As Boolean) Dim fizz As Date End Sub"; var selection = new Selection(4, 10, 4, 14); //Expectation const string expectedCode1 = @"Sub fizz(ByVal boo As Boolean, ByVal fizz As Date) End Sub"; const string expectedCode2 = @"Implements IClass1 Sub IClass1_fizz(ByVal boo As Boolean, ByVal fizz As Date) End Sub"; var builder = new MockVbeBuilder(); var project = builder.ProjectBuilder("TestProject1", ProjectProtection.Unprotected) .AddComponent("IClass1", ComponentType.ClassModule, inputCode1) .AddComponent("Class1", ComponentType.ClassModule, inputCode2) .Build(); var vbe = builder.AddProject(project).Build(); var component = project.Object.VBComponents[1]; vbe.Setup(v => v.ActiveCodePane).Returns(component.CodeModule.CodePane); var state = MockParser.CreateAndParse(vbe.Object); var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection); var module1 = project.Object.VBComponents[0].CodeModule; var module2 = project.Object.VBComponents[1].CodeModule; var messageBox = new Mock <IMessageBox>(); messageBox.Setup(m => m.Show(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <MessageBoxButtons>(), It.IsAny <MessageBoxIcon>())) .Returns(DialogResult.OK); var refactoring = new IntroduceParameterRefactoring(vbe.Object, state, messageBox.Object); refactoring.Refactor(qualifiedSelection); Assert.AreEqual(expectedCode1, module1.Content()); Assert.AreEqual(expectedCode2, module2.Content()); }
public void IntroduceParameterRefactoring_ImplementsInterface() { //Input const string inputCode1 = @"Sub fizz(ByVal boo As Boolean) End Sub"; const string inputCode2 = @"Implements IClass1 Sub IClass1_fizz(ByVal boo As Boolean) Dim fizz As Date End Sub"; //Expectation const string expectedCode1 = @"Sub fizz(ByVal boo As Boolean, ByVal fizz As Date) End Sub"; const string expectedCode2 = @"Implements IClass1 Sub IClass1_fizz(ByVal boo As Boolean, ByVal fizz As Date) End Sub"; var builder = new MockVbeBuilder(); var project = builder.ProjectBuilder("TestProject1", ProjectProtection.Unprotected) .AddComponent("IClass1", ComponentType.ClassModule, inputCode1) .AddComponent("Class1", ComponentType.ClassModule, inputCode2) .Build(); var vbe = builder.AddProject(project).Build(); var component0 = project.Object.VBComponents[0]; var component1 = project.Object.VBComponents[1]; vbe.Setup(v => v.ActiveCodePane).Returns(component1.CodeModule.CodePane); var state = MockParser.CreateAndParse(vbe.Object); var messageBox = new Mock <IMessageBox>(); messageBox.Setup(m => m.Show(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <MessageBoxButtons>(), It.IsAny <MessageBoxIcon>())) .Returns(DialogResult.OK); var refactoring = new IntroduceParameterRefactoring(vbe.Object, state, messageBox.Object); var target = state.AllUserDeclarations.SingleOrDefault(e => e.IdentifierName == "fizz" && e.DeclarationType == DeclarationType.Variable); refactoring.Refactor(target); var rewriter1 = state.GetRewriter(component0); Assert.AreEqual(expectedCode1, rewriter1.GetText()); var rewriter2 = state.GetRewriter(component1); Assert.AreEqual(expectedCode2, rewriter2.GetText()); }
public void IntroduceParameterRefactoring_ImplementsInterface() { //Input const string inputCode1 = @"Sub fizz(ByVal boo As Boolean) End Sub"; const string inputCode2 = @"Implements IClass1 Sub IClass1_fizz(ByVal boo As Boolean) Dim fizz As Date End Sub"; //Expectation const string expectedCode1 = @"Sub fizz(ByVal boo As Boolean, ByVal fizz As Date) End Sub"; const string expectedCode2 = @"Implements IClass1 Sub IClass1_fizz(ByVal boo As Boolean, ByVal fizz As Date) End Sub"; var builder = new MockVbeBuilder(); var project = builder.ProjectBuilder("TestProject1", ProjectProtection.Unprotected) .AddComponent("IClass1", ComponentType.ClassModule, inputCode1) .AddComponent("Class1", ComponentType.ClassModule, inputCode2) .Build(); var vbe = builder.AddProject(project).Build(); var component1 = project.Object.VBComponents[0]; var component2 = project.Object.VBComponents[1]; vbe.Setup(v => v.ActiveCodePane).Returns(component1.CodeModule.CodePane); var(state, rewritingManager) = MockParser.CreateAndParseWithRewritingManager(vbe.Object); using (state) { var messageBox = new Mock <IMessageBox>(); messageBox.Setup(m => m.Question(It.IsAny <string>(), It.IsAny <string>())).Returns(true); var refactoring = new IntroduceParameterRefactoring(vbe.Object, state, messageBox.Object, rewritingManager); var target = state.AllUserDeclarations.SingleOrDefault(e => e.IdentifierName == "fizz" && e.DeclarationType == DeclarationType.Variable); refactoring.Refactor(target); var actualCode1 = component1.CodeModule.Content(); Assert.AreEqual(expectedCode1, actualCode1); var actualCode2 = component2.CodeModule.Content(); Assert.AreEqual(expectedCode2, actualCode2); messageBox.Verify(m => m.Question(It.IsAny <string>(), It.IsAny <string>()), Times.Once()); } }
public override void Execute(object parameter) { if (Vbe.ActiveCodePane == null) { return; } var selection = Vbe.ActiveCodePane.GetSelection(); var refactoring = new IntroduceParameterRefactoring(_state, Editor, new MessageBox()); refactoring.Refactor(selection); }
public void IntroduceParameterRefactoring_PassInTarget_Nonvariable() { //Input const string inputCode = @"Private Sub Foo() Dim bar As Boolean End Sub"; //Arrange var builder = new MockVbeBuilder(); VBComponent component; var vbe = builder.BuildFromSingleStandardModule(inputCode, out component); var project = vbe.Object.VBProjects.Item(0); var module = project.VBComponents.Item(0).CodeModule; var codePaneFactory = new CodePaneWrapperFactory(); var mockHost = new Mock <IHostApplication>(); mockHost.SetupAllProperties(); var parser = MockParser.Create(vbe.Object, new RubberduckParserState()); parser.Parse(); if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); } var messageBox = new Mock <IMessageBox>(); messageBox.Setup(m => m.Show(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <MessageBoxButtons>(), It.IsAny <MessageBoxIcon>())) .Returns(DialogResult.OK); //Act var refactoring = new IntroduceParameterRefactoring(parser.State, new ActiveCodePaneEditor(vbe.Object, codePaneFactory), messageBox.Object); //Assert try { refactoring.Refactor(parser.State.AllUserDeclarations.First(d => d.DeclarationType != DeclarationType.Variable)); } catch (ArgumentException e) { messageBox.Verify(m => m.Show(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <MessageBoxButtons>(), It.IsAny <MessageBoxIcon>()), Times.Once); Assert.AreEqual("Invalid declaration type\r\nParameter name: target", e.Message); Assert.AreEqual(inputCode, module.Lines()); return; } Assert.Fail(); }
protected override void OnExecute(object parameter) { var selection = Vbe.GetActiveSelection(); if (!selection.HasValue) { return; } var refactoring = new IntroduceParameterRefactoring(Vbe, _state, _messageBox); refactoring.Refactor(selection.Value); }
protected override void OnExecute(object parameter) { var activeSelection = SelectionService.ActiveSelection(); if (!activeSelection.HasValue) { return; } var refactoring = new IntroduceParameterRefactoring(_state, _messageBox, RewritingManager, SelectionService); refactoring.Refactor(activeSelection.Value); }
public override void Execute(object parameter) { var selection = Vbe.ActiveCodePane.GetQualifiedSelection(); if (!selection.HasValue) { return; } var refactoring = new IntroduceParameterRefactoring(Vbe, _state, new MessageBox()); refactoring.Refactor(selection.Value); }
public RefactorIntroduceParameterCommand( IntroduceParameterRefactoring refactoring, IntroduceParameterFailedNotifier introduceParameterFailedNotifier, RubberduckParserState state, ISelectionProvider selectionProvider, ISelectedDeclarationProvider selectedDeclarationProvider) : base(refactoring, introduceParameterFailedNotifier, selectionProvider, state) { _state = state; _selectedDeclarationProvider = selectedDeclarationProvider; AddToCanExecuteEvaluation(SpecializedEvaluateCanExecute); }
public void IntroduceParameterRefactoring_Properties_GetAndSet() { //Input const string inputCode = @"Property Get Foo(ByVal fizz As Boolean) As Variant Dim bar As Integer Foo = fizz End Property Property Set Foo(ByVal fizz As Boolean, ByVal buzz As Variant) End Property"; var selection = new Selection(2, 10, 2, 13); //Expectation const string expectedCode = @"Property Get Foo(ByVal fizz As Boolean, ByVal bar As Integer) As Variant Foo = fizz End Property Property Set Foo(ByVal fizz As Boolean, ByVal bar As Integer, ByVal buzz As Variant) End Property"; //Arrange var builder = new MockVbeBuilder(); VBComponent component; var vbe = builder.BuildFromSingleStandardModule(inputCode, out component); var project = vbe.Object.VBProjects.Item(0); var module = project.VBComponents.Item(0).CodeModule; var codePaneFactory = new CodePaneWrapperFactory(); var mockHost = new Mock <IHostApplication>(); mockHost.SetupAllProperties(); var parser = MockParser.Create(vbe.Object, new RubberduckParserState()); parser.Parse(); if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); } var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection); //Act var refactoring = new IntroduceParameterRefactoring(parser.State, new ActiveCodePaneEditor(vbe.Object, codePaneFactory), null); refactoring.Refactor(qualifiedSelection); //Assert Assert.AreEqual(expectedCode, module.Lines()); }
public void IntroduceParameterRefactoring_MultipleVariablesInStatement_MoveLast() { //Input const string inputCode = @"Private Sub Foo(ByVal buz As Integer, _ ByRef baz As Date) Dim bar As Boolean, _ bat As Date, _ bap As Integer End Sub"; var selection = new Selection(5, 10, 5, 13); //Expectation const string expectedCode = @"Private Sub Foo(ByVal buz As Integer, _ ByRef baz As Date, ByVal bap As Integer) Dim bar As Boolean, _ bat As Date End Sub"; // note: the VBE removes extra spaces //Arrange var builder = new MockVbeBuilder(); VBComponent component; var vbe = builder.BuildFromSingleStandardModule(inputCode, out component); var project = vbe.Object.VBProjects.Item(0); var module = project.VBComponents.Item(0).CodeModule; var codePaneFactory = new CodePaneWrapperFactory(); var mockHost = new Mock <IHostApplication>(); mockHost.SetupAllProperties(); var parser = MockParser.Create(vbe.Object, new RubberduckParserState()); parser.Parse(); if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); } var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection); //Act var refactoring = new IntroduceParameterRefactoring(parser.State, new ActiveCodePaneEditor(vbe.Object, codePaneFactory), null); refactoring.Refactor(qualifiedSelection); //Assert Assert.AreEqual(expectedCode, module.Lines()); }
public void IntroduceParameterRefactoring_NoParamsInList_Sub() { //Input const string inputCode = @"Private Sub Foo() Dim bar As Boolean End Sub"; var selection = new Selection(2, 10, 2, 13); //Expectation const string expectedCode = @"Private Sub Foo(ByVal bar As Boolean) End Sub"; //Arrange var builder = new MockVbeBuilder(); VBComponent component; var vbe = builder.BuildFromSingleStandardModule(inputCode, out component); var project = vbe.Object.VBProjects.Item(0); var module = project.VBComponents.Item(0).CodeModule; var codePaneFactory = new CodePaneWrapperFactory(); var mockHost = new Mock<IHostApplication>(); mockHost.SetupAllProperties(); var parser = MockParser.Create(vbe.Object, new RubberduckParserState()); parser.Parse(); if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); } var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection); //Act var refactoring = new IntroduceParameterRefactoring(parser.State, new ActiveCodePaneEditor(vbe.Object, codePaneFactory), null); refactoring.Refactor(qualifiedSelection); //Assert Assert.AreEqual(expectedCode, module.Lines()); }
public void IntroduceParameterRefactoring_MultipleVariablesInStatement_OnOneLine_MoveFirst() { //Input const string inputCode = @"Private Sub Foo(ByVal buz As Integer, _ ByRef baz As Date) Dim bar As Boolean, bat As Date, bap As Integer End Sub"; var selection = new Selection(3, 10, 3, 13); //Expectation const string expectedCode = @"Private Sub Foo(ByVal buz As Integer, _ ByRef baz As Date, ByVal bar As Boolean) Dim bat As Date, bap As Integer End Sub"; // note: the VBE removes extra spaces //Arrange var builder = new MockVbeBuilder(); VBComponent component; var vbe = builder.BuildFromSingleStandardModule(inputCode, out component); var project = vbe.Object.VBProjects.Item(0); var module = project.VBComponents.Item(0).CodeModule; var codePaneFactory = new CodePaneWrapperFactory(); var mockHost = new Mock<IHostApplication>(); mockHost.SetupAllProperties(); var parser = MockParser.Create(vbe.Object, new RubberduckParserState()); parser.Parse(); if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); } var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection); //Act var refactoring = new IntroduceParameterRefactoring(parser.State, new ActiveCodePaneEditor(vbe.Object, codePaneFactory), null); refactoring.Refactor(qualifiedSelection); //Assert Assert.AreEqual(expectedCode, module.Lines()); }
public void IntroduceParameterRefactoring_DisplaysInvalidSelectionAndDoesNothingForInvalidSelection() { //Input const string inputCode = @"Private fizz As Boolean Private Sub Foo() End Sub"; var selection = new Selection(3, 16, 3, 16); //Arrange var builder = new MockVbeBuilder(); VBComponent component; var vbe = builder.BuildFromSingleStandardModule(inputCode, out component); var project = vbe.Object.VBProjects.Item(0); var module = project.VBComponents.Item(0).CodeModule; var codePaneFactory = new CodePaneWrapperFactory(); var mockHost = new Mock<IHostApplication>(); mockHost.SetupAllProperties(); var parser = MockParser.Create(vbe.Object, new RubberduckParserState()); parser.Parse(); if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); } var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection); var messageBox = new Mock<IMessageBox>(); messageBox.Setup(m => m.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxButtons>(), It.IsAny<MessageBoxIcon>())).Returns(DialogResult.OK); //Act var refactoring = new IntroduceParameterRefactoring(parser.State, new ActiveCodePaneEditor(vbe.Object, codePaneFactory), messageBox.Object); refactoring.Refactor(qualifiedSelection); //Assert messageBox.Verify(m => m.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxButtons>(), It.IsAny<MessageBoxIcon>()), Times.Once); Assert.AreEqual(inputCode, module.Lines()); }
public void IntroduceParameterRefactoring_ImplementsInterface_Reject() { //Input const string inputCode1 = @"Sub fizz(ByVal boo As Boolean) End Sub"; const string inputCode2 = @"Implements IClass1 Sub IClass1_fizz(ByVal boo As Boolean) Dim fizz As Date End Sub"; var selection = new Selection(4, 10, 4, 14); //Arrange var builder = new MockVbeBuilder(); var project = builder.ProjectBuilder("TestProject1", vbext_ProjectProtection.vbext_pp_none) .AddComponent("IClass1", vbext_ComponentType.vbext_ct_ClassModule, inputCode1) .AddComponent("Class1", vbext_ComponentType.vbext_ct_ClassModule, inputCode2) .Build(); var vbe = builder.AddProject(project).Build(); var component = project.Object.VBComponents.Item(1); vbe.Setup(v => v.ActiveCodePane).Returns(component.CodeModule.CodePane); var codePaneFactory = new CodePaneWrapperFactory(); var mockHost = new Mock<IHostApplication>(); mockHost.SetupAllProperties(); var parser = MockParser.Create(vbe.Object, new RubberduckParserState()); parser.Parse(); if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); } var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection); var module1 = project.Object.VBComponents.Item(0).CodeModule; var module2 = project.Object.VBComponents.Item(1).CodeModule; var messageBox = new Mock<IMessageBox>(); messageBox.Setup(m => m.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxButtons>(), It.IsAny<MessageBoxIcon>())) .Returns(DialogResult.No); //Act var refactoring = new IntroduceParameterRefactoring(parser.State, new ActiveCodePaneEditor(vbe.Object, codePaneFactory), messageBox.Object); refactoring.Refactor(qualifiedSelection); //Assert Assert.AreEqual(inputCode1, module1.Lines()); Assert.AreEqual(inputCode2, module2.Lines()); }
public void IntroduceParameterRefactoring_PassInTarget_Nonvariable() { //Input const string inputCode = @"Private Sub Foo() Dim bar As Boolean End Sub"; //Arrange var builder = new MockVbeBuilder(); VBComponent component; var vbe = builder.BuildFromSingleStandardModule(inputCode, out component); var project = vbe.Object.VBProjects.Item(0); var module = project.VBComponents.Item(0).CodeModule; var codePaneFactory = new CodePaneWrapperFactory(); var mockHost = new Mock<IHostApplication>(); mockHost.SetupAllProperties(); var parser = MockParser.Create(vbe.Object, new RubberduckParserState()); parser.Parse(); if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); } var messageBox = new Mock<IMessageBox>(); messageBox.Setup(m => m.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxButtons>(), It.IsAny<MessageBoxIcon>())) .Returns(DialogResult.OK); //Act var refactoring = new IntroduceParameterRefactoring(parser.State, new ActiveCodePaneEditor(vbe.Object, codePaneFactory), messageBox.Object); //Assert try { refactoring.Refactor(parser.State.AllUserDeclarations.First(d => d.DeclarationType != DeclarationType.Variable)); } catch (ArgumentException e) { messageBox.Verify(m => m.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxButtons>(), It.IsAny<MessageBoxIcon>()), Times.Once); Assert.AreEqual("Invalid declaration type\r\nParameter name: target", e.Message); Assert.AreEqual(inputCode, module.Lines()); return; } Assert.Fail(); }