Beispiel #1
0
        public void UntypedFunctionUsage_IgnoreQuickFixWorks()
        {
            const string inputCode =
                @"Sub Foo()
    Dim str As String
    str = Left(""test"", 1)
End Sub";

            const string expectedCode =
                @"Sub Foo()
    Dim str As String
'@Ignore UntypedFunctionUsage
    str = Left(""test"", 1)
End Sub";

            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("VBAProject", ProjectProtection.Unprotected)
                          .AddComponent("MyClass", ComponentType.ClassModule, inputCode)
                          .AddReference("VBA", MockVbeBuilder.LibraryPathVBA, 4, 2, true)
                          .Build();
            var vbe = builder.AddProject(project).Build();

            var component = project.Object.VBComponents[0];

            var(parser, rewritingManager) = MockParser.CreateWithRewriteManager(vbe.Object);
            using (var state = parser.State)
            {
                //FIXME reinstate and unignore tests
                //refers to "UntypedFunctionUsageInspectionTests.GetBuiltInDeclarations()"
                //GetBuiltInDeclarations().ForEach(d => state.AddDeclaration(d));

                parser.Parse(new CancellationTokenSource());
                if (state.Status >= ParserState.Error)
                {
                    Assert.Inconclusive("Parser Error");
                }

                var inspection        = new UntypedFunctionUsageInspection(state);
                var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);
                var rewriteSession    = rewritingManager.CheckOutCodePaneSession();

                new IgnoreOnceQuickFix(new AnnotationUpdater(), state, new[] { inspection }).Fix(inspectionResults.First(), rewriteSession);
                var actualCode = rewriteSession.CheckOutModuleRewriter(component.QualifiedModuleName).GetText();

                Assert.AreEqual(expectedCode, actualCode);
            }
        }