22using System . Runtime . InteropServices ;
33using Microsoft . Vbe . Interop ;
44using Rubberduck . Parsing . Annotations ;
5+ using Rubberduck . Parsing . Symbols ;
56using Rubberduck . Parsing . VBA ;
67using Rubberduck . UI ;
78
@@ -67,11 +68,12 @@ public void NewTestMethod()
6768
6869 try
6970 {
70- var declaration = _state . AllUserDeclarations . First ( f =>
71- f . DeclarationType == Parsing . Symbols . DeclarationType . ProceduralModule &&
71+ var declaration = _state . AllUserDeclarations . FirstOrDefault ( f =>
7272 f . QualifiedName . QualifiedModuleName . Component . CodeModule == _vbe . ActiveCodePane . CodeModule ) ;
7373
74- if ( declaration . Annotations . Any ( a => a . AnnotationType == AnnotationType . TestModule ) )
74+ if ( declaration != null &&
75+ declaration . DeclarationType == DeclarationType . ProceduralModule &&
76+ declaration . Annotations . Any ( a => a . AnnotationType == AnnotationType . TestModule ) )
7577 {
7678 var module = _vbe . ActiveCodePane . CodeModule ;
7779 var name = GetNextTestMethodName ( module . Parent ) ;
@@ -95,11 +97,12 @@ public void NewExpectedErrorTestMethod()
9597
9698 try
9799 {
98- var declaration = _state . AllUserDeclarations . First ( f =>
99- f . DeclarationType == Parsing . Symbols . DeclarationType . ProceduralModule &&
100+ var declaration = _state . AllUserDeclarations . FirstOrDefault ( f =>
100101 f . QualifiedName . QualifiedModuleName . Component . CodeModule == _vbe . ActiveCodePane . CodeModule ) ;
101102
102- if ( declaration . Annotations . Any ( a => a . AnnotationType == AnnotationType . TestModule ) )
103+ if ( declaration != null &&
104+ declaration . DeclarationType == DeclarationType . ProceduralModule &&
105+ declaration . Annotations . Any ( a => a . AnnotationType == AnnotationType . TestModule ) )
103106 {
104107 var module = _vbe . ActiveCodePane . CodeModule ;
105108 var name = GetNextTestMethodName ( module . Parent ) ;
0 commit comments