1
- using System ;
2
- using System . Collections . Generic ;
1
+ using System . Collections . Generic ;
3
2
using System . Diagnostics . CodeAnalysis ;
4
3
using System . Linq ;
5
- using System . Text ;
6
- using System . Threading . Tasks ;
7
4
using NUnit . Framework ;
8
5
using Rubberduck . Navigation . CodeExplorer ;
9
6
using Rubberduck . Navigation . Folders ;
10
- using Rubberduck . Parsing . Symbols ;
11
7
12
8
namespace RubberduckTests . CodeExplorer
13
9
{
@@ -246,6 +242,104 @@ public void Constructor_CreatesCorrectSubFolderStructure(params object[] paramet
246
242
AssertFolderStructureIsCorrect ( folder , structure ) ;
247
243
}
248
244
245
+ [ Test ]
246
+ [ Category ( "Code Explorer" ) ]
247
+ [ TestCase ( CodeExplorerTestSetup . TestModuleName , "Foo.Modules" ,
248
+ CodeExplorerTestSetup . TestClassName , "Foo.Classes" ,
249
+ CodeExplorerTestSetup . TestDocumentName , "Foo.Docs" ,
250
+ CodeExplorerTestSetup . TestUserFormName , "Foo.Forms" ) ]
251
+ [ TestCase ( CodeExplorerTestSetup . TestModuleName , "Foo" ,
252
+ CodeExplorerTestSetup . TestDocumentName , "Foo.Bar" ,
253
+ CodeExplorerTestSetup . TestUserFormName , "Foo.Bar" ,
254
+ CodeExplorerTestSetup . TestClassName , "Foo.Bar" ) ]
255
+ [ TestCase ( CodeExplorerTestSetup . TestClassName , "Foo.Bar" ,
256
+ CodeExplorerTestSetup . TestDocumentName , "Foo.Bar.Baz" ,
257
+ CodeExplorerTestSetup . TestUserFormName , "Foo.Bar" ,
258
+ CodeExplorerTestSetup . TestModuleName , "Foo" ) ]
259
+ [ TestCase ( CodeExplorerTestSetup . TestModuleName , "Foo.Bar.Baz" ,
260
+ CodeExplorerTestSetup . TestClassName , "Foo.Bar.Baz" ,
261
+ CodeExplorerTestSetup . TestUserFormName , "Foo.Bar.Baz" ,
262
+ CodeExplorerTestSetup . TestDocumentName , "Foo.Bar.Baz" ) ]
263
+ [ TestCase ( CodeExplorerTestSetup . TestModuleName , "Foo.Baz" ,
264
+ CodeExplorerTestSetup . TestDocumentName , "Foo.Bar" ,
265
+ CodeExplorerTestSetup . TestUserFormName , "Foo.Bar" ,
266
+ CodeExplorerTestSetup . TestClassName , "Foo.Baz" ) ]
267
+ [ TestCase ( CodeExplorerTestSetup . TestModuleName , "Foo" ,
268
+ CodeExplorerTestSetup . TestClassName , "Foo.Bar.Baz" ,
269
+ CodeExplorerTestSetup . TestUserFormName , "Foo.Foo.Foo" ,
270
+ CodeExplorerTestSetup . TestDocumentName , "Foo.Bar.Baz" ) ]
271
+ [ TestCase ( CodeExplorerTestSetup . TestClassName , "Foo Bar.Baz Baz" ,
272
+ CodeExplorerTestSetup . TestDocumentName , "Foo Bar.Baz" ,
273
+ CodeExplorerTestSetup . TestUserFormName , "Foo Bar.Foo Foo" ,
274
+ CodeExplorerTestSetup . TestModuleName , "Foo Bar" ) ]
275
+ public void Synchronize_AddedComponent_HasCorrectSubFolderStructure ( params object [ ] parameters )
276
+ {
277
+ var structure = ToFolderStructure ( parameters . Cast < string > ( ) ) ;
278
+ var root = structure . First ( ) . Folder ;
279
+ var path = root . Split ( FolderExtensions . FolderDelimiter ) ;
280
+
281
+ var declarations = CodeExplorerTestSetup . TestProjectWithFolderStructure ( structure , out var projectDeclaration ) ;
282
+ var synchronizing = CodeExplorerProjectViewModel . ExtractTrackedDeclarationsForProject ( projectDeclaration , ref declarations ) ;
283
+ var component = synchronizing . TestComponentDeclarations ( structure . Last ( ) . Name ) ;
284
+ var contents = synchronizing . Except ( component ) . ToList ( ) ;
285
+
286
+ var project = new CodeExplorerProjectViewModel ( projectDeclaration , ref contents , null , null ) ;
287
+ var folder = project . Children . OfType < CodeExplorerCustomFolderViewModel > ( ) . Single ( item => item . Name . Equals ( path . First ( ) ) ) ;
288
+
289
+ project . Synchronize ( ref synchronizing ) ;
290
+
291
+ AssertFolderStructureIsCorrect ( folder , structure ) ;
292
+ }
293
+
294
+ [ Test ]
295
+ [ Category ( "Code Explorer" ) ]
296
+ [ TestCase ( CodeExplorerTestSetup . TestModuleName , "Foo.Modules" ,
297
+ CodeExplorerTestSetup . TestClassName , "Foo.Classes" ,
298
+ CodeExplorerTestSetup . TestDocumentName , "Foo.Docs" ,
299
+ CodeExplorerTestSetup . TestUserFormName , "Foo.Forms" ) ]
300
+ [ TestCase ( CodeExplorerTestSetup . TestModuleName , "Foo" ,
301
+ CodeExplorerTestSetup . TestClassName , "Foo.Bar" ,
302
+ CodeExplorerTestSetup . TestDocumentName , "Foo.Bar" ,
303
+ CodeExplorerTestSetup . TestUserFormName , "Foo.Bar" ) ]
304
+ [ TestCase ( CodeExplorerTestSetup . TestModuleName , "Foo" ,
305
+ CodeExplorerTestSetup . TestClassName , "Foo.Bar" ,
306
+ CodeExplorerTestSetup . TestDocumentName , "Foo.Bar.Baz" ,
307
+ CodeExplorerTestSetup . TestUserFormName , "Foo.Bar" ) ]
308
+ [ TestCase ( CodeExplorerTestSetup . TestModuleName , "Foo.Bar.Baz" ,
309
+ CodeExplorerTestSetup . TestClassName , "Foo.Bar.Baz" ,
310
+ CodeExplorerTestSetup . TestDocumentName , "Foo.Bar.Baz" ,
311
+ CodeExplorerTestSetup . TestUserFormName , "Foo.Bar.Baz" ) ]
312
+ [ TestCase ( CodeExplorerTestSetup . TestModuleName , "Foo.Baz" ,
313
+ CodeExplorerTestSetup . TestClassName , "Foo.Baz" ,
314
+ CodeExplorerTestSetup . TestDocumentName , "Foo.Bar" ,
315
+ CodeExplorerTestSetup . TestUserFormName , "Foo.Bar" ) ]
316
+ [ TestCase ( CodeExplorerTestSetup . TestModuleName , "Foo" ,
317
+ CodeExplorerTestSetup . TestClassName , "Foo.Bar.Baz" ,
318
+ CodeExplorerTestSetup . TestDocumentName , "Foo.Bar.Baz" ,
319
+ CodeExplorerTestSetup . TestUserFormName , "Foo.Foo.Foo" ) ]
320
+ [ TestCase ( CodeExplorerTestSetup . TestModuleName , "Foo Bar" ,
321
+ CodeExplorerTestSetup . TestClassName , "Foo Bar.Baz Baz" ,
322
+ CodeExplorerTestSetup . TestDocumentName , "Foo Bar.Baz" ,
323
+ CodeExplorerTestSetup . TestUserFormName , "Foo Bar.Foo Foo" ) ]
324
+ public void Synchronize_RemovedComponent_HasCorrectSubFolderStructure ( params object [ ] parameters )
325
+ {
326
+ var structure = ToFolderStructure ( parameters . Cast < string > ( ) ) ;
327
+ var root = structure . First ( ) . Folder ;
328
+ var path = root . Split ( FolderExtensions . FolderDelimiter ) ;
329
+
330
+ var declarations = CodeExplorerTestSetup . TestProjectWithFolderStructure ( structure , out var projectDeclaration ) ;
331
+ var contents = CodeExplorerProjectViewModel . ExtractTrackedDeclarationsForProject ( projectDeclaration , ref declarations ) ;
332
+ var component = contents . TestComponentDeclarations ( structure . Last ( ) . Name ) ;
333
+ var synchronizing = contents . Except ( component ) . ToList ( ) ;
334
+
335
+ var project = new CodeExplorerProjectViewModel ( projectDeclaration , ref contents , null , null ) ;
336
+ var folder = project . Children . OfType < CodeExplorerCustomFolderViewModel > ( ) . Single ( item => item . Name . Equals ( path . First ( ) ) ) ;
337
+
338
+ project . Synchronize ( ref synchronizing ) ;
339
+
340
+ AssertFolderStructureIsCorrect ( folder , structure . Take ( structure . Count - 1 ) . ToList ( ) ) ;
341
+ }
342
+
249
343
private static void AssertFolderStructureIsCorrect ( CodeExplorerCustomFolderViewModel underTest , List < ( string Name , string Folder ) > structure )
250
344
{
251
345
foreach ( var ( name , fullPath ) in structure )
@@ -262,17 +356,17 @@ private static void AssertFolderStructureIsCorrect(CodeExplorerCustomFolderViewM
262
356
path . Take ( folder . FolderDepth + 1 ) ) ) ) ;
263
357
}
264
358
265
- Assert . IsNotNull ( folder ) ;
359
+ Assert . IsNotNull ( folder , $ "Folder { fullPath } was not found." ) ;
266
360
267
361
var components = folder . Children . OfType < CodeExplorerComponentViewModel > ( ) . ToList ( ) ;
268
362
var component = components . SingleOrDefault ( subFolder => subFolder . Name . Equals ( name ) ) ;
269
363
270
- Assert . IsNotNull ( component ) ;
364
+ Assert . IsNotNull ( component , $ "Component { name } was not found in folder { fullPath } ." ) ;
271
365
272
366
var expected = structure . Where ( item => item . Folder . Equals ( fullPath ) ) . Select ( item => item . Name ) . OrderBy ( _ => _ ) ;
273
367
var actual = components . Select ( item => item . Declaration . IdentifierName ) . OrderBy ( _ => _ ) ;
274
368
275
- Assert . IsTrue ( expected . SequenceEqual ( actual ) ) ;
369
+ Assert . IsTrue ( expected . SequenceEqual ( actual ) , $ "Folder { fullPath } does not contain expected components." ) ;
276
370
}
277
371
}
278
372
0 commit comments