public void GivenPrivateSub_DefaultQuickFixRemovesParameter() { const string inputCode = @" Private Sub Foo(ByVal arg1 as Integer) End Sub"; const string expectedCode = @" Private Sub Foo() End Sub"; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out var component); var(state, rewritingManager) = MockParser.CreateAndParseWithRewritingManager(vbe.Object); using (state) { var inspection = new ParameterNotUsedInspection(state); var inspectionResults = inspection.GetInspectionResults(CancellationToken.None); var rewriteSession = rewritingManager.CheckOutCodePaneSession(); var selectionService = MockedSelectionService(); new RemoveUnusedParameterQuickFix(state, new Mock <IRefactoringPresenterFactory>().Object, rewritingManager, selectionService) .Fix(inspectionResults.First(), rewriteSession); Assert.AreEqual(expectedCode, component.CodeModule.Content()); } }
public void GivenPrivateSub_DefaultQuickFixRemovesParameter() { const string inputCode = @" Private Sub Foo(ByVal arg1 as Integer) End Sub"; const string expectedCode = @" Private Sub Foo() End Sub"; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out var component); var(state, rewritingManager) = MockParser.CreateAndParseWithRewritingManager(vbe.Object); using (state) { var inspection = new ParameterNotUsedInspection(state); var inspectionResults = inspection.GetInspectionResults(CancellationToken.None); var rewriteSession = rewritingManager.CheckOutCodePaneSession(); var selectionService = MockedSelectionService(); var factory = new Mock <IRefactoringPresenterFactory>().Object; var selectedDeclarationProvider = new SelectedDeclarationProvider(selectionService, state); var uiDispatcherMock = new Mock <IUiDispatcher>(); uiDispatcherMock .Setup(m => m.Invoke(It.IsAny <Action>())) .Callback((Action action) => action.Invoke()); var refactoring = new RemoveParametersRefactoring(state, factory, rewritingManager, selectionService, selectedDeclarationProvider, uiDispatcherMock.Object); new RemoveUnusedParameterQuickFix(refactoring) .Fix(inspectionResults.First(), rewriteSession); Assert.AreEqual(expectedCode, component.CodeModule.Content()); } }
public void ParameterNotUsed_ReturnsResult_InterfaceImplementation() { //Input const string inputCode1 = @"Public Sub DoSomething(ByVal a As Integer) End Sub"; const string inputCode2 = @"Implements IClass1 Private Sub IClass1_DoSomething(ByVal a As Integer) 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(); using (var state = MockParser.CreateAndParse(vbe.Object)) { var inspection = new ParameterNotUsedInspection(state); var inspectionResults = inspection.GetInspectionResults(CancellationToken.None).ToList(); Assert.AreEqual(1, inspectionResults.Count); } }
public void InspectionName() { const string inspectionName = "ParameterNotUsedInspection"; var inspection = new ParameterNotUsedInspection(null); Assert.AreEqual(inspectionName, inspection.Name); }
public void ParameterUsed_DoesNotReturnResult() { const string inputCode = @"Private Sub Foo(ByVal arg1 as Integer) arg1 = 9 End Sub"; //Arrange var builder = new MockVbeBuilder(); VBComponent component; var vbe = builder.BuildFromSingleStandardModule(inputCode, out component); 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 ParameterNotUsedInspection(vbe.Object, parser.State, null); var inspectionResults = inspection.GetInspectionResults(); Assert.AreEqual(0, inspectionResults.Count()); }
public void ParameterNotUsed_Ignored_DoesNotReturnResult() { const string inputCode = @"'@Ignore ParameterNotUsed Private Sub Foo(ByVal arg1 as Integer) End Sub"; //Arrange var builder = new MockVbeBuilder(); VBComponent component; var vbe = builder.BuildFromSingleStandardModule(inputCode, out component); var mockHost = new Mock <IHostApplication>(); mockHost.SetupAllProperties(); var parser = MockParser.Create(vbe.Object, new RubberduckParserState(new Mock <ISinks>().Object)); parser.Parse(new CancellationTokenSource()); if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); } var inspection = new ParameterNotUsedInspection(parser.State, null); var inspectionResults = inspection.GetInspectionResults(); Assert.IsFalse(inspectionResults.Any()); }
public void ParameterNotUsed_QuickFixWorks() { const string inputCode = @"Private Sub Foo(ByVal arg1 as Integer) End Sub"; const string expectedCode = @"Private Sub Foo() 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 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 ParameterNotUsedInspection(vbe.Object, parser.State, null); var inspectionResults = inspection.GetInspectionResults(); inspectionResults.First().QuickFixes.First().Fix(); Assert.AreEqual(expectedCode, module.Lines()); }
public void ParameterNotUsed_ReturnsResult() { const string inputCode = @"Private Sub Foo(ByVal arg1 as Integer) End Sub"; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _); var state = MockParser.CreateAndParse(vbe.Object); var inspection = new ParameterNotUsedInspection(state); var inspectionResults = inspection.GetInspectionResults(); Assert.AreEqual(1, inspectionResults.Count()); }
public void ParameterNotUsed_Ignored_DoesNotReturnResult() { const string inputCode = @"'@Ignore ParameterNotUsed Private Sub Foo(ByVal arg1 as Integer) End Sub"; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _); var state = MockParser.CreateAndParse(vbe.Object); var inspection = new ParameterNotUsedInspection(state); var inspectionResults = inspection.GetInspectionResults(); Assert.IsFalse(inspectionResults.Any()); }
public void ParameterNotUsed_ReturnsResult_SomeParamsUsed() { const string inputCode = @"Private Sub Foo(ByVal arg1 as Integer, ByVal arg2 as String) arg1 = 9 End Sub"; IVBComponent component; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out component); var state = MockParser.CreateAndParse(vbe.Object); var inspection = new ParameterNotUsedInspection(state, null); var inspectionResults = inspection.GetInspectionResults(); Assert.AreEqual(1, inspectionResults.Count()); }
public void ParameterUsed_DoesNotReturnResult() { const string inputCode = @"Private Sub Foo(ByVal arg1 as Integer) arg1 = 9 End Sub"; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _); using (var state = MockParser.CreateAndParse(vbe.Object)) { var inspection = new ParameterNotUsedInspection(state); var inspectionResults = inspection.GetInspectionResults(CancellationToken.None); Assert.AreEqual(0, inspectionResults.Count()); } }
public void GivenPrivateSub_DefaultQuickFixRemovesParameter() { const string inputCode = @" Private Sub Foo(ByVal arg1 as Integer) End Sub"; const string expectedCode = @" Private Sub Foo() End Sub"; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out var component); var state = MockParser.CreateAndParse(vbe.Object); var inspection = new ParameterNotUsedInspection(state); var inspectionResults = inspection.GetInspectionResults(); new RemoveUnusedParameterQuickFix(vbe.Object, state, new Mock <IMessageBox>().Object).Fix( inspectionResults.First()); Assert.AreEqual(expectedCode, component.CodeModule.Content()); }
public void GivenPrivateSub_IgnoreQuickFixWorks() { const string inputCode = @"Private Sub Foo(ByVal arg1 as Integer) End Sub"; const string expectedCode = @"'@Ignore ParameterNotUsed Private Sub Foo(ByVal arg1 as Integer) End Sub"; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out var component); var state = MockParser.CreateAndParse(vbe.Object); var inspection = new ParameterNotUsedInspection(state); var inspectionResults = inspection.GetInspectionResults(); new IgnoreOnceQuickFix(state, new[] { inspection }).Fix(inspectionResults.First()); Assert.AreEqual(expectedCode, state.GetRewriter(component).GetText()); }
public void GivenPrivateSub_IgnoreQuickFixWorks() { const string inputCode = @"Private Sub Foo(ByVal arg1 as Integer) End Sub"; const string expectedCode = @"'@Ignore ParameterNotUsed Private Sub Foo(ByVal arg1 as Integer) End Sub"; IVBComponent component; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out component); var state = MockParser.CreateAndParse(vbe.Object); var inspection = new ParameterNotUsedInspection(state, null); var inspectionResults = inspection.GetInspectionResults(); inspectionResults.First().QuickFixes.Single(s => s is IgnoreOnceQuickFix).Fix(); Assert.AreEqual(expectedCode, component.CodeModule.Content()); }
public void ParameterNotUsed_ReturnsResult_InterfaceImplementation() { //Input const string inputCode1 = @"Public Sub DoSomething(ByVal a As Integer) End Sub"; const string inputCode2 = @"Implements IClass1 Private Sub IClass1_DoSomething(ByVal a 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 ParameterNotUsedInspection(vbe.Object, parser.State, null); var inspectionResults = inspection.GetInspectionResults(); Assert.AreEqual(1, inspectionResults.Count()); }
public void ParameterNotUsed_AmbiguousName_DoesNotReturnResult() { const string inputCode = @" Public Property Get Item() Item = 12 End Property Public Property Let Item(ByVal Item As Variant) DoSomething Item End Property Private Sub DoSomething(ByVal value As Variant) Msgbox(value) End Sub"; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _); using (var state = MockParser.CreateAndParse(vbe.Object)) { var inspection = new ParameterNotUsedInspection(state); var inspectionResults = inspection.GetInspectionResults(CancellationToken.None); Assert.IsFalse(inspectionResults.Any()); } }
public void InspectionType() { var inspection = new ParameterNotUsedInspection(null); Assert.AreEqual(CodeInspectionType.CodeQualityIssues, inspection.InspectionType); }