Skip to content

Commit 531e6dd

Browse files
committed
Add test.
1 parent 74f2064 commit 531e6dd

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

RubberduckTests/RubberduckTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
<Compile Include="Mocks\MockExtentions.cs" />
120120
<Compile Include="Inspections\DefTypeStatementInspectionTests.cs" />
121121
<Compile Include="Inspections\InspectionProviderTests.cs" />
122+
<Compile Include="Symbols\DeclarationExtensionTests.cs" />
122123
<Compile Include="Symbols\ToVbExpressionTests.cs" />
123124
<Compile Include="UnitTesting\TestMethodTests.cs" />
124125
<Compile Include="VBEditor\Utility\DisposalActionContainerTests.cs" />
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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

Comments
 (0)