public void ImplicitActiveWorkbookReference_Ignored_DoesNotReportRange()
        {
            const string inputCode =
                @"
Sub foo()
    Dim sheet As Worksheet

    '@Ignore ImplicitActiveWorkbookReference
    Set sheet = Worksheets(""Sheet1"")
End Sub";

            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("TestProject1", "TestProject1", ProjectProtection.Unprotected)
                          .AddComponent("Class1", ComponentType.ClassModule, inputCode)
                          .AddReference("Excel", MockVbeBuilder.LibraryPathMsExcel, 1, 8, true)
                          .Build();
            var vbe = builder.AddProject(project).Build();


            var parser = MockParser.Create(vbe.Object, new RubberduckParserState(vbe.Object));

            parser.State.AddTestLibrary("Excel.1.8.xml");

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

            var inspection        = new ImplicitActiveWorkbookReferenceInspection(parser.State);
            var inspectionResults = inspection.GetInspectionResults();

            Assert.AreEqual(0, inspectionResults.Count());
        }
コード例 #2
0
        public void ImplicitActiveWorkbookReference_IgnoreQuickFixWorks()
        {
            const string inputCode =
                @"
Sub foo()
    Dim sheet As Worksheet
    Set sheet = Worksheets(""Sheet1"")
End Sub";

            const string expectedCode =
                @"
Sub foo()
    Dim sheet As Worksheet
'@Ignore ImplicitActiveWorkbookReference
    Set sheet = Worksheets(""Sheet1"")
End Sub";

            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("TestProject1", "TestProject1", ProjectProtection.Unprotected)
                          .AddComponent("Class1", ComponentType.ClassModule, inputCode)
                          .AddReference("Excel", MockVbeBuilder.LibraryPathMsExcel, 1, 8, true)
                          .Build();
            var component = project.Object.VBComponents[0];
            var vbe       = builder.AddProject(project).Build();

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var inspection        = new ImplicitActiveWorkbookReferenceInspection(state);
                var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);

                new IgnoreOnceQuickFix(state, new[] { inspection }).Fix(inspectionResults.First());
                Assert.AreEqual(expectedCode, state.GetRewriter(component).GetText());
            }
        }
        public void InspectionName()
        {
            const string inspectionName = "ImplicitActiveWorkbookReferenceInspection";
            var          inspection     = new ImplicitActiveWorkbookReferenceInspection(null);

            Assert.AreEqual(inspectionName, inspection.Name);
        }
        public void ImplicitActiveWorkbookReference_Ignored_DoesNotReportRange()
        {
            const string inputCode =
                @"
Sub foo()
    Dim sheet As Worksheet

    '@Ignore ImplicitActiveWorkbookReference
    Set sheet = Worksheets(""Sheet1"")
End Sub";

            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("TestProject1", "TestProject1", ProjectProtection.Unprotected)
                          .AddComponent("Class1", ComponentType.ClassModule, inputCode)
                          .AddReference("Excel", MockVbeBuilder.LibraryPathMsExcel, 1, 8, true)
                          .Build();
            var vbe = builder.AddProject(project).Build();


            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var inspection        = new ImplicitActiveWorkbookReferenceInspection(state);
                var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);

                Assert.AreEqual(0, inspectionResults.Count());
            }
        }
        private int ArrangeAndGetInspectionCount(string code)
        {
            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("TestProject1", "TestProject1", ProjectProtection.Unprotected)
                          .AddComponent("Module1", ComponentType.StandardModule, code)
                          .AddReference("Excel", MockVbeBuilder.LibraryPathMsExcel, 1, 8, true)
                          .Build();
            var vbe = builder.AddProject(project).Build();


            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var inspection        = new ImplicitActiveWorkbookReferenceInspection(state);
                var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);

                return(inspectionResults.Count());
            }
        }
コード例 #6
0
        public void ImplicitActiveWorkbookReference_IgnoreQuickFixWorks()
        {
            const string inputCode =
                @"
Sub foo()
    Dim sheet As Worksheet
    Set sheet = Worksheets(""Sheet1"")
End Sub";

            const string expectedCode =
                @"
Sub foo()
    Dim sheet As Worksheet
'@Ignore ImplicitActiveWorkbookReference
    Set sheet = Worksheets(""Sheet1"")
End Sub";

            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("TestProject1", "TestProject1", ProjectProtection.Unprotected)
                          .AddComponent("Class1", ComponentType.ClassModule, inputCode)
                          .AddReference("Excel", MockVbeBuilder.LibraryPathMsExcel, 1, 8, true)
                          .Build();
            var component = project.Object.VBComponents[0];
            var vbe       = builder.AddProject(project).Build();


            var parser = MockParser.Create(vbe.Object);

            parser.State.AddTestLibrary("Excel.1.8.xml");

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

            var inspection        = new ImplicitActiveWorkbookReferenceInspection(parser.State);
            var inspectionResults = inspection.GetInspectionResults();

            new IgnoreOnceQuickFix(parser.State, new[] { inspection }).Fix(inspectionResults.First());
            Assert.AreEqual(expectedCode, parser.State.GetRewriter(component).GetText());
        }
        public void InspectionType()
        {
            var inspection = new ImplicitActiveWorkbookReferenceInspection(null);

            Assert.AreEqual(CodeInspectionType.MaintainabilityAndReadabilityIssues, inspection.InspectionType);
        }
        public void InspectionType()
        {
            var inspection = new ImplicitActiveWorkbookReferenceInspection(null);

            Assert.AreEqual(CodeInspectionType.LanguageOpportunities, inspection.InspectionType);
        }