public ProjectBuilder ( string name, vbext_ProjectProtection protection ) : |
||
name | string | The name of the project to build. |
protection | vbext_ProjectProtection | A value that indicates whether the project is protected. |
리턴 |
public void UseMeaningfulName_ReturnsResult_NameEndsWithDigit() { const string inputCode = @"Sub Foo1() End Sub"; //Arrange var builder = new MockVbeBuilder(); var project = builder.ProjectBuilder("VBAProject", vbext_ProjectProtection.vbext_pp_none) .AddComponent("MyClass", vbext_ComponentType.vbext_ct_ClassModule, inputCode) .Build(); var vbe = builder.AddProject(project).Build(); 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 inspection = new UseMeaningfulNameInspection(null, parser.State); var inspectionResults = inspection.GetInspectionResults(); Assert.AreEqual(1, inspectionResults.Count()); }
private RubberduckParserState Resolve(params Tuple<string,vbext_ComponentType>[] components) { var builder = new MockVbeBuilder(); var projectBuilder = builder.ProjectBuilder("TestProject", vbext_ProjectProtection.vbext_pp_none); for (var i = 0; i < components.Length; i++) { projectBuilder.AddComponent("Component" + (i + 1), components[i].Item2, components[i].Item1); } var project = projectBuilder.Build(); builder.AddProject(project); var vbe = builder.Build(); var parser = MockParser.Create(vbe.Object, new RubberduckParserState()); parser.Parse(); if (parser.State.Status != ParserState.Ready) { Assert.Inconclusive("Parser state should be 'Ready', but returns '{0}'.", parser.State.Status); } return parser.State; }
public void DefaultProjectName_DoesNotReturnResult() { const string inputCode = @""; //Arrange var builder = new MockVbeBuilder(); var project = builder.ProjectBuilder("TestProject", vbext_ProjectProtection.vbext_pp_none) .AddComponent("Class1", vbext_ComponentType.vbext_ct_ClassModule, inputCode) .Build(); var vbe = builder.AddProject(project).Build(); 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 inspection = new DefaultProjectNameInspection(parser.State); var inspectionResults = inspection.GetInspectionResults(); Assert.AreEqual(0, inspectionResults.Count()); }
public static Mock <IVBE> BuildFromSingleModule(string content, string name, ComponentType type, out IVBComponent component, Selection selection = default, bool referenceStdLibs = false) { var vbeBuilder = new MockVbeBuilder(); var builder = vbeBuilder.ProjectBuilder(TestProjectName, ProjectProtection.Unprotected); builder.AddComponent(name, type, content, selection); if (referenceStdLibs) { builder.AddReference("VBA", LibraryPathVBA, 4, 2, true); } var project = builder.Build(); var vbe = vbeBuilder.AddProject(project).Build(); component = project.Object.VBComponents[0]; vbe.Object.ActiveVBProject = project.Object; vbe.Object.ActiveCodePane = component.CodeModule.CodePane; return(vbe); }
public void GivenReferencedPublicField_UpdatesReferenceToNewProperty() { //Input const string code_class1 = @"Public fizz As Integer Sub Foo() fizz = 1 End Sub"; const string code_class2 = @"Sub Foo() Dim c As Class1 c.fizz = 0 Bar c.fizz End Sub Sub Bar(ByVal v As Integer) End Sub"; var selection = new Selection(1, 1, 1, 1); //Expectation const string expectedCode1 = @"Private fizz As Integer Public Property Get Name() As Integer Name = fizz End Property Public Property Let Name(ByVal value As Integer) fizz = value End Property Sub Foo() Name = 1 End Sub"; const string expectedCode2 = @"Sub Foo() Dim c As Class1 c.Name = 0 Bar c.Name End Sub Sub Bar(ByVal v As Integer) End Sub"; //Arrange var builder = new MockVbeBuilder(); var project = builder.ProjectBuilder("TestProject1", vbext_ProjectProtection.vbext_pp_none) .AddComponent("Class1", vbext_ComponentType.vbext_ct_ClassModule, code_class1) .AddComponent("Class2", vbext_ComponentType.vbext_ct_ClassModule, code_class2) .Build(); var vbe = builder.AddProject(project).Build(); var component = project.Object.VBComponents.Item(0); 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 model = new EncapsulateFieldModel(parser.State, qualifiedSelection) { ImplementLetSetterType = true, ImplementSetSetterType = false, ParameterName = "value", PropertyName = "Name" }; //SetupFactory var factory = SetupFactory(model); //Act var refactoring = new EncapsulateFieldRefactoring(factory.Object, new ActiveCodePaneEditor(vbe.Object, codePaneFactory)); refactoring.Refactor(qualifiedSelection); var actualCode1 = module1.Lines(); var actualCode2 = module2.Lines(); //Assert Assert.AreEqual(expectedCode1, actualCode1); Assert.AreEqual(expectedCode2, actualCode2); }
public void RenameRefactoring_RenameEvent() { //Input const string inputCode1 = @"Public Event Foo(ByVal arg1 As Integer, ByVal arg2 As String)"; const string inputCode2 = @"Private WithEvents abc As Class1 Private Sub abc_Foo(ByVal i As Integer, ByVal s As String) End Sub"; var selection = new Selection(1, 16, 1, 16); //Expectation const string expectedCode1 = @"Public Event Goo(ByVal arg1 As Integer, ByVal arg2 As String)"; const string expectedCode2 = @"Private WithEvents abc As Class1 Private Sub abc_Goo(ByVal i As Integer, ByVal s As String) End Sub"; //Arrange var builder = new MockVbeBuilder(); var project = builder.ProjectBuilder("TestProject1", vbext_ProjectProtection.vbext_pp_none) .AddComponent("Class1", vbext_ComponentType.vbext_ct_ClassModule, inputCode1) .AddComponent("Class2", vbext_ComponentType.vbext_ct_ClassModule, inputCode2) .Build(); var vbe = builder.AddProject(project).Build(); var component = project.Object.VBComponents.Item(0); 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 model = new RenameModel(vbe.Object, parser.State, qualifiedSelection, null) { NewName = "Goo" }; //SetupFactory var factory = SetupFactory(model); //Act var refactoring = new RenameRefactoring(factory.Object, new ActiveCodePaneEditor(vbe.Object, codePaneFactory), null, parser.State); refactoring.Refactor(qualifiedSelection); //Assert Assert.AreEqual(expectedCode1, module1.Lines()); Assert.AreEqual(expectedCode2, module2.Lines()); }
public void FunctionReturnValueNotUsed_QuickFixWorks_Interface() { const string inputInterfaceCode = @"Public Function Test() As Integer End Function"; const string expectedInterfaceCode = @"Public Sub Test() End Sub"; const string inputImplementationCode1 = @"Implements IFoo Public Function IFoo_Test() As Integer IFoo_Test = 42 End Function"; const string expectedImplementationCode1 = @"Implements IFoo Public Sub IFoo_Test() End Sub"; const string inputImplementationCode2 = @"Implements IFoo Public Function IFoo_Test() As Integer IFoo_Test = 42 End Function"; const string expectedImplementationCode2 = @"Implements IFoo Public Sub IFoo_Test() End Sub"; const string callSiteCode = @" Public Function Baz() Dim testObj As IFoo Set testObj = new Bar() testObj.Test End Function"; //Arrange var builder = new MockVbeBuilder(); var projectBuilder = builder.ProjectBuilder("TestProject", vbext_ProjectProtection.vbext_pp_none); projectBuilder.AddComponent("IFoo", vbext_ComponentType.vbext_ct_ClassModule, inputInterfaceCode); projectBuilder.AddComponent("Bar", vbext_ComponentType.vbext_ct_ClassModule, inputImplementationCode1); projectBuilder.AddComponent("Bar2", vbext_ComponentType.vbext_ct_ClassModule, inputImplementationCode2); projectBuilder.AddComponent("TestModule", vbext_ComponentType.vbext_ct_StdModule, callSiteCode); var vbe = projectBuilder.MockVbeBuilder().Build(); 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 inspection = new FunctionReturnValueNotUsedInspection(parser.State); var inspectionResults = inspection.GetInspectionResults(); inspectionResults.First().QuickFixes.First().Fix(); var project = vbe.Object.VBProjects.Item(0); var interfaceModule = project.VBComponents.Item(0).CodeModule; string actualInterface = interfaceModule.Lines(); Assert.AreEqual(expectedInterfaceCode, actualInterface, "Interface"); var implementationModule1 = project.VBComponents.Item(1).CodeModule; string actualImplementation1 = implementationModule1.Lines(); //Assert.AreEqual(expectedImplementationCode1, actualImplementation1, "Implementation1"); var implementationModule2 = project.VBComponents.Item(2).CodeModule; string actualImplementation2 = implementationModule2.Lines(); //Assert.AreEqual(expectedImplementationCode2, actualImplementation2, "Implementation2"); }
public void FunctionReturnValueNotUsed_ReturnsResult_InterfaceMember() { const string interfaceCode = @"Public Function Test() As Integer End Function"; const string implementationCode = @"Implements IFoo Public Function IFoo_Test() As Integer IFoo_Test = 42 End Function"; const string callSiteCode = @" Public Sub Baz() Dim testObj As IFoo Set testObj = new Bar() testObj.Test End Sub"; //Arrange var builder = new MockVbeBuilder(); var projectBuilder = builder.ProjectBuilder("TestProject", vbext_ProjectProtection.vbext_pp_none); projectBuilder.AddComponent("IFoo", vbext_ComponentType.vbext_ct_ClassModule, interfaceCode); projectBuilder.AddComponent("Bar", vbext_ComponentType.vbext_ct_ClassModule, implementationCode); projectBuilder.AddComponent("TestModule", vbext_ComponentType.vbext_ct_StdModule, callSiteCode); var vbe = projectBuilder.MockVbeBuilder().Build(); 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 inspection = new FunctionReturnValueNotUsedInspection(parser.State); var inspectionResults = inspection.GetInspectionResults(); Assert.AreEqual(1, inspectionResults.Count()); }
public void ProcedureShouldBeFunction_DoesNotReturnResult_EventImplementation() { //Input const string inputCode1 = @"Public Event Foo(ByRef arg1 As Integer)"; const string inputCode2 = @"Private WithEvents abc As Class1 Private Sub abc_Foo(ByRef arg1 As Integer) End Sub"; //Arrange var builder = new MockVbeBuilder(); var project = builder.ProjectBuilder("TestProject1", vbext_ProjectProtection.vbext_pp_none) .AddComponent("Class1", vbext_ComponentType.vbext_ct_ClassModule, inputCode1) .AddComponent("Class2", vbext_ComponentType.vbext_ct_ClassModule, inputCode2) .Build(); var vbe = builder.AddProject(project).Build(); 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 inspection = new ProcedureCanBeWrittenAsFunctionInspection(parser.State); var inspectionResults = inspection.GetInspectionResults(); Assert.AreEqual(0, inspectionResults.Count()); }
public void Presenter_NullTargetReturnsNullModel() { //Input const string inputCode = @" Private Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String) End Sub"; var selection = Selection.Home; //Arrange var builder = new MockVbeBuilder(); var projectBuilder = builder.ProjectBuilder("TestProject1", vbext_ProjectProtection.vbext_pp_none); projectBuilder.AddComponent("Module1", vbext_ComponentType.vbext_ct_StdModule, inputCode); var project = projectBuilder.Build(); builder.AddProject(project); var vbe = builder.Build(); 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 codePane = project.Object.VBComponents.Item(0).CodeModule.CodePane; var ext = codePaneFactory.Create(codePane); ext.Selection = selection; var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(codePane.CodeModule.Parent), selection); var editor = new Mock<IActiveCodePaneEditor>(); editor.Setup(e => e.GetSelection()).Returns(qualifiedSelection); var factory = new EncapsulateFieldPresenterFactory(parser.State, editor.Object, null); var presenter = factory.Create(); Assert.AreEqual(null, presenter.Show()); }
public void Factory_NullSelectionReturnsNullPresenter() { //Input const string inputCode = @"Private fizz As Integer"; //Arrange var builder = new MockVbeBuilder(); var projectBuilder = builder.ProjectBuilder("TestProject1", vbext_ProjectProtection.vbext_pp_none); projectBuilder.AddComponent("Module1", vbext_ComponentType.vbext_ct_StdModule, inputCode); var project = projectBuilder.Build(); builder.AddProject(project); var vbe = builder.Build(); 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 editor = new Mock<IActiveCodePaneEditor>(); editor.Setup(e => e.GetSelection()).Returns((QualifiedSelection?)null); var factory = new EncapsulateFieldPresenterFactory(parser.State, editor.Object, null); Assert.AreEqual(null, factory.Create()); }
public void RenameRefactoring_RenameCodeModule() { const string newName = "RenameModule"; //Input const string inputCode = @"Private Sub Foo(ByVal a As Integer, ByVal b As String) End Sub"; var selection = new Selection(3, 27, 3, 27); //Arrange var builder = new MockVbeBuilder(); var project = builder.ProjectBuilder("TestProject1", vbext_ProjectProtection.vbext_pp_none) .AddComponent("Class1", vbext_ComponentType.vbext_ct_ClassModule, inputCode) .Build(); var vbe = builder.AddProject(project).Build(); var component = project.Object.VBComponents.Item(0); 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 model = new RenameModel(vbe.Object, parser.State, qualifiedSelection, null) { NewName = newName }; model.Target = model.Declarations.FirstOrDefault(i => i.DeclarationType == DeclarationType.Class && i.IdentifierName == "Class1"); //SetupFactory var factory = SetupFactory(model); //Act var refactoring = new RenameRefactoring(factory.Object, new ActiveCodePaneEditor(vbe.Object, codePaneFactory), null, parser.State); refactoring.Refactor(model.Target); //Assert Assert.AreSame(newName, component.CodeModule.Name); }
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 OptionBaseOnePartiallySpecified_ReturnsResults() { const string inputCode1 = @""; const string inputCode2 = @"Option Base 1"; //Arrange var builder = new MockVbeBuilder(); var project = builder.ProjectBuilder("TestProject1", vbext_ProjectProtection.vbext_pp_none) .AddComponent("Class1", vbext_ComponentType.vbext_ct_ClassModule, inputCode1) .AddComponent("Class2", vbext_ComponentType.vbext_ct_ClassModule, inputCode2) .Build(); var vbe = builder.AddProject(project).Build(); 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 inspection = new OptionBaseInspection(parser.State); var inspectionResults = inspection.GetInspectionResults(); Assert.AreEqual(1, inspectionResults.Count()); }
public void ProcedureNotUsed_NoResultForClassInitialize() { //Input const string inputCode = @"Private Sub Class_Initialize() End Sub"; //Arrange var builder = new MockVbeBuilder(); var vbe = builder.ProjectBuilder("TestProject", vbext_ProjectProtection.vbext_pp_none) .AddComponent("TestClass", vbext_ComponentType.vbext_ct_ClassModule, inputCode) .MockVbeBuilder().Build(); 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 inspection = new ProcedureNotUsedInspection(parser.State); var inspectionResults = inspection.GetInspectionResults(); Assert.AreEqual(0, inspectionResults.Count()); }
public void ReorderParametersRefactoring_EventParamsSwapped_DifferentParamNames_TwoHandlers() { //Input const string inputCode1 = @"Public Event Foo(ByVal arg1 As Integer, ByVal arg2 As String)"; const string inputCode2 = @"Private WithEvents abc As Class1 Private Sub abc_Foo(ByVal i As Integer, ByVal s As String) End Sub"; const string inputCode3 = @"Private WithEvents abc As Class1 Private Sub abc_Foo(ByVal v1 As Integer, ByVal v2 As String) End Sub"; var selection = new Selection(1, 15, 1, 15); //Expectation const string expectedCode1 = @"Public Event Foo(ByVal arg2 As String, ByVal arg1 As Integer)"; const string expectedCode2 = @"Private WithEvents abc As Class1 Private Sub abc_Foo(ByVal s As String, ByVal i As Integer) End Sub"; // note: IDE removes excess spaces const string expectedCode3 = @"Private WithEvents abc As Class1 Private Sub abc_Foo(ByVal v2 As String, ByVal v1 As Integer) End Sub"; // note: IDE removes excess spaces //Arrange var builder = new MockVbeBuilder(); var project = builder.ProjectBuilder("TestProject1", vbext_ProjectProtection.vbext_pp_none) .AddComponent("Class1", vbext_ComponentType.vbext_ct_ClassModule, inputCode1) .AddComponent("Class2", vbext_ComponentType.vbext_ct_ClassModule, inputCode2) .AddComponent("Class3", vbext_ComponentType.vbext_ct_ClassModule, inputCode3) .Build(); var vbe = builder.AddProject(project).Build(); var component = project.Object.VBComponents.Item(0); 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 module3 = project.Object.VBComponents.Item(2).CodeModule; //Specify Params to remove var model = new ReorderParametersModel(parser.State, qualifiedSelection, null); model.Parameters.Reverse(); //SetupFactory var factory = SetupFactory(model); //Act var refactoring = new ReorderParametersRefactoring(factory.Object, new ActiveCodePaneEditor(vbe.Object, codePaneFactory), null); refactoring.Refactor(qualifiedSelection); //Assert Assert.AreEqual(expectedCode1, module1.Lines()); Assert.AreEqual(expectedCode2, module2.Lines()); Assert.AreEqual(expectedCode3, module3.Lines()); }
public void ReorderParametersRefactoring_ParamsSwapped_RejectPrompt() { //Input const string inputCode1 = @"Implements IClass1 Private Sub IClass1_DoSomething(ByVal a As Integer, ByVal b As String) End Sub"; const string inputCode2 = @"Public Sub DoSomething(ByVal a As Integer, ByVal b As String) End Sub"; var selection = new Selection(3, 23, 3, 27); //Arrange var builder = new MockVbeBuilder(); var project = builder.ProjectBuilder("TestProject1", vbext_ProjectProtection.vbext_pp_none) .AddComponent("Class1", vbext_ComponentType.vbext_ct_ClassModule, inputCode1) .AddComponent("IClass1", vbext_ComponentType.vbext_ct_ClassModule, inputCode2) .Build(); var vbe = builder.AddProject(project).Build(); var component = project.Object.VBComponents.Item(0); 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.No); //Specify Params to remove var model = new ReorderParametersModel(parser.State, qualifiedSelection, messageBox.Object); Assert.IsNull(model.TargetDeclaration); }
public void ReorderParametersRefactoring_InterfaceParamsSwapped_AcceptPrompt() { //Input const string inputCode1 = @"Implements IClass1 Private Sub IClass1_DoSomething(ByVal a As Integer, ByVal b As String) End Sub"; const string inputCode2 = @"Public Sub DoSomething(ByVal a As Integer, ByVal b As String) End Sub"; var selection = new Selection(3, 23, 3, 27); //Expectation const string expectedCode1 = @"Implements IClass1 Private Sub IClass1_DoSomething(ByVal b As String, ByVal a As Integer) End Sub"; // note: IDE removes excess spaces const string expectedCode2 = @"Public Sub DoSomething(ByVal b As String, ByVal a As Integer) End Sub"; //Arrange var builder = new MockVbeBuilder(); var project = builder.ProjectBuilder("TestProject1", vbext_ProjectProtection.vbext_pp_none) .AddComponent("Class1", vbext_ComponentType.vbext_ct_ClassModule, inputCode1) .AddComponent("IClass1", vbext_ComponentType.vbext_ct_ClassModule, inputCode2) .Build(); var vbe = builder.AddProject(project).Build(); var component = project.Object.VBComponents.Item(0); 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.Yes); //Specify Params to remove var model = new ReorderParametersModel(parser.State, qualifiedSelection, messageBox.Object); model.Parameters.Reverse(); //SetupFactory var factory = SetupFactory(model); //Act var refactoring = new ReorderParametersRefactoring(factory.Object, new ActiveCodePaneEditor(vbe.Object, codePaneFactory), null); refactoring.Refactor(qualifiedSelection); //Assert Assert.AreEqual(expectedCode1, module1.Lines()); Assert.AreEqual(expectedCode2, module2.Lines()); }
public void ImplicitByRefParameter_ReturnsResult_InterfaceImplementation() { //Input const string inputCode1 = @"Sub Foo(arg1 As Integer) End Sub"; const string inputCode2 = @"Implements IClass1 Sub IClass1_Foo(arg1 As Integer) End Sub"; //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 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 inspection = new ImplicitByRefParameterInspection(parser.State); var inspectionResults = inspection.GetInspectionResults(); Assert.AreEqual(1, inspectionResults.Count()); }
public void RenameRefactoring_RenameProject() { const string oldName = "TestProject1"; const string newName = "Renamed"; //Arrange var builder = new MockVbeBuilder(); var vbe = builder.ProjectBuilder(oldName, vbext_ProjectProtection.vbext_pp_none) .AddComponent("Module1", vbext_ComponentType.vbext_ct_StdModule, string.Empty) .MockVbeBuilder() .Build(); 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 model = new RenameModel(vbe.Object, parser.State, default(QualifiedSelection), null) { NewName = newName }; model.Target = model.Declarations.First(i => i.DeclarationType == DeclarationType.Project && !i.IsBuiltIn); //SetupFactory var factory = SetupFactory(model); //Act var refactoring = new RenameRefactoring(factory.Object, new ActiveCodePaneEditor(vbe.Object, codePaneFactory), null, parser.State); refactoring.Refactor(model.Target); //Assert Assert.AreEqual(newName, vbe.Object.VBProjects.Item(0).Name); }