forked from dotnet/roslyn-analyzers
-
Notifications
You must be signed in to change notification settings - Fork 1
/
IdentifiersShouldHaveCorrectSuffixTests.cs
1135 lines (857 loc) · 34.3 KB
/
IdentifiersShouldHaveCorrectSuffixTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Testing;
using Test.Utilities;
using Xunit;
namespace Microsoft.CodeQuality.Analyzers.ApiDesignGuidelines.UnitTests
{
public class IdentifiersShouldHaveCorrectSuffixTests : DiagnosticAnalyzerTestBase
{
protected override DiagnosticAnalyzer GetBasicDiagnosticAnalyzer()
{
return new IdentifiersShouldHaveCorrectSuffixAnalyzer();
}
protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer()
{
return new IdentifiersShouldHaveCorrectSuffixAnalyzer();
}
[Fact]
public void CA1710_AllScenarioDiagnostics_CSharp()
{
VerifyCSharp(@"
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Data;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Security;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
public class EventsItemsEventArgs : EventArgs { }
public class EventsItemsDerived : EventsItemsEventArgs { }
public class EventsItems : EventArgs { }
public delegate void EventCallback(object sender, EventArgs e);
public class EventHandlerTest
{
public event EventCallback EventOne;
}
[Serializable]
public class DiskError : Exception
{
public DiskError() { }
public DiskError(string message) : base(message) { }
public DiskError(string message, Exception innerException) : base(message, innerException) { }
protected DiskError(SerializationInfo info, StreamingContext context) : base(info, context) { }
}
[AttributeUsage(AttributeTargets.Class)]
public sealed class Verifiable : Attribute
{
}
public class ConditionClass : IMembershipCondition
{
public bool Check(Evidence evidence) { return false; }
public IMembershipCondition Copy() { return (IMembershipCondition)null; }
public void FromXml(SecurityElement e, PolicyLevel level) { }
public SecurityElement ToXml(PolicyLevel level) { return (SecurityElement)null; }
public void FromXml(SecurityElement e) { }
public SecurityElement ToXml() { return (SecurityElement)null; }
}
[Serializable]
public class MyTable<TKey, TValue> : System.Collections.Generic.Dictionary<TKey, TValue>
{
protected MyTable(SerializationInfo info, StreamingContext context) : base(info, context) { }
}
[Serializable]
public class MyStringObjectHashtable : System.Collections.Generic.Dictionary<string, object>
{
protected MyStringObjectHashtable(SerializationInfo info, StreamingContext context) : base(info, context) { }
}
public class MyList<T> : System.Collections.ObjectModel.Collection<T> { }
public class StringGrouping<T> : System.Collections.ObjectModel.Collection<T> { }
public class LastInFirstOut<T> : System.Collections.Generic.Stack<T> { }
public class StackOfIntegers : System.Collections.Generic.Stack<int> { }
public class FirstInFirstOut<T> : System.Collections.Generic.Queue<T> { }
public class QueueOfNumbers : System.Collections.Generic.Queue<int> { }
public class MyDataStructure : Stack { }
public class AnotherDataStructure : Queue { }
public class WronglyNamedPermissionClass : CodeAccessPermission
{
public override IPermission Copy() { return (IPermission)null; }
public override void FromXml(SecurityElement e) { }
public override IPermission Intersect(IPermission target) { return (IPermission)null; }
public override bool IsSubsetOf(IPermission target) { return false; }
public override SecurityElement ToXml() { return (SecurityElement)null; }
}
public class WronglyNamedIPermissionClass : IPermission
{
public IPermission Copy() { return (IPermission)null; }
public void FromXml(SecurityElement e) { }
public IPermission Intersect(IPermission target) { return (IPermission)null; }
public bool IsSubsetOf(IPermission target) { return false; }
public SecurityElement ToXml() { return (SecurityElement)null; }
public IPermission Union(IPermission target) { return (IPermission)null; }
public void Demand() { }
}
public class WronglyNamedType : Stream
{
public override bool CanRead { get { return false; } }
public override bool CanSeek { get { return false; } }
public override bool CanWrite { get { return false; } }
public override long Length { get { return 0; } }
public override long Position { get { return 0; } set { } }
public override void Close() { base.Close(); }
public override void Flush() { }
public override int Read(byte[] buffer, int offset, int count) { return 0; }
public override long Seek(long offset, SeekOrigin origin) { return 0; }
public override void SetLength(long value) { }
public override void Write(byte[] buffer, int offset, int count) { }
}
public class MyCollectionIsEnumerable : IEnumerable
{
public void CopyTo(Array destination, int index)
{
System.Console.WriteLine(this);
System.Console.WriteLine(destination);
System.Console.WriteLine(index);
}
public int Count
{
get
{
Console.WriteLine(this);
return 0;
}
set
{
System.Console.WriteLine(this);
System.Console.WriteLine(value);
}
}
public bool IsSynchronized
{
get
{
Console.WriteLine(this);
return true;
}
set
{
System.Console.WriteLine(this);
System.Console.WriteLine(value);
}
}
public object SyncRoot
{
get
{
return this;
}
set
{
System.Console.WriteLine(this);
System.Console.WriteLine(value);
}
}
public IEnumerator GetEnumerator() { return null; }
}
public class CollectionDoesNotEndInCollectionClass : StringCollection { }
[Serializable]
public class DictionaryDoesNotEndInDictionaryClass : Hashtable
{
protected DictionaryDoesNotEndInDictionaryClass(SerializationInfo info, StreamingContext context)
: base(info, context) { }
}
public class MyTest<T> : List<T>
{
}
[Serializable]
public class DataSetWithWrongSuffix : DataSet
{
protected DataSetWithWrongSuffix(SerializationInfo info, StreamingContext context)
: base(info, context) { }
}
[Serializable]
public class DataTableWithWrongSuffix : DataTable
{
protected DataTableWithWrongSuffix(SerializationInfo info, StreamingContext context)
: base(info, context) { }
}",
GetCA1710CSharpResultAt(line: 16, column: 14, symbolName: "EventsItemsDerived", replacementName: "EventArgs"),
GetCA1710CSharpResultAt(line: 18, column: 14, symbolName: "EventsItems", replacementName: "EventArgs"),
GetCA1710CSharpResultAt(line: 24, column: 32, symbolName: "EventCallback", replacementName: "EventHandler"),
GetCA1710CSharpResultAt(line: 28, column: 14, symbolName: "DiskError", replacementName: "Exception"),
GetCA1710CSharpResultAt(line: 39, column: 21, symbolName: "Verifiable", replacementName: "Attribute"),
GetCA1710CSharpResultAt(line: 43, column: 14, symbolName: "ConditionClass", replacementName: "Condition"),
GetCA1710CSharpResultAt(line: 54, column: 14, symbolName: "MyTable<TKey, TValue>", replacementName: "Dictionary"),
GetCA1710CSharpResultAt(line: 60, column: 14, symbolName: "MyStringObjectHashtable", replacementName: "Dictionary"),
GetCA1710CSharpResultAt(line: 65, column: 14, symbolName: "MyList<T>", replacementName: "Collection"),
GetCA1710CSharpResultAt(line: 67, column: 14, symbolName: "StringGrouping<T>", replacementName: "Collection"),
GetCA1710CSharpResultAt(line: 69, column: 14, symbolName: "LastInFirstOut<T>", replacementName: "Stack", isSpecial: true),
GetCA1710CSharpResultAt(line: 71, column: 14, symbolName: "StackOfIntegers", replacementName: "Stack", isSpecial: true),
GetCA1710CSharpResultAt(line: 73, column: 14, symbolName: "FirstInFirstOut<T>", replacementName: "Queue", isSpecial: true),
GetCA1710CSharpResultAt(line: 75, column: 14, symbolName: "QueueOfNumbers", replacementName: "Queue", isSpecial: true),
GetCA1710CSharpResultAt(line: 77, column: 14, symbolName: "MyDataStructure", replacementName: "Stack", isSpecial: true),
GetCA1710CSharpResultAt(line: 79, column: 14, symbolName: "AnotherDataStructure", replacementName: "Queue", isSpecial: true),
GetCA1710CSharpResultAt(line: 81, column: 14, symbolName: "WronglyNamedPermissionClass", replacementName: "Permission"),
GetCA1710CSharpResultAt(line: 90, column: 14, symbolName: "WronglyNamedIPermissionClass", replacementName: "Permission"),
GetCA1710CSharpResultAt(line: 101, column: 14, symbolName: "WronglyNamedType", replacementName: "Stream"),
GetCA1710CSharpResultAt(line: 116, column: 14, symbolName: "MyCollectionIsEnumerable", replacementName: "Collection"),
GetCA1710CSharpResultAt(line: 165, column: 14, symbolName: "CollectionDoesNotEndInCollectionClass", replacementName: "Collection"),
GetCA1710CSharpResultAt(line: 168, column: 14, symbolName: "DictionaryDoesNotEndInDictionaryClass", replacementName: "Dictionary"),
GetCA1710CSharpResultAt(line: 174, column: 14, symbolName: "MyTest<T>", replacementName: "Collection"),
GetCA1710CSharpResultAt(line: 179, column: 14, symbolName: "DataSetWithWrongSuffix", replacementName: "DataSet"),
GetCA1710CSharpResultAt(line: 186, column: 14, symbolName: "DataTableWithWrongSuffix", replacementName: "DataTable", isSpecial: true));
}
[Fact]
public void CA1710_NoDiagnostics_CSharp()
{
VerifyCSharp(@"
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Data;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Security;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
[Serializable]
public class MyDictionary<TKey, TValue> : System.Collections.Generic.Dictionary<TKey, TValue>
{
protected MyDictionary(SerializationInfo info, StreamingContext context) : base(info, context) { }
}
[Serializable]
public class MyStringObjectDictionary : System.Collections.Generic.Dictionary<string, object>
{
protected MyStringObjectDictionary(SerializationInfo info, StreamingContext context) : base(info, context) { }
}
public class MyCollection<T> : System.Collections.ObjectModel.Collection<T> { }
public class MyStringCollection : System.Collections.ObjectModel.Collection<string> { }
public class MyStack<T> : System.Collections.Generic.Stack<T> { }
public class MyIntegerStack : System.Collections.Generic.Stack<int> { }
public class StackCollection<T> : System.Collections.Generic.Stack<T> { }
public class IntegerStackCollection : System.Collections.Generic.Stack<int> { }
public class MyQueue<T> : System.Collections.Generic.Queue<T> { }
public class MyIntegerQueue : System.Collections.Generic.Queue<int> { }
public class QueueCollection<T> : System.Collections.Generic.Queue<T> { }
public class IntegerQueueCollection : System.Collections.Generic.Queue<int> { }
public delegate void SimpleEventHandler(object sender, EventArgs e);
public class EventHandlerTest
{
public event SimpleEventHandler EventOne;
public event EventHandler<EventArgs> EventTwo;
}
[Serializable]
public class DiskErrorException : Exception
{
public DiskErrorException() { }
public DiskErrorException(string message) : base(message) { }
public DiskErrorException(string message, Exception innerException) : base(message, innerException) { }
protected DiskErrorException(SerializationInfo info, StreamingContext context) : base(info, context) { }
}
[AttributeUsage(AttributeTargets.Class)]
public sealed class VerifiableAttribute : Attribute
{
}
public class MyCondition : IMembershipCondition
{
public bool Check(Evidence evidence) { return false; }
public IMembershipCondition Copy() { return (IMembershipCondition)null; }
public void FromXml(SecurityElement e, PolicyLevel level) { }
public SecurityElement ToXml(PolicyLevel level) { return (SecurityElement)null; }
public void FromXml(SecurityElement e) { }
public SecurityElement ToXml() { return (SecurityElement)null; }
}
public class CorrectlyNamedPermission : CodeAccessPermission
{
public override IPermission Copy() { return (IPermission)null; }
public override void FromXml(SecurityElement e) { }
public override IPermission Intersect(IPermission target) { return (IPermission)null; }
public override bool IsSubsetOf(IPermission target) { return false; }
public override SecurityElement ToXml() { return (SecurityElement)null; }
}
public class CorrectlyNamedIPermission : IPermission
{
public IPermission Copy() { return (IPermission)null; }
public void FromXml(SecurityElement e) { }
public IPermission Intersect(IPermission target) { return (IPermission)null; }
public bool IsSubsetOf(IPermission target) { return false; }
public SecurityElement ToXml() { return (SecurityElement)null; }
public IPermission Union(IPermission target) { return (IPermission)null; }
public void Demand() { }
}
public class CorrectlyNamedTypeStream : Stream
{
public override bool CanRead { get { return false; } }
public override bool CanSeek { get { return false; } }
public override bool CanWrite { get { return false; } }
public override long Length { get { return 0; } }
public override long Position { get { return 0; } set { } }
public override void Close() { base.Close(); }
public override void Flush() { }
public override int Read(byte[] buffer, int offset, int count) { return 0; }
public override long Seek(long offset, SeekOrigin origin) { return 0; }
public override void SetLength(long value) { }
public override void Write(byte[] buffer, int offset, int count) { }
}
public class CollectionEndsInCollection : StringCollection { }
[Serializable]
public class DictionaryEndsInDictionary : Hashtable
{
public DictionaryEndsInDictionary() { }
protected DictionaryEndsInDictionary(SerializationInfo info, StreamingContext context)
: base(info, context) { }
}
[Serializable]
public class MySpecialQueue : Queue { }
public class QueueCollection : Queue { }
[Serializable]
public class MyStack : Stack { }
public class StackCollection : Stack { }
[Serializable]
public class MyDataSet : DataSet
{
public MyDataSet() { }
protected MyDataSet(SerializationInfo info, StreamingContext context) : base(info, context) { }
public void DoWork() { Console.WriteLine(this); }
}
[Serializable]
public class MyDataTable : DataTable
{
public MyDataTable() { }
protected MyDataTable(SerializationInfo info, StreamingContext context)
: base(info, context) { }
public void DoWork() { Console.WriteLine(this); }
}
[Serializable]
public class MyCollectionDataTable : DataTable, IEnumerable
{
public MyCollectionDataTable() { }
protected MyCollectionDataTable(SerializationInfo info, StreamingContext context)
: base(info, context) { }
public void DoWork() { Console.WriteLine(this); }
public IEnumerator GetEnumerator()
{
return null;
}
}");
}
[Fact]
public void CA1710_AllScenarioDiagnostics_VisualBasic()
{
this.PrintActualDiagnosticsOnFailure = true;
VerifyBasic(@"
Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
Imports System.Collections.Specialized
Imports System.Data
Imports System.IO
Imports System.Runtime.Serialization
Imports System.Security
Imports System.Security.Policy
Public Class AnotherDataStructure
Inherits Queue
End Class
Public Class CollectionDoesNotEndInCollectionClass
Inherits StringCollection
End Class
Public Class ConditionClass
Implements IMembershipCondition, ISecurityEncodable, ISecurityPolicyEncodable
' Methods
Public Function Check(ByVal evidence As Evidence) As Boolean Implements IMembershipCondition.Check
Return False
End Function
Public Function Copy() As IMembershipCondition Implements IMembershipCondition.Copy
Return Nothing
End Function
Public Sub FromXml(ByVal e As SecurityElement) Implements ISecurityEncodable.FromXml
End Sub
Public Sub FromXml(ByVal e As SecurityElement, ByVal level As PolicyLevel) Implements ISecurityPolicyEncodable.FromXml
End Sub
Public Function ToXml() As SecurityElement Implements ISecurityEncodable.ToXml
Return Nothing
End Function
Public Function ToXml(ByVal level As PolicyLevel) As SecurityElement Implements ISecurityPolicyEncodable.ToXml
Return Nothing
End Function
Public Overrides Function ToString() As String Implements IMembershipCondition.ToString
Return MyBase.ToString()
End Function
Public Overrides Function Equals(ByVal obj As Object) As Boolean Implements IMembershipCondition.Equals
Return MyBase.Equals(obj)
End Function
Public Overrides Function GetHashCode() As Integer
Return MyBase.GetHashCode()
End Function
End Class
<Serializable()>
Public Class DataSetWithWrongSuffix
Inherits DataSet
' Methods
Protected Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)
MyBase.New(info, context)
End Sub
End Class
<Serializable()>
Public Class DataTableWithWrongSuffix
Inherits DataTable
' Methods
Protected Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)
MyBase.New(info, context)
End Sub
End Class
<Serializable()>
Public Class DictionaryDoesNotEndInDictionaryClass
Inherits Hashtable
' Methods
Protected Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)
MyBase.New(info, context)
End Sub
End Class
<Serializable()>
Public Class DiskError
Inherits Exception
' Methods
Public Sub New()
End Sub
Public Sub New(ByVal message As String)
MyBase.New(message)
End Sub
Protected Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)
MyBase.New(info, context)
End Sub
Public Sub New(ByVal message As String, ByVal innerException As Exception)
MyBase.New(message, innerException)
End Sub
End Class
Public Delegate Sub EventCallback(ByVal sender As Object, ByVal e As EventArgs)
Public Class EventHandlerTest
' Events
Public Event EventOne As EventCallback
End Class
Public Class EventsItems
Inherits EventArgs
End Class
Public Class FirstInFirstOut(Of T)
Inherits Queue(Of T)
End Class
Public Class LastInFirstOut(Of T)
Inherits Stack(Of T)
End Class
Public Class MyCollectionIsEnumerable
Implements IEnumerable
Public Function GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator
Return Nothing
End Function
End Class
Public Class MyDataStructure
Inherits Stack
End Class
Public Class MyList(Of T)
Inherits Collection(Of T)
End Class
<Serializable()>
Public Class MyStringObjectHashtable
Inherits Dictionary(Of String, Object)
' Methods
Protected Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)
MyBase.New(info, context)
End Sub
End Class
<Serializable()>
Public Class MyTable(Of TKey, TValue)
Inherits Dictionary(Of TKey, TValue)
' Methods
Protected Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)
MyBase.New(info, context)
End Sub
End Class
Public Class MyTest(Of T)
Inherits List(Of T)
End Class
Public Class QueueOfNumbers
Inherits Queue(Of Integer)
End Class
Public Class StackOfIntegers
Inherits Stack(Of Integer)
End Class
Public Class StringGrouping(Of T)
Inherits Collection(Of T)
End Class
<AttributeUsage(AttributeTargets.Class)>
Public NotInheritable Class Verifiable
Inherits Attribute
End Class
Public Class WronglyNamedIPermissionClass
Implements IPermission, ISecurityEncodable
' Methods
Public Function Copy() As IPermission Implements IPermission.Copy
Return Nothing
End Function
Public Sub Demand() Implements IPermission.Demand
End Sub
Public Sub FromXml(ByVal e As SecurityElement) Implements ISecurityEncodable.FromXml
End Sub
Public Function Intersect(ByVal target As IPermission) As IPermission Implements IPermission.Intersect
Return Nothing
End Function
Public Function IsSubsetOf(ByVal target As IPermission) As Boolean Implements IPermission.IsSubsetOf
Return False
End Function
Public Function ToXml() As SecurityElement Implements ISecurityEncodable.ToXml
Return Nothing
End Function
Public Function Union(ByVal target As IPermission) As IPermission Implements IPermission.Union
Return Nothing
End Function
End Class
Public Class WronglyNamedPermissionClass
Inherits CodeAccessPermission
' Methods
Public Overrides Function Copy() As IPermission
Return Nothing
End Function
Public Overrides Sub FromXml(ByVal e As SecurityElement)
End Sub
Public Overrides Function Intersect(ByVal target As IPermission) As IPermission
Return Nothing
End Function
Public Overrides Function IsSubsetOf(ByVal target As IPermission) As Boolean
Return False
End Function
Public Overrides Function ToXml() As SecurityElement
Return Nothing
End Function
End Class
Public Class WronglyNamedType
Inherits Stream
' Methods
Public Overrides Sub Close()
MyBase.Close()
End Sub
Public Overrides Sub Flush()
End Sub
Public Overrides Function Read(ByVal buffer As Byte(), ByVal offset As Integer, ByVal count As Integer) As Integer
Return 0
End Function
Public Overrides Function Seek(ByVal offset As Long, ByVal origin As SeekOrigin) As Long
Return CType(0, Long)
End Function
Public Overrides Sub SetLength(ByVal value As Long)
End Sub
Public Overrides Sub Write(ByVal buffer As Byte(), ByVal offset As Integer, ByVal count As Integer)
End Sub
' Properties
Public Overrides ReadOnly Property CanRead() As Boolean
Get
Return False
End Get
End Property
Public Overrides ReadOnly Property CanSeek() As Boolean
Get
Return False
End Get
End Property
Public Overrides ReadOnly Property CanWrite() As Boolean
Get
Return False
End Get
End Property
Public Overrides ReadOnly Property Length() As Long
Get
Return CType(0, Long)
End Get
End Property
Public Overrides Property Position() As Long
Get
Return CType(0, Long)
End Get
Set(ByVal value As Long)
End Set
End Property
End Class",
GetCA1710BasicResultAt(line: 13, column: 14, symbolName: "AnotherDataStructure", replacementName: "Queue", isSpecial: true),
GetCA1710BasicResultAt(line: 17, column: 14, symbolName: "CollectionDoesNotEndInCollectionClass", replacementName: "Collection"),
GetCA1710BasicResultAt(line: 22, column: 14, symbolName: "ConditionClass", replacementName: "Condition"),
GetCA1710BasicResultAt(line: 64, column: 14, symbolName: "DataSetWithWrongSuffix", replacementName: "DataSet"),
GetCA1710BasicResultAt(line: 75, column: 14, symbolName: "DataTableWithWrongSuffix", replacementName: "DataTable", isSpecial: true),
GetCA1710BasicResultAt(line: 86, column: 14, symbolName: "DictionaryDoesNotEndInDictionaryClass", replacementName: "Dictionary"),
GetCA1710BasicResultAt(line: 97, column: 14, symbolName: "DiskError", replacementName: "Exception"),
GetCA1710BasicResultAt(line: 122, column: 18, symbolName: "EventCallback", replacementName: "EventHandler"),
GetCA1710BasicResultAt(line: 125, column: 14, symbolName: "EventsItems", replacementName: "EventArgs"),
GetCA1710BasicResultAt(line: 130, column: 14, symbolName: "FirstInFirstOut(Of T)", replacementName: "Queue", isSpecial: true),
GetCA1710BasicResultAt(line: 135, column: 14, symbolName: "LastInFirstOut(Of T)", replacementName: "Stack", isSpecial: true),
GetCA1710BasicResultAt(line: 140, column: 14, symbolName: "MyCollectionIsEnumerable", replacementName: "Collection"),
GetCA1710BasicResultAt(line: 148, column: 14, symbolName: "MyDataStructure", replacementName: "Stack", isSpecial: true),
GetCA1710BasicResultAt(line: 153, column: 14, symbolName: "MyList(Of T)", replacementName: "Collection"),
GetCA1710BasicResultAt(line: 159, column: 14, symbolName: "MyStringObjectHashtable", replacementName: "Dictionary"),
GetCA1710BasicResultAt(line: 170, column: 14, symbolName: "MyTable(Of TKey, TValue)", replacementName: "Dictionary"),
GetCA1710BasicResultAt(line: 180, column: 14, symbolName: "MyTest(Of T)", replacementName: "Collection"),
GetCA1710BasicResultAt(line: 185, column: 14, symbolName: "QueueOfNumbers", replacementName: "Queue", isSpecial: true),
GetCA1710BasicResultAt(line: 190, column: 14, symbolName: "StackOfIntegers", replacementName: "Stack", isSpecial: true),
GetCA1710BasicResultAt(line: 195, column: 14, symbolName: "StringGrouping(Of T)", replacementName: "Collection"),
GetCA1710BasicResultAt(line: 201, column: 29, symbolName: "Verifiable", replacementName: "Attribute"),
GetCA1710BasicResultAt(line: 206, column: 14, symbolName: "WronglyNamedIPermissionClass", replacementName: "Permission"),
GetCA1710BasicResultAt(line: 238, column: 14, symbolName: "WronglyNamedPermissionClass", replacementName: "Permission"),
GetCA1710BasicResultAt(line: 263, column: 14, symbolName: "WronglyNamedType", replacementName: "Stream"));
}
[Fact]
public void CA1710_NoDiagnostics_VisualBasic()
{
this.PrintActualDiagnosticsOnFailure = true;
VerifyBasic(@"
Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
Imports System.Collections.Specialized
Imports System.Data
Imports System.IO
Imports System.Runtime.Serialization
Imports System.Security
Imports System.Security.Policy
Public Class CollectionEndsInCollection
Inherits StringCollection
End Class
Public Class CorrectlyNamedIPermission
Implements IPermission, ISecurityEncodable
Public Function Copy() As System.Security.IPermission Implements System.Security.IPermission.Copy
Return Me
End Function
Public Sub Demand() Implements System.Security.IPermission.Demand
End Sub
Public Function Intersect(ByVal target As System.Security.IPermission) As System.Security.IPermission Implements System.Security.IPermission.Intersect
Return Nothing
End Function
Public Function IsSubsetOf(ByVal target As System.Security.IPermission) As Boolean Implements System.Security.IPermission.IsSubsetOf
Return False
End Function
Public Function Union(ByVal target As System.Security.IPermission) As System.Security.IPermission Implements System.Security.IPermission.Union
Return Me
End Function
Public Sub FromXml(ByVal e As System.Security.SecurityElement) Implements System.Security.ISecurityEncodable.FromXml
End Sub
Public Function ToXml() As System.Security.SecurityElement Implements System.Security.ISecurityEncodable.ToXml
End Function
End Class
Public Class CorrectlyNamedPermission
Inherits CodeAccessPermission
Public Overrides Function Copy() As System.Security.IPermission
End Function
Public Overrides Sub FromXml(ByVal elem As System.Security.SecurityElement)
End Sub
Public Overrides Function Intersect(ByVal target As System.Security.IPermission) As System.Security.IPermission
End Function
Public Overrides Function IsSubsetOf(ByVal target As System.Security.IPermission) As Boolean
End Function
Public Overrides Function ToXml() As System.Security.SecurityElement
End Function
End Class
Public Class CorrectlyNamedTypeStream
Inherits FileStream
Public Sub New()
MyBase.New("""", FileMode.Open)
End Sub
End Class
<Serializable()>
Public Class DictionaryEndsInDictionary
Inherits Hashtable
' Methods
Public Sub New()
End Sub
Protected Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)
MyBase.New(info, context)
End Sub
End Class
<Serializable()>
Public Class DiskErrorException
Inherits Exception
' Methods
Public Sub New()
End Sub
Public Sub New(ByVal message As String)
MyBase.New(message)
End Sub
Protected Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)
MyBase.New(info, context)
End Sub
Public Sub New(ByVal message As String, ByVal innerException As Exception)
MyBase.New(message, innerException)
End Sub
End Class
Public Class EventHandlerTest
' Events
Public Event EventOne As SimpleEventHandler
End Class
Public Class EventsItemsEventArgs
Inherits EventArgs
End Class
Public Class IntegerQueueCollection
Inherits Queue(Of Integer)
End Class
Public Class IntegerStackCollection
Inherits Stack(Of Integer)
End Class
Public Class MyCollection(Of T)
Inherits Collection(Of T)
End Class
Public Class MyCondition
Implements IMembershipCondition, ISecurityEncodable, ISecurityPolicyEncodable
Public Sub FromXml(ByVal e As System.Security.SecurityElement) Implements System.Security.ISecurityEncodable.FromXml
End Sub
Public Function ToXml() As System.Security.SecurityElement Implements System.Security.ISecurityEncodable.ToXml
End Function
Public Sub FromXml1(ByVal e As System.Security.SecurityElement, ByVal level As System.Security.Policy.PolicyLevel) Implements System.Security.ISecurityPolicyEncodable.FromXml
End Sub
Public Function ToXml1(ByVal level As System.Security.Policy.PolicyLevel) As System.Security.SecurityElement Implements System.Security.ISecurityPolicyEncodable.ToXml
End Function
Public Function Check(ByVal evidence As System.Security.Policy.Evidence) As Boolean Implements System.Security.Policy.IMembershipCondition.Check
End Function
Public Function Copy() As System.Security.Policy.IMembershipCondition Implements System.Security.Policy.IMembershipCondition.Copy
End Function
Public Function Equals1(ByVal obj As Object) As Boolean Implements System.Security.Policy.IMembershipCondition.Equals
End Function
Public Function ToString1() As String Implements System.Security.Policy.IMembershipCondition.ToString
End Function
End Class
<Serializable()>
Public Class MyDataSet
Inherits DataSet
' Methods
Public Sub New()
End Sub
Protected Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)
MyBase.New(info, context)
End Sub
Public Sub DoWork()
Console.WriteLine(Me)
End Sub
End Class
<Serializable()>
Public Class MyDataTable
Inherits DataTable
' Methods
Public Sub New()
End Sub
Protected Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)
MyBase.New(info, context)
End Sub
Public Sub DoWork()
Console.WriteLine(Me)
End Sub
End Class
<Serializable()>
Public Class MyDictionary(Of TKey, TValue)
Inherits Dictionary(Of TKey, TValue)
' Methods
Protected Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)
MyBase.New(info, context)