Skip to content

Commit b1d5661

Browse files
committed
Incorporated InspectionTestsBase and test cases
1 parent d4c3f2b commit b1d5661

File tree

1 file changed

+38
-10
lines changed

1 file changed

+38
-10
lines changed

RubberduckTests/Inspections/ImplementedInterfaceMemberInspectionTests.cs

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
using RubberduckTests.Mocks;
55
using Rubberduck.Inspections.Concrete;
66
using Rubberduck.VBEditor.SafeComWrappers;
7+
using Rubberduck.Parsing.Inspections.Abstract;
8+
using Rubberduck.Parsing.VBA;
79

810
namespace RubberduckTests.Inspections
911
{
1012
[TestFixture]
11-
public class ImplementedInterfaceMemberInspectionTests
13+
public class ImplementedInterfaceMemberInspectionTests : InspectionTestsBase
1214
{
1315
[Test]
1416
[Category("Inspections")]
@@ -120,6 +122,35 @@ Sub IClass1_Qux()
120122
CheckActualEmptyBlockCountEqualsExpected(interfaceCode, concreteCode, 1);
121123
}
122124

125+
//https://github.com/rubberduck-vba/Rubberduck/issues/5143
126+
[TestCase(@"MsgBox ""?""","", 1)] //No implementers, only the annotation marks interface class
127+
[TestCase("", "", 0)] //Annotated only, but no implementers - no result
128+
[TestCase(@"MsgBox ""?""", "Implements IClass1", 1)] //Annotated and an Implementer yields a single inspection result
129+
[Category("Inspections")]
130+
public void ImplementedInterfaceMember_AnnotatedOnly_ReturnsResult(string interfaceBody, string implementsStatement, int expected)
131+
{
132+
string interfaceCode =
133+
$@"
134+
'@Interface
135+
136+
Public Sub DoSomething(ByVal a As Integer)
137+
End Sub
138+
Public Sub DoSomethingElse(ByVal a As Integer)
139+
{interfaceBody}
140+
End Sub";
141+
string concreteCode =
142+
$@"
143+
144+
{implementsStatement}
145+
146+
Private Sub IClass_DoSomething(ByVal a As Integer)
147+
MsgBox ""?""
148+
End Sub
149+
Public Sub IClass_DoSomethingElse(ByVal a As Integer)
150+
End Sub";
151+
CheckActualEmptyBlockCountEqualsExpected(interfaceCode, concreteCode, expected);
152+
}
153+
123154
private void CheckActualEmptyBlockCountEqualsExpected(string interfaceCode, string concreteCode, int expectedCount)
124155
{
125156
var builder = new MockVbeBuilder();
@@ -129,16 +160,13 @@ private void CheckActualEmptyBlockCountEqualsExpected(string interfaceCode, stri
129160
.Build();
130161
var vbe = builder.AddProject(project).Build();
131162

132-
using (var state = MockParser.CreateAndParse(vbe.Object))
133-
{
134-
135-
var inspection = new ImplementedInterfaceMemberInspection(state);
136-
var inspector = InspectionsHelper.GetInspector(inspection);
137-
var actualResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result;
138-
139-
Assert.AreEqual(expectedCount, actualResults.Count());
140-
}
163+
var inspectionResults = InspectionResults(vbe.Object);
164+
Assert.AreEqual(expectedCount, inspectionResults.Count());
165+
}
141166

167+
protected override IInspection InspectionUnderTest(RubberduckParserState state)
168+
{
169+
return new ImplementedInterfaceMemberInspection(state);
142170
}
143171
}
144172
}

0 commit comments

Comments
 (0)