1+ using System . Linq ;
2+ using Microsoft . Vbe . Interop ;
3+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
4+ using Rubberduck . Inspections ;
5+ using Rubberduck . Parsing . VBA ;
6+ using Rubberduck . VBEditor . Extensions ;
7+ using Rubberduck . VBEditor . VBEInterfaces . RubberduckCodePane ;
8+ using RubberduckTests . Mocks ;
9+
10+ namespace RubberduckTests . Inspections
11+ {
12+ [ TestClass ]
13+ public class ObsoleteCallStatementInspectionTests
14+ {
15+ [ TestMethod ]
16+ public void ObsoleteCallStatement_ReturnsResult ( )
17+ {
18+ const string inputCode =
19+ @"Sub Foo()
20+ Call Foo
21+ End Sub" ;
22+
23+ //Arrange
24+ var builder = new MockVbeBuilder ( ) ;
25+ var project = builder . ProjectBuilder ( "TestProject1" , vbext_ProjectProtection . vbext_pp_none )
26+ . AddComponent ( "Class1" , vbext_ComponentType . vbext_ct_ClassModule , inputCode )
27+ . Build ( ) . Object ;
28+
29+ var codePaneFactory = new RubberduckCodePaneFactory ( ) ;
30+ var parseResult = new RubberduckParser ( codePaneFactory ) . Parse ( project ) ;
31+
32+ var inspection = new ObsoleteCallStatementInspection ( ) ;
33+ var inspectionResults = inspection . GetInspectionResults ( parseResult ) ;
34+
35+ Assert . AreEqual ( 1 , inspectionResults . Count ( ) ) ;
36+ }
37+
38+ [ TestMethod ]
39+ public void ObsoleteCallStatement_DoesNotReturnResult ( )
40+ {
41+ const string inputCode =
42+ @"Sub Foo()
43+ Foo
44+ End Sub" ;
45+
46+ //Arrange
47+ var builder = new MockVbeBuilder ( ) ;
48+ var project = builder . ProjectBuilder ( "TestProject1" , vbext_ProjectProtection . vbext_pp_none )
49+ . AddComponent ( "Class1" , vbext_ComponentType . vbext_ct_ClassModule , inputCode )
50+ . Build ( ) . Object ;
51+
52+ var codePaneFactory = new RubberduckCodePaneFactory ( ) ;
53+ var parseResult = new RubberduckParser ( codePaneFactory ) . Parse ( project ) ;
54+
55+ var inspection = new ObsoleteCallStatementInspection ( ) ;
56+ var inspectionResults = inspection . GetInspectionResults ( parseResult ) ;
57+
58+ Assert . AreEqual ( 0 , inspectionResults . Count ( ) ) ;
59+ }
60+
61+ [ TestMethod ]
62+ public void ObsoleteCallStatement_ReturnsMultipleResults ( )
63+ {
64+ const string inputCode =
65+ @"Sub Foo()
66+ Call Goo(1, ""test"")
67+ End Sub
68+
69+ Sub Goo(arg1 As Integer, arg1 As String)
70+ Call Foo
71+ End Sub" ;
72+
73+ //Arrange
74+ var builder = new MockVbeBuilder ( ) ;
75+ var project = builder . ProjectBuilder ( "TestProject1" , vbext_ProjectProtection . vbext_pp_none )
76+ . AddComponent ( "Class1" , vbext_ComponentType . vbext_ct_ClassModule , inputCode )
77+ . Build ( ) . Object ;
78+
79+ var codePaneFactory = new RubberduckCodePaneFactory ( ) ;
80+ var parseResult = new RubberduckParser ( codePaneFactory ) . Parse ( project ) ;
81+
82+ var inspection = new ObsoleteCallStatementInspection ( ) ;
83+ var inspectionResults = inspection . GetInspectionResults ( parseResult ) ;
84+
85+ Assert . AreEqual ( 2 , inspectionResults . Count ( ) ) ;
86+ }
87+
88+ [ TestMethod ]
89+ public void ObsoleteCallStatement_ReturnsResults_SomeObsoleteCallStatements ( )
90+ {
91+ const string inputCode =
92+ @"Sub Foo()
93+ Call Goo(1, ""test"")
94+ End Sub
95+
96+ Sub Goo(arg1 As Integer, arg1 As String)
97+ Foo
98+ End Sub" ;
99+
100+ //Arrange
101+ var builder = new MockVbeBuilder ( ) ;
102+ var project = builder . ProjectBuilder ( "TestProject1" , vbext_ProjectProtection . vbext_pp_none )
103+ . AddComponent ( "Class1" , vbext_ComponentType . vbext_ct_ClassModule , inputCode )
104+ . Build ( ) . Object ;
105+
106+ var codePaneFactory = new RubberduckCodePaneFactory ( ) ;
107+ var parseResult = new RubberduckParser ( codePaneFactory ) . Parse ( project ) ;
108+
109+ var inspection = new ObsoleteCallStatementInspection ( ) ;
110+ var inspectionResults = inspection . GetInspectionResults ( parseResult ) ;
111+
112+ Assert . AreEqual ( 1 , inspectionResults . Count ( ) ) ;
113+ }
114+
115+ [ TestMethod ]
116+ public void ObsoleteCallStatement_QuickFixWorks_RemoveCallStatement ( )
117+ {
118+ const string inputCode =
119+ @"Sub Foo()
120+ Call Goo(1, ""test"")
121+ End Sub
122+
123+ Sub Goo(arg1 As Integer, arg1 As String)
124+ Call Foo
125+ End Sub" ;
126+
127+ const string expectedCode =
128+ @"Sub Foo()
129+ Goo 1, ""test""
130+ End Sub
131+
132+ Sub Goo(arg1 As Integer, arg1 As String)
133+ Foo
134+ End Sub" ;
135+
136+ //Arrange
137+ var builder = new MockVbeBuilder ( ) ;
138+ var project = builder . ProjectBuilder ( "TestProject1" , vbext_ProjectProtection . vbext_pp_none )
139+ . AddComponent ( "Class1" , vbext_ComponentType . vbext_ct_ClassModule , inputCode )
140+ . Build ( ) . Object ;
141+ var module = project . VBComponents . Item ( 0 ) . CodeModule ;
142+
143+ var codePaneFactory = new RubberduckCodePaneFactory ( ) ;
144+ var parseResult = new RubberduckParser ( codePaneFactory ) . Parse ( project ) ;
145+
146+ var inspection = new ObsoleteCallStatementInspection ( ) ;
147+ var inspectionResults = inspection . GetInspectionResults ( parseResult ) ;
148+
149+ inspectionResults . First ( ) . GetQuickFixes ( ) . First ( ) . Value ( ) ;
150+
151+ Assert . AreEqual ( expectedCode , module . Lines ( ) ) ;
152+ }
153+
154+ [ TestMethod ]
155+ public void InspectionType ( )
156+ {
157+ var inspection = new ObsoleteCallStatementInspection ( ) ;
158+ Assert . AreEqual ( CodeInspectionType . LanguageOpportunities , inspection . InspectionType ) ;
159+ }
160+
161+ [ TestMethod ]
162+ public void InspectionName ( )
163+ {
164+ const string inspectionName = "ObsoleteCallStatementInspection" ;
165+ var inspection = new ObsoleteCallStatementInspection ( ) ;
166+
167+ Assert . AreEqual ( inspectionName , inspection . Name ) ;
168+ }
169+ }
170+ }
0 commit comments