@@ -155,6 +155,48 @@ public void ImportModule()
155
155
vbComponents . Verify ( c => c . Import ( "C:\\ Users\\ Rubberduck\\ Desktop\\ StdModule1.bas" ) , Times . Once ) ;
156
156
}
157
157
158
+ [ TestMethod ]
159
+ public void ImportModule_Cancel ( )
160
+ {
161
+ var builder = new MockVbeBuilder ( ) ;
162
+ var project = builder . ProjectBuilder ( "TestProject1" , vbext_ProjectProtection . vbext_pp_none )
163
+ . AddComponent ( "Module1" , vbext_ComponentType . vbext_ct_StdModule , "" ) ;
164
+
165
+ var vbComponents = project . MockVBComponents ;
166
+
167
+ var vbe = builder . AddProject ( project . Build ( ) ) . Build ( ) ;
168
+ var mockHost = new Mock < IHostApplication > ( ) ;
169
+ mockHost . SetupAllProperties ( ) ;
170
+
171
+ var openFileDialog = new Mock < IOpenFileDialog > ( ) ;
172
+ openFileDialog . Setup ( o => o . AddExtension ) ;
173
+ openFileDialog . Setup ( o => o . AutoUpgradeEnabled ) ;
174
+ openFileDialog . Setup ( o => o . CheckFileExists ) ;
175
+ openFileDialog . Setup ( o => o . Multiselect ) ;
176
+ openFileDialog . Setup ( o => o . ShowHelp ) ;
177
+ openFileDialog . Setup ( o => o . Filter ) ;
178
+ openFileDialog . Setup ( o => o . CheckFileExists ) ;
179
+ openFileDialog . Setup ( o => o . FileName ) . Returns ( "C:\\ Users\\ Rubberduck\\ Desktop\\ StdModule1.bas" ) ;
180
+ openFileDialog . Setup ( o => o . ShowDialog ( ) ) . Returns ( DialogResult . Cancel ) ;
181
+
182
+ var state = new RubberduckParserState ( ) ;
183
+ var commands = new List < ICommand >
184
+ {
185
+ new CodeExplorer_ImportCommand ( openFileDialog . Object )
186
+ } ;
187
+
188
+ var vm = new CodeExplorerViewModel ( state , commands ) ;
189
+
190
+ var parser = MockParser . Create ( vbe . Object , state ) ;
191
+ parser . Parse ( ) ;
192
+ if ( parser . State . Status >= ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
193
+
194
+ vm . SelectedItem = vm . Projects . First ( ) . Items . First ( ) . Items . First ( ) ;
195
+ vm . ImportCommand . Execute ( vm . SelectedItem ) ;
196
+
197
+ vbComponents . Verify ( c => c . Import ( "C:\\ Users\\ Rubberduck\\ Desktop\\ StdModule1.bas" ) , Times . Never ) ;
198
+ }
199
+
158
200
[ TestMethod ]
159
201
public void ExportModule ( )
160
202
{
@@ -189,6 +231,40 @@ public void ExportModule()
189
231
component . Verify ( c => c . Export ( "C:\\ Users\\ Rubberduck\\ Desktop\\ StdModule1.bas" ) , Times . Once ) ;
190
232
}
191
233
234
+ [ TestMethod ]
235
+ public void ExportModule_Cancel ( )
236
+ {
237
+ var builder = new MockVbeBuilder ( ) ;
238
+ var projectMock = builder . ProjectBuilder ( "TestProject1" , vbext_ProjectProtection . vbext_pp_none )
239
+ . AddComponent ( "Module1" , vbext_ComponentType . vbext_ct_StdModule , "" ) ;
240
+
241
+ var project = projectMock . Build ( ) ;
242
+ var vbe = builder . AddProject ( project ) . Build ( ) ;
243
+ var component = projectMock . MockComponents . First ( ) ;
244
+
245
+ var saveFileDialog = new Mock < ISaveFileDialog > ( ) ;
246
+ saveFileDialog . Setup ( o => o . OverwritePrompt ) ;
247
+ saveFileDialog . Setup ( o => o . FileName ) . Returns ( "C:\\ Users\\ Rubberduck\\ Desktop\\ StdModule1.bas" ) ;
248
+ saveFileDialog . Setup ( o => o . ShowDialog ( ) ) . Returns ( DialogResult . Cancel ) ;
249
+
250
+ var state = new RubberduckParserState ( ) ;
251
+ var commands = new List < ICommand >
252
+ {
253
+ new CodeExplorer_ExportCommand ( saveFileDialog . Object )
254
+ } ;
255
+
256
+ var vm = new CodeExplorerViewModel ( state , commands ) ;
257
+
258
+ var parser = MockParser . Create ( vbe . Object , state ) ;
259
+ parser . Parse ( ) ;
260
+ if ( parser . State . Status >= ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
261
+
262
+ vm . SelectedItem = vm . Projects . First ( ) . Items . First ( ) . Items . First ( ) ;
263
+ vm . ExportCommand . Execute ( vm . SelectedItem ) ;
264
+
265
+ component . Verify ( c => c . Export ( "C:\\ Users\\ Rubberduck\\ Desktop\\ StdModule1.bas" ) , Times . Never ) ;
266
+ }
267
+
192
268
[ TestMethod ]
193
269
public void OpenDesigner ( )
194
270
{
@@ -220,7 +296,95 @@ public void OpenDesigner()
220
296
}
221
297
222
298
[ TestMethod ]
223
- public void RemoveModule_Cancel ( )
299
+ public void RemoveModule_Export ( )
300
+ {
301
+ var builder = new MockVbeBuilder ( ) ;
302
+ var projectMock = builder . ProjectBuilder ( "TestProject1" , vbext_ProjectProtection . vbext_pp_none )
303
+ . AddComponent ( "Module1" , vbext_ComponentType . vbext_ct_StdModule , "" ) ;
304
+
305
+ var vbComponents = projectMock . MockVBComponents ;
306
+
307
+ var project = projectMock . Build ( ) ;
308
+ var vbe = builder . AddProject ( project ) . Build ( ) ;
309
+ var component = project . Object . VBComponents . Item ( 0 ) ;
310
+
311
+ var mockHost = new Mock < IHostApplication > ( ) ;
312
+ mockHost . SetupAllProperties ( ) ;
313
+
314
+ var saveFileDialog = new Mock < ISaveFileDialog > ( ) ;
315
+ saveFileDialog . Setup ( o => o . OverwritePrompt ) ;
316
+ saveFileDialog . Setup ( o => o . FileName ) . Returns ( "C:\\ Users\\ Rubberduck\\ Desktop\\ StdModule1.bas" ) ;
317
+ saveFileDialog . Setup ( o => o . ShowDialog ( ) ) . Returns ( DialogResult . OK ) ;
318
+
319
+ var messageBox = new Mock < IMessageBox > ( ) ;
320
+ messageBox . Setup ( m =>
321
+ m . Show ( It . IsAny < string > ( ) , It . IsAny < string > ( ) , It . IsAny < MessageBoxButtons > ( ) ,
322
+ It . IsAny < MessageBoxIcon > ( ) , It . IsAny < MessageBoxDefaultButton > ( ) ) ) . Returns ( DialogResult . Yes ) ;
323
+
324
+ var commands = new List < ICommand >
325
+ {
326
+ new CodeExplorer_RemoveCommand ( saveFileDialog . Object , messageBox . Object )
327
+ } ;
328
+
329
+ var state = new RubberduckParserState ( ) ;
330
+ var vm = new CodeExplorerViewModel ( state , commands ) ;
331
+
332
+ var parser = MockParser . Create ( vbe . Object , state ) ;
333
+ parser . Parse ( ) ;
334
+ if ( parser . State . Status >= ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
335
+
336
+ vm . SelectedItem = vm . Projects . First ( ) . Items . First ( ) . Items . First ( ) ;
337
+ vm . RemoveCommand . Execute ( vm . SelectedItem ) ;
338
+
339
+ vbComponents . Verify ( c => c . Remove ( component ) , Times . Once ) ;
340
+ }
341
+
342
+ [ TestMethod ]
343
+ public void RemoveModule_Export_Cancel ( )
344
+ {
345
+ var builder = new MockVbeBuilder ( ) ;
346
+ var projectMock = builder . ProjectBuilder ( "TestProject1" , vbext_ProjectProtection . vbext_pp_none )
347
+ . AddComponent ( "Module1" , vbext_ComponentType . vbext_ct_StdModule , "" ) ;
348
+
349
+ var vbComponents = projectMock . MockVBComponents ;
350
+
351
+ var project = projectMock . Build ( ) ;
352
+ var vbe = builder . AddProject ( project ) . Build ( ) ;
353
+ var component = project . Object . VBComponents . Item ( 0 ) ;
354
+
355
+ var mockHost = new Mock < IHostApplication > ( ) ;
356
+ mockHost . SetupAllProperties ( ) ;
357
+
358
+ var saveFileDialog = new Mock < ISaveFileDialog > ( ) ;
359
+ saveFileDialog . Setup ( o => o . OverwritePrompt ) ;
360
+ saveFileDialog . Setup ( o => o . FileName ) . Returns ( "C:\\ Users\\ Rubberduck\\ Desktop\\ StdModule1.bas" ) ;
361
+ saveFileDialog . Setup ( o => o . ShowDialog ( ) ) . Returns ( DialogResult . Cancel ) ;
362
+
363
+ var messageBox = new Mock < IMessageBox > ( ) ;
364
+ messageBox . Setup ( m =>
365
+ m . Show ( It . IsAny < string > ( ) , It . IsAny < string > ( ) , It . IsAny < MessageBoxButtons > ( ) ,
366
+ It . IsAny < MessageBoxIcon > ( ) , It . IsAny < MessageBoxDefaultButton > ( ) ) ) . Returns ( DialogResult . Yes ) ;
367
+
368
+ var commands = new List < ICommand >
369
+ {
370
+ new CodeExplorer_RemoveCommand ( saveFileDialog . Object , messageBox . Object )
371
+ } ;
372
+
373
+ var state = new RubberduckParserState ( ) ;
374
+ var vm = new CodeExplorerViewModel ( state , commands ) ;
375
+
376
+ var parser = MockParser . Create ( vbe . Object , state ) ;
377
+ parser . Parse ( ) ;
378
+ if ( parser . State . Status >= ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
379
+
380
+ vm . SelectedItem = vm . Projects . First ( ) . Items . First ( ) . Items . First ( ) ;
381
+ vm . RemoveCommand . Execute ( vm . SelectedItem ) ;
382
+
383
+ vbComponents . Verify ( c => c . Remove ( component ) , Times . Never ) ;
384
+ }
385
+
386
+ [ TestMethod ]
387
+ public void RemoveModule_NoExport ( )
224
388
{
225
389
var builder = new MockVbeBuilder ( ) ;
226
390
var projectMock = builder . ProjectBuilder ( "TestProject1" , vbext_ProjectProtection . vbext_pp_none )
@@ -238,7 +402,7 @@ public void RemoveModule_Cancel()
238
402
var messageBox = new Mock < IMessageBox > ( ) ;
239
403
messageBox . Setup ( m =>
240
404
m . Show ( It . IsAny < string > ( ) , It . IsAny < string > ( ) , It . IsAny < MessageBoxButtons > ( ) ,
241
- It . IsAny < MessageBoxIcon > ( ) ) ) . Returns ( DialogResult . No ) ;
405
+ It . IsAny < MessageBoxIcon > ( ) , It . IsAny < MessageBoxDefaultButton > ( ) ) ) . Returns ( DialogResult . No ) ;
242
406
243
407
var commands = new List < ICommand >
244
408
{
@@ -258,6 +422,45 @@ public void RemoveModule_Cancel()
258
422
vbComponents . Verify ( c => c . Remove ( component ) , Times . Once ) ;
259
423
}
260
424
425
+ [ TestMethod ]
426
+ public void RemoveModule_Cancel ( )
427
+ {
428
+ var builder = new MockVbeBuilder ( ) ;
429
+ var projectMock = builder . ProjectBuilder ( "TestProject1" , vbext_ProjectProtection . vbext_pp_none )
430
+ . AddComponent ( "Module1" , vbext_ComponentType . vbext_ct_StdModule , "" ) ;
431
+
432
+ var vbComponents = projectMock . MockVBComponents ;
433
+
434
+ var project = projectMock . Build ( ) ;
435
+ var vbe = builder . AddProject ( project ) . Build ( ) ;
436
+ var component = project . Object . VBComponents . Item ( 0 ) ;
437
+
438
+ var mockHost = new Mock < IHostApplication > ( ) ;
439
+ mockHost . SetupAllProperties ( ) ;
440
+
441
+ var messageBox = new Mock < IMessageBox > ( ) ;
442
+ messageBox . Setup ( m =>
443
+ m . Show ( It . IsAny < string > ( ) , It . IsAny < string > ( ) , It . IsAny < MessageBoxButtons > ( ) ,
444
+ It . IsAny < MessageBoxIcon > ( ) , It . IsAny < MessageBoxDefaultButton > ( ) ) ) . Returns ( DialogResult . Cancel ) ;
445
+
446
+ var commands = new List < ICommand >
447
+ {
448
+ new CodeExplorer_RemoveCommand ( null , messageBox . Object )
449
+ } ;
450
+
451
+ var state = new RubberduckParserState ( ) ;
452
+ var vm = new CodeExplorerViewModel ( state , commands ) ;
453
+
454
+ var parser = MockParser . Create ( vbe . Object , state ) ;
455
+ parser . Parse ( ) ;
456
+ if ( parser . State . Status >= ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
457
+
458
+ vm . SelectedItem = vm . Projects . First ( ) . Items . First ( ) . Items . First ( ) ;
459
+ vm . RemoveCommand . Execute ( vm . SelectedItem ) ;
460
+
461
+ vbComponents . Verify ( c => c . Remove ( component ) , Times . Never ) ;
462
+ }
463
+
261
464
[ TestMethod ]
262
465
public void IndentModule ( )
263
466
{
0 commit comments