@@ -112,8 +112,7 @@ public void TestEarlyReleaseErrorCaseAttrib()
112
112
var test = ResourceFiles . EarlyReleaseTestCases . EarlyReleaseErrorCaseHaver ;
113
113
VerifyCSharpDiagnostic ( test , col => col . Count ( ) == 1 , dx => dx . Id == DotNetVaultAnalyzer . DotNetVault_EarlyDisposeJustification &&
114
114
dx . Severity == DiagnosticSeverity . Info && dx . DefaultSeverity == DiagnosticSeverity . Info &&
115
- dx . GetMessage ( ) . Contains ( "DisposingOnError" ) ) ;
116
- }
115
+ dx . GetMessage ( ) . Contains ( "DisposingOnError" ) ) ; }
117
116
118
117
[ TestMethod ]
119
118
public void TestUnjustifiedEarlyRelease ( )
@@ -164,6 +163,71 @@ public void TestNotVsBadBase()
164
163
dx => true ) ;
165
164
}
166
165
166
+ [ TestMethod ]
167
+ public void TestNotOkBadAssignUs ( )
168
+ {
169
+ var test = ResourceFiles . NdiTestCases . NoCopyBadAssignUsingStatement ;
170
+ SortedSet < string > expectedIds = new SortedSet < string > { DotNetVaultAnalyzer . DotNetVault_UsingMandatory_NoCopyAssignment , DotNetVaultAnalyzer . DotNetVault_UsingMandatory_NoCopyIllegalPass } ;
171
+ VerifyCSharpDiagnostic ( test ,
172
+ dxes => new SortedSet < string > ( dxes . Select ( dx => dx . Descriptor . Id ) ) . SetEquals ( expectedIds ) , dx => true ) ;
173
+
174
+
175
+ }
176
+
177
+ [ TestMethod ]
178
+ public void TestInlineNotOkCase ( )
179
+ {
180
+ Dictionary < string , int > expectedCounts = new Dictionary < string , int >
181
+ {
182
+ { DotNetVaultAnalyzer . DotNetVault_UsingMandatory_NoCopyAssignment , 8 } ,
183
+ { DotNetVaultAnalyzer . DotNetVault_UsingMandatory_NoCopyIllegalPass , 4 } ,
184
+ { DotNetVaultAnalyzer . DotNetVault_UsingMandatory_NoLockedResourceWrappersAllowedInScope , 2 }
185
+ } ;
186
+
187
+ Dictionary < string , int > actualCounts = new Dictionary < string , int >
188
+ {
189
+ { DotNetVaultAnalyzer . DotNetVault_UsingMandatory_NoCopyAssignment , 0 } ,
190
+ { DotNetVaultAnalyzer . DotNetVault_UsingMandatory_NoCopyIllegalPass , 0 } ,
191
+ { DotNetVaultAnalyzer . DotNetVault_UsingMandatory_NoLockedResourceWrappersAllowedInScope , 0 }
192
+ } ;
193
+
194
+ var test = ResourceFiles . NdiTestCases . NoCopyAttributeWithBadAssignment ;
195
+ VerifyCSharpDiagnostic ( test , dxes =>
196
+ {
197
+ foreach ( var dx in dxes )
198
+ {
199
+ ++ actualCounts [ dx . Id ] ;
200
+ }
201
+ return actualCounts . All ( kvp => expectedCounts [ kvp . Key ] == kvp . Value ) ;
202
+
203
+ } , dx => true ) ;
204
+ }
205
+
206
+ [ TestMethod ]
207
+ public void TestCopyAssignmentOne ( )
208
+ {
209
+ var test = ResourceFiles . CopyAssignmentTestCases . CopyAssignmentTestCase1 ;
210
+ VerifyCSharpDiagnostic ( test , col => col . Count ( ) == 3 ,
211
+ dx => dx . Id == DotNetVaultAnalyzer
212
+ . DotNetVault_UsingMandatory_IrregularLockedResourceObjects_NotAllowedInScope ) ;
213
+ }
214
+
215
+ [ TestMethod ]
216
+ public void TestCopyAssignmentTwo ( )
217
+ {
218
+ var test = ResourceFiles . CopyAssignmentTestCases . CopyAssignmentTestCase2 ;
219
+ VerifyCSharpDiagnostic ( test , col => col . Count ( ) == 1 ,
220
+ dx => dx . Id == DotNetVaultAnalyzer . DotNetVault_UsingMandatory_NoCopyAssignment ) ;
221
+ }
222
+
223
+ [ TestMethod ]
224
+ public void TestBadExtensionMethod ( )
225
+ {
226
+ var test = ResourceFiles . NdiTestCases . ExtensionMethodPbvTest ;
227
+ VerifyCSharpDiagnostic ( test , dxes => dxes . SingleOrDefault ( ) != null ,
228
+ dx => dx . Id == DotNetVaultAnalyzer . DotNetVault_UsingMandatory_NoCopyIllegalPass_ExtMethod ) ;
229
+ }
230
+
167
231
[ TestMethod ]
168
232
public void TestNdiOkCases ( )
169
233
{
@@ -217,6 +281,78 @@ static bool TestIndividuals(Diagnostic dx) =>
217
281
( dx . Id == DotNetVaultAnalyzer . DotNetVault_NotDirectlyInvocable && dx . Location . GetLineSpan ( ) . StartLinePosition . Line == zeroIdxVersion ) ;
218
282
}
219
283
284
+ [ TestMethod ]
285
+ public void TestNdiNotOkIllegalWrapper ( )
286
+ {
287
+ var test = ResourceFiles . NdiTestCases . IllegalWrapperTestCase ;
288
+ VerifyCSharpDiagnostic ( test , col => col . Count ( ) == 2 ,
289
+ dx => dx . Descriptor . Id ==
290
+ DotNetVaultAnalyzer . DotNetVault_UsingMandatory_NoLockedResourceWrappersAllowedInScope ) ;
291
+ }
292
+
293
+ [ TestMethod ]
294
+ public void TestNdiNotOkIllegalWrapperTestCaseTwo ( )
295
+ {
296
+ var test = ResourceFiles . NdiTestCases . illegalwrappertestcase2 ;
297
+ VerifyCSharpDiagnostic ( test , col => col . Any ( ) , dx => true ) ;
298
+ }
299
+
300
+ [ TestMethod ]
301
+ public void TestNdiNotOkIllegalWrapperCaseThree ( )
302
+ {
303
+ var test = ResourceFiles . NdiTestCases . illegalwrappertestcase3 ;
304
+ VerifyCSharpDiagnostic ( test , col => col . Count ( ) == 1 ,
305
+ dx => dx . Id == DotNetVaultAnalyzer . DotNetVault_UsingMandatory_NoLockedResourceWrappersAllowedInScope ) ;
306
+ }
307
+
308
+ [ TestMethod ]
309
+ public void TestNdiNotOkIllegalWrapperCaseFour ( )
310
+ {
311
+ var test = ResourceFiles . NdiTestCases . IllegalWrapperTestCase4 ;
312
+ VerifyCSharpDiagnostic ( test , col => col . Any ( ) ,
313
+ dx => dx . Id == DotNetVaultAnalyzer . DotNetVault_UsingMandatory_NoLockedResourceWrappersAllowedInScope ) ;
314
+ }
315
+
316
+ [ TestMethod ]
317
+ public void TestNdiNotOkDeepIllegalWrapper ( )
318
+ {
319
+ var test = ResourceFiles . NdiTestCases . TestDeepIllegalWrapper ;
320
+ VerifyCSharpDiagnostic ( test , col => col . Count ( ) == 2 ,
321
+ dx => dx . Descriptor . Id ==
322
+ DotNetVaultAnalyzer . DotNetVault_UsingMandatory_NoLockedResourceWrappersAllowedInScope ) ;
323
+ }
324
+
325
+ [ TestMethod ]
326
+ public void TestDeepWrapperActuallyOk ( )
327
+ {
328
+ var test = ResourceFiles . NdiTestCases . TestDeepWrapperActuallyOk ;
329
+ VerifyCSharpDiagnostic ( test ) ;
330
+ }
331
+
332
+ [ TestMethod ]
333
+ public void TestRefStructAttrOkCases ( )
334
+ {
335
+ var test = ResourceFiles . RefStructAttributeTestCases . RefStructAttributeTestsOk ;
336
+ VerifyCSharpDiagnostic ( test ) ;
337
+ }
338
+
339
+ [ TestMethod ]
340
+ public void TestRefStructAttrNotOkCase1 ( )
341
+ {
342
+ var test = ResourceFiles . RefStructAttributeTestCases . RefStructAttrNotOkCase1 ;
343
+ VerifyCSharpDiagnostic ( test , col => col . Count ( ) == 1 ,
344
+ dx => dx . Descriptor . Id == DotNetVaultAnalyzer . DotNetVault_OnlyOnRefStruct ) ;
345
+ }
346
+
347
+ [ TestMethod ]
348
+ public void TestRefStructAttrNotOkCase2 ( )
349
+ {
350
+ var test = ResourceFiles . RefStructAttributeTestCases . RoRegularNotARefStructCase2 ;
351
+ VerifyCSharpDiagnostic ( test , col => col . Count ( ) == 1 ,
352
+ dx => dx . Descriptor . Id == DotNetVaultAnalyzer . DotNetVault_OnlyOnRefStruct ) ;
353
+ }
354
+
355
+
220
356
[ TestMethod ]
221
357
public void TestNotVsEx ( )
222
358
{
@@ -583,7 +719,8 @@ private static Project CreateProject(string[] sources, string language = Languag
583
719
. AddMetadataReference ( projectId , UriReference )
584
720
. AddMetadataReference ( projectId , NameReference )
585
721
. AddMetadataReference ( projectId , NdiReference )
586
- . AddMetadataReference ( projectId , UmReference ) ;
722
+ . AddMetadataReference ( projectId , UmReference )
723
+ . AddMetadataReference ( projectId , NcReference ) ;
587
724
588
725
589
726
int count = 0 ;
@@ -610,5 +747,6 @@ private static Project CreateProject(string[] sources, string language = Languag
610
747
private static readonly MetadataReference NameReference = MetadataReference . CreateFromFile ( typeof ( Name ) . Assembly . Location ) ;
611
748
private static readonly MetadataReference NdiReference = MetadataReference . CreateFromFile ( typeof ( NoDirectInvokeAttribute ) . Assembly . Location ) ;
612
749
private static readonly MetadataReference UmReference = MetadataReference . CreateFromFile ( typeof ( UsingMandatoryAttribute ) . Assembly . Location ) ;
750
+ private static readonly MetadataReference NcReference = MetadataReference . CreateFromFile ( typeof ( NoCopyAttribute ) . Assembly . Location ) ;
613
751
}
614
752
}
0 commit comments