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 . VBEHost ;
8
+ using RubberduckTests . Mocks ;
9
+
10
+ namespace RubberduckTests . Inspections
11
+ {
12
+ [ TestClass ]
13
+ public class OptionBaseInspectionTests
14
+ {
15
+ [ TestMethod ]
16
+ public void OptionBaseOneSpecified_ReturnsResult ( )
17
+ {
18
+ const string inputCode = @"Option Base 1" ;
19
+
20
+ //Arrange
21
+ var builder = new MockVbeBuilder ( ) ;
22
+ VBComponent component ;
23
+ var vbe = builder . BuildFromSingleStandardModule ( inputCode , out component ) ;
24
+ var mockHost = new Mock < IHostApplication > ( ) ;
25
+ mockHost . SetupAllProperties ( ) ;
26
+ var parser = new RubberduckParser ( vbe . Object , new RubberduckParserState ( ) ) ;
27
+
28
+ parser . Parse ( ) ;
29
+ if ( parser . State . Status == ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
30
+
31
+ var inspection = new OptionBaseInspection ( parser . State ) ;
32
+ var inspectionResults = inspection . GetInspectionResults ( ) ;
33
+
34
+ Assert . AreEqual ( 1 , inspectionResults . Count ( ) ) ;
35
+ }
36
+
37
+ [ TestMethod ]
38
+ public void OptionBaseNotSpecified_DoesNotReturnResult ( )
39
+ {
40
+ const string inputCode = @"" ;
41
+
42
+ //Arrange
43
+ var builder = new MockVbeBuilder ( ) ;
44
+ VBComponent component ;
45
+ var vbe = builder . BuildFromSingleStandardModule ( inputCode , out component ) ;
46
+ var mockHost = new Mock < IHostApplication > ( ) ;
47
+ mockHost . SetupAllProperties ( ) ;
48
+ var parser = new RubberduckParser ( vbe . Object , new RubberduckParserState ( ) ) ;
49
+
50
+ parser . Parse ( ) ;
51
+ if ( parser . State . Status == ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
52
+
53
+ var inspection = new OptionBaseInspection ( parser . State ) ;
54
+ var inspectionResults = inspection . GetInspectionResults ( ) ;
55
+
56
+ Assert . AreEqual ( 0 , inspectionResults . Count ( ) ) ;
57
+ }
58
+
59
+ [ TestMethod ]
60
+ public void OptionBaseZeroSpecified_DoesNotReturnResult ( )
61
+ {
62
+ const string inputCode = @"Option Base 0" ;
63
+
64
+ //Arrange
65
+ var builder = new MockVbeBuilder ( ) ;
66
+ VBComponent component ;
67
+ var vbe = builder . BuildFromSingleStandardModule ( inputCode , out component ) ;
68
+ var mockHost = new Mock < IHostApplication > ( ) ;
69
+ mockHost . SetupAllProperties ( ) ;
70
+ var parser = new RubberduckParser ( vbe . Object , new RubberduckParserState ( ) ) ;
71
+
72
+ parser . Parse ( ) ;
73
+ if ( parser . State . Status == ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
74
+
75
+ var inspection = new OptionBaseInspection ( parser . State ) ;
76
+ var inspectionResults = inspection . GetInspectionResults ( ) ;
77
+
78
+ Assert . AreEqual ( 0 , inspectionResults . Count ( ) ) ;
79
+ }
80
+
81
+ [ TestMethod ]
82
+ public void OptionBaseOneSpecified_ReturnsMultipleResults ( )
83
+ {
84
+ const string inputCode = @"Option Base 1" ;
85
+
86
+ //Arrange
87
+ var builder = new MockVbeBuilder ( ) ;
88
+ var project = builder . ProjectBuilder ( "TestProject1" , vbext_ProjectProtection . vbext_pp_none )
89
+ . AddComponent ( "Class1" , vbext_ComponentType . vbext_ct_ClassModule , inputCode )
90
+ . AddComponent ( "Class2" , vbext_ComponentType . vbext_ct_ClassModule , inputCode )
91
+ . Build ( ) ;
92
+ var vbe = builder . AddProject ( project ) . Build ( ) ;
93
+
94
+ var mockHost = new Mock < IHostApplication > ( ) ;
95
+ mockHost . SetupAllProperties ( ) ;
96
+ var parser = new RubberduckParser ( vbe . Object , new RubberduckParserState ( ) ) ;
97
+
98
+ parser . Parse ( ) ;
99
+ if ( parser . State . Status == ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
100
+
101
+ var inspection = new OptionBaseInspection ( parser . State ) ;
102
+ var inspectionResults = inspection . GetInspectionResults ( ) ;
103
+
104
+ Assert . AreEqual ( 2 , inspectionResults . Count ( ) ) ;
105
+ }
106
+
107
+ [ TestMethod ]
108
+ public void OptionBaseOnePartiallySpecified_ReturnsResults ( )
109
+ {
110
+ const string inputCode1 = @"" ;
111
+ const string inputCode2 = @"Option Base 1" ;
112
+
113
+ //Arrange
114
+ var builder = new MockVbeBuilder ( ) ;
115
+ var project = builder . ProjectBuilder ( "TestProject1" , vbext_ProjectProtection . vbext_pp_none )
116
+ . AddComponent ( "Class1" , vbext_ComponentType . vbext_ct_ClassModule , inputCode1 )
117
+ . AddComponent ( "Class2" , vbext_ComponentType . vbext_ct_ClassModule , inputCode2 )
118
+ . Build ( ) ;
119
+ var vbe = builder . AddProject ( project ) . Build ( ) ;
120
+
121
+ var mockHost = new Mock < IHostApplication > ( ) ;
122
+ mockHost . SetupAllProperties ( ) ;
123
+ var parser = new RubberduckParser ( vbe . Object , new RubberduckParserState ( ) ) ;
124
+
125
+ parser . Parse ( ) ;
126
+ if ( parser . State . Status == ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
127
+
128
+ var inspection = new OptionBaseInspection ( parser . State ) ;
129
+ var inspectionResults = inspection . GetInspectionResults ( ) ;
130
+
131
+ Assert . AreEqual ( 1 , inspectionResults . Count ( ) ) ;
132
+ }
133
+
134
+ [ TestMethod ]
135
+ public void InspectionType ( )
136
+ {
137
+ var inspection = new OptionBaseInspection ( null ) ;
138
+ Assert . AreEqual ( CodeInspectionType . MaintainabilityAndReadabilityIssues , inspection . InspectionType ) ;
139
+ }
140
+
141
+ [ TestMethod ]
142
+ public void InspectionName ( )
143
+ {
144
+ const string inspectionName = "OptionBaseInspection" ;
145
+ var inspection = new OptionBaseInspection ( null ) ;
146
+
147
+ Assert . AreEqual ( inspectionName , inspection . Name ) ;
148
+ }
149
+ }
150
+ }
0 commit comments