|
| 1 | +using System.Linq; |
| 2 | +using System.Threading; |
| 3 | +using NUnit.Framework; |
| 4 | +using Rubberduck.Common; |
| 5 | +using Rubberduck.Parsing.Symbols; |
| 6 | +using Rubberduck.VBEditor; |
| 7 | +using Rubberduck.VBEditor.SafeComWrappers; |
| 8 | +using RubberduckTests.Mocks; |
| 9 | + |
| 10 | +namespace RubberduckTests.Symbols |
| 11 | +{ |
| 12 | + [TestFixture] |
| 13 | + public class DeclarationExtensionTests |
| 14 | + { |
| 15 | + [Test] |
| 16 | + [Category("Resolver")] |
| 17 | + public void FindInterfaceImplementationMembersMatchesDeclarationTypes() |
| 18 | + { |
| 19 | + var intrface = |
| 20 | +@"Option Explicit |
| 21 | +
|
| 22 | +Public Property Get Foo(Bar As Long) As Long |
| 23 | +End Property |
| 24 | +
|
| 25 | +Public Property Let Foo(Bar As Long, NewValue As Long) |
| 26 | +End Property |
| 27 | +"; |
| 28 | + |
| 29 | + var implementation = |
| 30 | +@"Option Explicit |
| 31 | +
|
| 32 | +Implements TestInterface |
| 33 | +
|
| 34 | +Private Property Get TestInterface_Foo(Bar As Long) As Long |
| 35 | +End Property |
| 36 | +
|
| 37 | +Private Property Let TestInterface_Foo(Bar As Long, RHS As Long) |
| 38 | +End Property |
| 39 | +"; |
| 40 | + var vbe = new MockVbeBuilder() |
| 41 | + .ProjectBuilder("UnderTest", ProjectProtection.Unprotected) |
| 42 | + .AddComponent("TestInterface", ComponentType.ClassModule, intrface, new Selection(1, 1)) |
| 43 | + .AddComponent("TestImplementation", ComponentType.ClassModule, implementation, new Selection(1, 1)) |
| 44 | + .AddProjectToVbeBuilder() |
| 45 | + .Build(); |
| 46 | + |
| 47 | + var parser = MockParser.Create(vbe.Object); |
| 48 | + parser.Parse(new CancellationTokenSource()); |
| 49 | + |
| 50 | + var declarations = parser.State.DeclarationFinder.AllDeclarations.ToList(); |
| 51 | + var declaration = declarations.Single(decl => decl.DeclarationType == DeclarationType.PropertyGet && decl.IdentifierName.Equals("Foo")); |
| 52 | + |
| 53 | + var expected = declarations.Single(decl => decl.DeclarationType == DeclarationType.PropertyGet && decl.IdentifierName.Equals("TestInterface_Foo")); |
| 54 | + var actual = declarations.FindInterfaceImplementationMembers(declaration).ToList(); |
| 55 | + var results = actual.Count; |
| 56 | + |
| 57 | + Assert.AreEqual(1, results, "Expected {0} Declarations, received {1}", expected, results); |
| 58 | + Assert.AreEqual(expected, actual.First(), "Expected {0}, resolved to {1}", expected, actual); |
| 59 | + } |
| 60 | + } |
| 61 | +} |
0 commit comments