2
2
using System . Runtime . InteropServices ;
3
3
using Microsoft . Vbe . Interop ;
4
4
using Rubberduck . Parsing . Annotations ;
5
+ using Rubberduck . Parsing . Symbols ;
5
6
using Rubberduck . Parsing . VBA ;
6
7
using Rubberduck . UI ;
7
8
@@ -67,11 +68,12 @@ public void NewTestMethod()
67
68
68
69
try
69
70
{
70
- var declaration = _state . AllUserDeclarations . First ( f =>
71
- f . DeclarationType == Parsing . Symbols . DeclarationType . ProceduralModule &&
71
+ var declaration = _state . AllUserDeclarations . FirstOrDefault ( f =>
72
72
f . QualifiedName . QualifiedModuleName . Component . CodeModule == _vbe . ActiveCodePane . CodeModule ) ;
73
73
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 ) )
75
77
{
76
78
var module = _vbe . ActiveCodePane . CodeModule ;
77
79
var name = GetNextTestMethodName ( module . Parent ) ;
@@ -95,11 +97,12 @@ public void NewExpectedErrorTestMethod()
95
97
96
98
try
97
99
{
98
- var declaration = _state . AllUserDeclarations . First ( f =>
99
- f . DeclarationType == Parsing . Symbols . DeclarationType . ProceduralModule &&
100
+ var declaration = _state . AllUserDeclarations . FirstOrDefault ( f =>
100
101
f . QualifiedName . QualifiedModuleName . Component . CodeModule == _vbe . ActiveCodePane . CodeModule ) ;
101
102
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 ) )
103
106
{
104
107
var module = _vbe . ActiveCodePane . CodeModule ;
105
108
var name = GetNextTestMethodName ( module . Parent ) ;
0 commit comments