1
+ using System . Linq ;
2
+ using Microsoft . Vbe . Interop ;
3
+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
4
+ using Moq ;
5
+ using Rubberduck . Inspections ;
6
+ using Rubberduck . Parsing . VBA ;
7
+ using Rubberduck . VBEditor . Extensions ;
8
+ using Rubberduck . VBEditor . VBEHost ;
9
+ using RubberduckTests . Mocks ;
10
+
11
+ namespace RubberduckTests . Inspections
12
+ {
13
+ [ TestClass ]
14
+ public class EncapsulatePublicFieldInspectionTests
15
+ {
16
+ [ TestMethod ]
17
+ public void PublicField_ReturnsResult ( )
18
+ {
19
+ const string inputCode =
20
+ @"Public fizz As Boolean" ;
21
+
22
+ //Arrange
23
+ var builder = new MockVbeBuilder ( ) ;
24
+ VBComponent component ;
25
+ var vbe = builder . BuildFromSingleStandardModule ( inputCode , out component ) ;
26
+ var mockHost = new Mock < IHostApplication > ( ) ;
27
+ mockHost . SetupAllProperties ( ) ;
28
+ var parser = new RubberduckParser ( vbe . Object , new RubberduckParserState ( ) ) ;
29
+
30
+ parser . Parse ( ) ;
31
+
32
+ var inspection = new EncapsulatePublicFieldInspection ( parser . State ) ;
33
+ var inspectionResults = inspection . GetInspectionResults ( ) ;
34
+
35
+ Assert . AreEqual ( 1 , inspectionResults . Count ( ) ) ;
36
+ }
37
+
38
+ [ TestMethod ]
39
+ public void MultiplePublicFields_ReturnMultipleResult ( )
40
+ {
41
+ const string inputCode =
42
+ @"Public fizz As Boolean
43
+ Public buzz As Integer, _
44
+ bazz As Integer" ;
45
+
46
+ //Arrange
47
+ var builder = new MockVbeBuilder ( ) ;
48
+ VBComponent component ;
49
+ var vbe = builder . BuildFromSingleStandardModule ( inputCode , out component ) ;
50
+ var mockHost = new Mock < IHostApplication > ( ) ;
51
+ mockHost . SetupAllProperties ( ) ;
52
+ var parser = new RubberduckParser ( vbe . Object , new RubberduckParserState ( ) ) ;
53
+
54
+ parser . Parse ( ) ;
55
+
56
+ var inspection = new EncapsulatePublicFieldInspection ( parser . State ) ;
57
+ var inspectionResults = inspection . GetInspectionResults ( ) ;
58
+
59
+ Assert . AreEqual ( 3 , inspectionResults . Count ( ) ) ;
60
+ }
61
+
62
+ [ TestMethod ]
63
+ public void PrivateField_DoesNotReturnResult ( )
64
+ {
65
+ const string inputCode =
66
+ @"Private fizz As Boolean" ;
67
+
68
+ //Arrange
69
+ var builder = new MockVbeBuilder ( ) ;
70
+ VBComponent component ;
71
+ var vbe = builder . BuildFromSingleStandardModule ( inputCode , out component ) ;
72
+ var mockHost = new Mock < IHostApplication > ( ) ;
73
+ mockHost . SetupAllProperties ( ) ;
74
+ var parser = new RubberduckParser ( vbe . Object , new RubberduckParserState ( ) ) ;
75
+
76
+ parser . Parse ( ) ;
77
+
78
+ var inspection = new EncapsulatePublicFieldInspection ( parser . State ) ;
79
+ var inspectionResults = inspection . GetInspectionResults ( ) ;
80
+
81
+ Assert . AreEqual ( 0 , inspectionResults . Count ( ) ) ;
82
+ }
83
+
84
+ [ TestMethod ]
85
+ public void PublicNonField_DoesNotReturnResult ( )
86
+ {
87
+ const string inputCode =
88
+ @"Public Sub Foo(ByRef arg1 As String)
89
+ End Sub" ;
90
+
91
+ //Arrange
92
+ var builder = new MockVbeBuilder ( ) ;
93
+ VBComponent component ;
94
+ var vbe = builder . BuildFromSingleStandardModule ( inputCode , out component ) ;
95
+ var mockHost = new Mock < IHostApplication > ( ) ;
96
+ mockHost . SetupAllProperties ( ) ;
97
+ var parser = new RubberduckParser ( vbe . Object , new RubberduckParserState ( ) ) ;
98
+
99
+ parser . Parse ( ) ;
100
+
101
+ var inspection = new EncapsulatePublicFieldInspection ( parser . State ) ;
102
+ var inspectionResults = inspection . GetInspectionResults ( ) ;
103
+
104
+ Assert . AreEqual ( 0 , inspectionResults . Count ( ) ) ;
105
+ }
106
+
107
+ [ TestMethod ]
108
+ public void InspectionType ( )
109
+ {
110
+ var inspection = new EncapsulatePublicFieldInspection ( null ) ;
111
+ Assert . AreEqual ( CodeInspectionType . MaintainabilityAndReadabilityIssues , inspection . InspectionType ) ;
112
+ }
113
+
114
+ [ TestMethod ]
115
+ public void InspectionName ( )
116
+ {
117
+ const string inspectionName = "EncapsulatePublicFieldInspection" ;
118
+ var inspection = new EncapsulatePublicFieldInspection ( null ) ;
119
+
120
+ Assert . AreEqual ( inspectionName , inspection . Name ) ;
121
+ }
122
+ }
123
+ }
0 commit comments