1
+ using System . Collections . Generic ;
1
2
using System . Linq ;
2
3
using System . Threading ;
3
4
using NUnit . Framework ;
4
5
using Rubberduck . Inspections . Concrete ;
6
+ using Rubberduck . Parsing . Inspections . Abstract ;
5
7
using Rubberduck . Parsing . VBA ;
6
8
using Rubberduck . VBEditor . SafeComWrappers ;
7
9
using RubberduckTests . Mocks ;
8
10
9
11
namespace RubberduckTests . Inspections
10
12
{
11
13
[ TestFixture ]
12
- public class ApplicationWorksheetFunctionInspectionTests
14
+ public class ApplicationWorksheetFunctionInspectionTests : InspectionTestsBase
13
15
{
14
- private static RubberduckParserState ArrangeParserAndParse ( string inputCode )
16
+ private IEnumerable < IInspectionResult > GetInspectionResultsUsingExcelLibrary ( string inputCode )
15
17
{
16
18
var builder = new MockVbeBuilder ( ) ;
17
19
var project = builder . ProjectBuilder ( "VBAProject" , ProjectProtection . Unprotected )
18
20
. AddComponent ( "Module1" , ComponentType . StandardModule , inputCode )
19
21
. AddReference ( "Excel" , MockVbeBuilder . LibraryPathMsExcel , 1 , 8 , true )
20
22
. Build ( ) ;
21
23
22
- var vbe = builder . AddProject ( project ) . Build ( ) ;
23
-
24
- return MockParser . CreateAndParse ( vbe . Object ) ; ;
24
+ var vbe = builder . AddProject ( project ) . Build ( ) . Object ;
25
+ return InspectionResults ( vbe ) ;
25
26
}
26
27
27
28
[ Test ]
@@ -34,15 +35,7 @@ Dim foo As Double
34
35
foo = Application.Pi
35
36
End Sub
36
37
" ;
37
-
38
- using ( var state = ArrangeParserAndParse ( inputCode ) )
39
- {
40
-
41
- var inspection = new ApplicationWorksheetFunctionInspection ( state ) ;
42
- var inspectionResults = inspection . GetInspectionResults ( CancellationToken . None ) ;
43
-
44
- Assert . AreEqual ( 1 , inspectionResults . Count ( ) ) ;
45
- }
38
+ Assert . AreEqual ( 1 , GetInspectionResultsUsingExcelLibrary ( inputCode ) . Count ( ) ) ;
46
39
}
47
40
48
41
[ Test ]
@@ -57,15 +50,7 @@ With Application
57
50
End With
58
51
End Sub
59
52
" ;
60
-
61
- using ( var state = ArrangeParserAndParse ( inputCode ) )
62
- {
63
-
64
- var inspection = new ApplicationWorksheetFunctionInspection ( state ) ;
65
- var inspectionResults = inspection . GetInspectionResults ( CancellationToken . None ) ;
66
-
67
- Assert . AreEqual ( 1 , inspectionResults . Count ( ) ) ;
68
- }
53
+ Assert . AreEqual ( 1 , GetInspectionResultsUsingExcelLibrary ( inputCode ) . Count ( ) ) ;
69
54
}
70
55
71
56
[ Test ]
@@ -80,15 +65,7 @@ Dim xlApp as Excel.Application
80
65
foo = xlApp.Pi
81
66
End Sub
82
67
" ;
83
-
84
- using ( var state = ArrangeParserAndParse ( inputCode ) )
85
- {
86
-
87
- var inspection = new ApplicationWorksheetFunctionInspection ( state ) ;
88
- var inspectionResults = inspection . GetInspectionResults ( CancellationToken . None ) ;
89
-
90
- Assert . AreEqual ( 1 , inspectionResults . Count ( ) ) ;
91
- }
68
+ Assert . AreEqual ( 1 , GetInspectionResultsUsingExcelLibrary ( inputCode ) . Count ( ) ) ;
92
69
}
93
70
94
71
[ Test ]
@@ -105,15 +82,7 @@ With xlApp
105
82
End With
106
83
End Sub
107
84
" ;
108
-
109
- using ( var state = ArrangeParserAndParse ( inputCode ) )
110
- {
111
-
112
- var inspection = new ApplicationWorksheetFunctionInspection ( state ) ;
113
- var inspectionResults = inspection . GetInspectionResults ( CancellationToken . None ) ;
114
-
115
- Assert . AreEqual ( 1 , inspectionResults . Count ( ) ) ;
116
- }
85
+ Assert . AreEqual ( 1 , GetInspectionResultsUsingExcelLibrary ( inputCode ) . Count ( ) ) ;
117
86
}
118
87
119
88
[ Test ]
@@ -126,15 +95,7 @@ Dim foo As Double
126
95
foo = Application.WorksheetFunction.Pi
127
96
End Sub
128
97
" ;
129
-
130
- using ( var state = ArrangeParserAndParse ( inputCode ) )
131
- {
132
-
133
- var inspection = new ApplicationWorksheetFunctionInspection ( state ) ;
134
- var inspectionResults = inspection . GetInspectionResults ( CancellationToken . None ) ;
135
-
136
- Assert . IsFalse ( inspectionResults . Any ( ) ) ;
137
- }
98
+ Assert . AreEqual ( 0 , GetInspectionResultsUsingExcelLibrary ( inputCode ) . Count ( ) ) ;
138
99
}
139
100
140
101
[ Test ]
@@ -149,15 +110,7 @@ Dim xlApp as Excel.Application
149
110
foo = xlApp.WorksheetFunction.Pi
150
111
End Sub
151
112
" ;
152
-
153
- using ( var state = ArrangeParserAndParse ( inputCode ) )
154
- {
155
-
156
- var inspection = new ApplicationWorksheetFunctionInspection ( state ) ;
157
- var inspectionResults = inspection . GetInspectionResults ( CancellationToken . None ) ;
158
-
159
- Assert . IsFalse ( inspectionResults . Any ( ) ) ;
160
- }
113
+ Assert . AreEqual ( 0 , GetInspectionResultsUsingExcelLibrary ( inputCode ) . Count ( ) ) ;
161
114
}
162
115
163
116
[ Test ]
@@ -170,25 +123,7 @@ Dim foo As Double
170
123
foo = Application.Pi
171
124
End Sub
172
125
" ;
173
- var builder = new MockVbeBuilder ( ) ;
174
- var project = builder . ProjectBuilder ( "VBAProject" , ProjectProtection . Unprotected )
175
- . AddComponent ( "Module1" , ComponentType . StandardModule , inputCode )
176
- . Build ( ) ;
177
-
178
- var vbe = builder . AddProject ( project ) . Build ( ) ;
179
-
180
- using ( var state = MockParser . CreateAndParse ( vbe . Object ) )
181
- {
182
- if ( state . Status >= ParserState . Error )
183
- {
184
- Assert . Inconclusive ( "Parser Error" ) ;
185
- }
186
-
187
- var inspection = new ApplicationWorksheetFunctionInspection ( state ) ;
188
- var inspectionResults = inspection . GetInspectionResults ( CancellationToken . None ) ;
189
-
190
- Assert . IsFalse ( inspectionResults . Any ( ) ) ;
191
- }
126
+ Assert . AreEqual ( 0 , InspectionResultsForStandardModule ( inputCode ) . Count ( ) ) ;
192
127
}
193
128
194
129
[ Test ]
@@ -202,15 +137,7 @@ Dim foo As Double
202
137
foo = Application.Pi
203
138
End Sub
204
139
" ;
205
-
206
- using ( var state = ArrangeParserAndParse ( inputCode ) )
207
- {
208
-
209
- var inspection = new ApplicationWorksheetFunctionInspection ( state ) ;
210
- var inspectionResults = inspection . GetInspectionResults ( CancellationToken . None ) ;
211
-
212
- Assert . IsFalse ( inspectionResults . Any ( ) ) ;
213
- }
140
+ Assert . AreEqual ( 0 , GetInspectionResultsUsingExcelLibrary ( inputCode ) . Count ( ) ) ;
214
141
}
215
142
216
143
[ Test ]
@@ -222,5 +149,10 @@ public void InspectionName()
222
149
223
150
Assert . AreEqual ( inspectionName , inspection . Name ) ;
224
151
}
152
+
153
+ protected override IInspection InspectionUnderTest ( RubberduckParserState state )
154
+ {
155
+ return new ApplicationWorksheetFunctionInspection ( state ) ;
156
+ }
225
157
}
226
158
}
0 commit comments