1
1
using System ;
2
2
using System . Collections . Generic ;
3
+ using System . Linq ;
3
4
using Microsoft . Vbe . Interop ;
4
5
using Microsoft . VisualStudio . TestTools . UnitTesting ;
5
6
using Moq ;
@@ -27,7 +28,7 @@ private void CleanUp()
27
28
}
28
29
29
30
[ TestMethod ]
30
- public void RemoveParamatersRefactoring_RemoveOnlyParam ( )
31
+ public void RemoveParamatersRefactoring_RemoveBothParams ( )
31
32
{
32
33
//Input
33
34
const string inputCode =
@@ -62,7 +63,7 @@ public void RemoveParamatersRefactoring_RemoveOnlyParam()
62
63
}
63
64
64
65
[ TestMethod ]
65
- public void RemoveParamatersRefactoring_RemoveBothParams ( )
66
+ public void RemoveParamatersRefactoring_RemoveOnlyParam ( )
66
67
{
67
68
//Input
68
69
const string inputCode =
@@ -166,6 +167,51 @@ public void RemoveParamatersRefactoring_RemoveSecondParam()
166
167
Assert . AreEqual ( expectedCode , _module . Object . Lines ( ) ) ;
167
168
}
168
169
170
+ [ TestMethod ]
171
+ public void RemoveParamatersRefactoring_ClientReferencesAreUpdated ( )
172
+ {
173
+ //Input
174
+ const string inputCode =
175
+ @"Private Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
176
+ End Sub
177
+
178
+ Private Sub Bar()
179
+ Foo 10, ""Hello""
180
+ End Sub
181
+ " ;
182
+ var selection = new Selection ( 1 , 23 , 1 , 27 ) ; //startLine, startCol, endLine, endCol
183
+
184
+ //Expectation
185
+ const string expectedCode =
186
+ @"Private Sub Foo(ByVal arg1 As Integer )
187
+ End Sub
188
+
189
+ Private Sub Bar()
190
+ Foo 10
191
+ End Sub
192
+ " ; //note: The IDE strips out the extra whitespace, you can't see it but there's a space after "Foo 10 "
193
+
194
+ //Arrange
195
+ SetupProject ( inputCode ) ;
196
+ var parseResult = new RubberduckParser ( ) . Parse ( _project . Object ) ;
197
+
198
+ var qualifiedSelection = GetQualifiedSelection ( selection ) ;
199
+
200
+ //Specify Param(s) to remove
201
+ var model = new RemoveParametersModel ( parseResult , qualifiedSelection ) ;
202
+ model . Parameters [ 1 ] . IsRemoved = true ;
203
+
204
+ //SetupFactory
205
+ var factory = SetupFactory ( model ) ;
206
+
207
+ //Act
208
+ var refactoring = new RemoveParametersRefactoring ( factory . Object ) ;
209
+ refactoring . Refactor ( qualifiedSelection ) ;
210
+
211
+ //Assert
212
+ Assert . AreEqual ( expectedCode , _module . Object . Lines ( ) ) ;
213
+ }
214
+
169
215
#region setup
170
216
private QualifiedSelection GetQualifiedSelection ( Selection selection )
171
217
{
@@ -201,6 +247,7 @@ private void SetupProject(string inputCode)
201
247
202
248
_module = Mocks . MockFactory . CreateCodeModuleMock ( inputCode ) ;
203
249
_module . SetupGet ( m => m . CodePane ) . Returns ( codePane . Object ) ;
250
+
204
251
_module . Setup ( m => m . ReplaceLine ( It . IsAny < int > ( ) , It . IsAny < string > ( ) ) )
205
252
. Callback < int , string > ( ( i , s ) => ReplaceModuleLine ( _module , i , s ) ) ;
206
253
@@ -217,14 +264,15 @@ private void SetupProject(string inputCode)
217
264
218
265
private static void ReplaceModuleLine ( Mock < CodeModule > module , int lineNumber , string newLine )
219
266
{
220
- var lines = module . Object . Lines ( ) . Split ( new [ ] { Environment . NewLine } , StringSplitOptions . None ) ;
267
+ var lines = module . Object . Lines ( ) . Split ( new [ ] { Environment . NewLine } , StringSplitOptions . None ) ;
221
268
222
269
lines [ lineNumber - 1 ] = newLine ;
223
270
224
271
var newCode = String . Join ( Environment . NewLine , lines ) ;
225
272
226
273
module . SetupGet ( c => c . get_Lines ( 1 , lines . Length ) ) . Returns ( newCode ) ;
227
274
}
275
+
228
276
#endregion
229
277
}
230
278
}
0 commit comments