|
| 1 | +using System.Linq; |
| 2 | +using Microsoft.Vbe.Interop; |
| 3 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 4 | +using Moq; |
| 5 | +using Rubberduck.Inspections; |
| 6 | +using Rubberduck.Parsing.VBA; |
| 7 | +using Rubberduck.VBEditor.VBEHost; |
| 8 | +using Rubberduck.VBEditor.VBEInterfaces.RubberduckCodePane; |
| 9 | +using RubberduckTests.Mocks; |
| 10 | + |
| 11 | +namespace RubberduckTests |
| 12 | +{ |
| 13 | + [TestClass] |
| 14 | + public class RubberduckParserTests |
| 15 | + { |
| 16 | + [TestMethod] |
| 17 | + public void ParseResultDeclarations_IncludeVbaStandardLibDeclarations() |
| 18 | + { |
| 19 | + //Arrange |
| 20 | + var builder = new MockVbeBuilder(); |
| 21 | + var project = builder.ProjectBuilder("TestProject1", vbext_ProjectProtection.vbext_pp_none) |
| 22 | + .AddComponent("Class1", vbext_ComponentType.vbext_ct_ClassModule, "") |
| 23 | + .Build().Object; |
| 24 | + |
| 25 | + var codePaneFactory = new CodePaneWrapperFactory(); |
| 26 | + var mockHost = new Mock<IHostApplication>(); |
| 27 | + mockHost.SetupAllProperties(); |
| 28 | + |
| 29 | + //Act |
| 30 | + var parseResult = new RubberduckParser(codePaneFactory, project.VBE).Parse(project); |
| 31 | + |
| 32 | + //Assert |
| 33 | + Assert.IsTrue(parseResult.Declarations.Items.Any(item => item.IsBuiltIn)); |
| 34 | + } |
| 35 | + |
| 36 | + [TestMethod] |
| 37 | + public void ParseResultDeclarations_MockHost_ExcludeExcelDeclarations() |
| 38 | + { |
| 39 | + //Arrange |
| 40 | + var builder = new MockVbeBuilder(); |
| 41 | + var project = builder.ProjectBuilder("TestProject1", vbext_ProjectProtection.vbext_pp_none) |
| 42 | + .AddComponent("Class1", vbext_ComponentType.vbext_ct_ClassModule, "") |
| 43 | + .Build().Object; |
| 44 | + |
| 45 | + var codePaneFactory = new CodePaneWrapperFactory(); |
| 46 | + var mockHost = new Mock<IHostApplication>(); |
| 47 | + mockHost.SetupAllProperties(); |
| 48 | + |
| 49 | + //Act |
| 50 | + var parseResult = new RubberduckParser(codePaneFactory, project.VBE).Parse(project); |
| 51 | + |
| 52 | + //Assert |
| 53 | + Assert.IsFalse(parseResult.Declarations.Items.Any(item => item.IsBuiltIn && item.ParentScope.StartsWith("Excel"))); |
| 54 | + } |
| 55 | + |
| 56 | + [TestMethod] |
| 57 | + public void ParseResultDeclarations_ExcelHost_IncludesExcelDeclarations() |
| 58 | + { |
| 59 | + //Arrange |
| 60 | + var builder = new MockVbeBuilder(); |
| 61 | + var project = builder.ProjectBuilder("TestProject1", vbext_ProjectProtection.vbext_pp_none) |
| 62 | + .AddComponent("Class1", vbext_ComponentType.vbext_ct_ClassModule, "") |
| 63 | + .AddReference("Excel", @"C:\Program Files\Microsoft Office\Office14\EXCEL.EXE", true) |
| 64 | + .Build(); |
| 65 | + var vbe = builder.AddProject(project).Build(); |
| 66 | + |
| 67 | + var codePaneFactory = new CodePaneWrapperFactory(); |
| 68 | + |
| 69 | + //Act |
| 70 | + var parseResult = new RubberduckParser(codePaneFactory, vbe.Object).Parse(project.Object); |
| 71 | + |
| 72 | + //Assert |
| 73 | + Assert.IsTrue(parseResult.Declarations.Items.Any(item => item.IsBuiltIn && item.ParentScope.StartsWith("Excel"))); |
| 74 | + } |
| 75 | + } |
| 76 | +} |
0 commit comments