public void ProviderCallsNotifierOnFailureToRewrite() { const string inputCode = @"Public Sub Foo() Dim str As String str = """" End Sub"; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out var component); var(state, rewritingManager) = MockParser.CreateAndParseWithRewritingManager(vbe.Object); using (state) { var inspection = new EmptyStringLiteralInspection(state); var inspector = InspectionsHelper.GetInspector(inspection); var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result; var inspectionResult = inspectionResults.First(); var failureNotifierMock = new Mock <IQuickFixFailureNotifier>(); var quickFixProvider = new QuickFixProvider(rewritingManager, failureNotifierMock.Object, new IQuickFix[] { new ReplaceEmptyStringLiteralStatementQuickFix() }); var quickFix = quickFixProvider.QuickFixes(inspectionResult).First(); //Make rewrite fail. component.CodeModule.InsertLines(1, "'afejfaofef"); quickFixProvider.Fix(quickFix, inspectionResult); failureNotifierMock.Verify(m => m.NotifyQuickFixExecutionFailure(RewriteSessionState.StaleParseTree)); } }
public void ProviderDoesNotKnowAboutInspection() { const string inputCode = @"Public Sub Foo() Const const1 As Integer = 9 End Sub"; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _); var state = MockParser.CreateAndParse(vbe.Object); var inspection = new ConstantNotUsedInspection(state); var inspectionResults = inspection.GetInspectionResults(); var quickFixProvider = new QuickFixProvider(state, new IQuickFix[] { }); Assert.AreEqual(0, quickFixProvider.QuickFixes(inspectionResults.First()).Count()); }
public void ProviderKnowsAboutInspection() { const string inputCode = @"Public Sub Foo() Dim str As String str = """" End Sub"; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _); var state = MockParser.CreateAndParse(vbe.Object); var inspection = new EmptyStringLiteralInspection(state); var inspector = InspectionsHelper.GetInspector(inspection); var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result; var quickFixProvider = new QuickFixProvider(state, new IQuickFix[] { new ReplaceEmptyStringLiteralStatementQuickFix(state) }); Assert.AreEqual(1, quickFixProvider.QuickFixes(inspectionResults.First()).Count()); }
public void ProviderDoesNotKnowAboutInspection() { const string inputCode = @"Public Sub Foo() Const const1 As Integer = 9 End Sub"; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _); var(state, rewritingManager) = MockParser.CreateAndParseWithRewritingManager(vbe.Object); using (state) { var inspection = new ConstantNotUsedInspection(state); var inspectionResults = inspection.GetInspectionResults(CancellationToken.None); var failureNotifier = new Mock <IQuickFixFailureNotifier>().Object; var quickFixProvider = new QuickFixProvider(rewritingManager, failureNotifier, new IQuickFix[] { }); Assert.AreEqual(0, quickFixProvider.QuickFixes(inspectionResults.First()).Count()); } }
public void ResultDisablesFix() { const string inputCode = @"Public Sub Foo() Const const1 As Integer = 9 End Sub"; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _); var state = MockParser.CreateAndParse(vbe.Object); var inspection = new ConstantNotUsedInspection(state); var inspectionResults = inspection.GetInspectionResults(); var quickFixProvider = new QuickFixProvider(state, new IQuickFix[] { new RemoveUnusedDeclarationQuickFix(state) }); var result = inspectionResults.First(); result.Properties.Add("DisableFixes", nameof(RemoveUnusedDeclarationQuickFix)); Assert.AreEqual(0, quickFixProvider.QuickFixes(result).Count()); }
public void ResultDisablesFix() { const string inputCode = @"Public Sub Foo() Const const1 As Integer = 9 End Sub"; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out _); var(state, rewritingManager) = MockParser.CreateAndParseWithRewritingManager(vbe.Object); using (state) { var inspection = new ConstantNotUsedInspection(state); var inspectionResults = inspection.GetInspectionResults(CancellationToken.None); var failureNotifier = new Mock <IQuickFixFailureNotifier>().Object; var quickFixProvider = new QuickFixProvider(rewritingManager, failureNotifier, new IQuickFix[] { new RemoveUnusedDeclarationQuickFix() }); var result = inspectionResults.First(); result.Properties.DisableFixes = nameof(RemoveUnusedDeclarationQuickFix); Assert.AreEqual(0, quickFixProvider.QuickFixes(result).Count()); } }