|
6 | 6 | using Rubberduck.VBEditor.SafeComWrappers;
|
7 | 7 | using Rubberduck.VBEditor.Utility;
|
8 | 8 | using System;
|
| 9 | +using System.Collections.Generic; |
9 | 10 | using System.Linq;
|
10 | 11 | using System.Runtime.InteropServices;
|
11 | 12 | using System.Runtime.InteropServices.ComTypes;
|
@@ -89,6 +90,70 @@ Dim d As Boolean
|
89 | 90 | }
|
90 | 91 | }
|
91 | 92 |
|
| 93 | + [Category("Code Explorer")] |
| 94 | + [Test] |
| 95 | + public void AddedModuleIsAtCorrectDepth_FirstAnnotation() |
| 96 | + { |
| 97 | + const string inputCode = |
| 98 | +@"'@Folder(""First.Second.Third"") |
| 99 | +
|
| 100 | +Sub Foo() |
| 101 | +Dim d As Boolean |
| 102 | +d = True |
| 103 | +End Sub"; |
| 104 | + |
| 105 | + using (var explorer = new MockedCodeExplorer(ProjectType.HostProject, new[] { ComponentType.StandardModule }, new[] { inputCode }) |
| 106 | + .SelectFirstCustomFolder()) |
| 107 | + { |
| 108 | + var project = explorer.ViewModel.Projects.OfType<CodeExplorerProjectViewModel>().First(); |
| 109 | + var folder = (CodeExplorerCustomFolderViewModel)explorer.ViewModel.SelectedItem; |
| 110 | + var declarations = project.State.AllUserDeclarations.ToList(); |
| 111 | + |
| 112 | + var annotation = new FolderAnnotation(new QualifiedSelection(project.Declaration.QualifiedModuleName, new Selection(1, 1)), null, new[] { "\"First\"" }); |
| 113 | + var predeclared = new PredeclaredIdAnnotation(new QualifiedSelection(project.Declaration.QualifiedModuleName, new Selection(2, 1)), null, Enumerable.Empty<string>()); |
| 114 | + |
| 115 | + declarations.Add(GetNewClassDeclaration(project.Declaration, "Foo", new IAnnotation [] { annotation, predeclared })); |
| 116 | + |
| 117 | + project.Synchronize(declarations); |
| 118 | + var added = folder.Children.OfType<CodeExplorerComponentViewModel>().Single(); |
| 119 | + |
| 120 | + Assert.AreEqual(DeclarationType.ClassModule, added.Declaration.DeclarationType); |
| 121 | + Assert.AreEqual("\"First\"", added.Declaration.CustomFolder); |
| 122 | + } |
| 123 | + } |
| 124 | + |
| 125 | + [Category("Code Explorer")] |
| 126 | + [Test] |
| 127 | + public void AddedModuleIsAtCorrectDepth_NotFirstAnnotation() |
| 128 | + { |
| 129 | + const string inputCode = |
| 130 | +@"'@Folder(""First.Second.Third"") |
| 131 | +
|
| 132 | +Sub Foo() |
| 133 | +Dim d As Boolean |
| 134 | +d = True |
| 135 | +End Sub"; |
| 136 | + |
| 137 | + using (var explorer = new MockedCodeExplorer(ProjectType.HostProject, new[] { ComponentType.StandardModule }, new[] { inputCode }) |
| 138 | + .SelectFirstCustomFolder()) |
| 139 | + { |
| 140 | + var project = explorer.ViewModel.Projects.OfType<CodeExplorerProjectViewModel>().First(); |
| 141 | + var folder = (CodeExplorerCustomFolderViewModel)explorer.ViewModel.SelectedItem; |
| 142 | + var declarations = project.State.AllUserDeclarations.ToList(); |
| 143 | + |
| 144 | + var annotation = new FolderAnnotation(new QualifiedSelection(project.Declaration.QualifiedModuleName, new Selection(2, 1)), null, new[] { "\"First\"" }); |
| 145 | + var predeclared = new PredeclaredIdAnnotation(new QualifiedSelection(project.Declaration.QualifiedModuleName, new Selection(1, 1)), null, Enumerable.Empty<string>()); |
| 146 | + |
| 147 | + declarations.Add(GetNewClassDeclaration(project.Declaration, "Foo", new IAnnotation[] { predeclared, annotation })); |
| 148 | + |
| 149 | + project.Synchronize(declarations); |
| 150 | + var added = folder.Children.OfType<CodeExplorerComponentViewModel>().Single(); |
| 151 | + |
| 152 | + Assert.AreEqual(DeclarationType.ClassModule, added.Declaration.DeclarationType); |
| 153 | + Assert.AreEqual("\"First\"", added.Declaration.CustomFolder); |
| 154 | + } |
| 155 | + } |
| 156 | + |
92 | 157 | [Category("Code Explorer")]
|
93 | 158 | [Test]
|
94 | 159 | public void AddedModuleIsAtCorrectDepth_RootNode()
|
@@ -298,6 +363,11 @@ private static Declaration GetNewClassDeclaration(Declaration project, string na
|
298 | 363 | ? Enumerable.Empty<IAnnotation>()
|
299 | 364 | : new[] { new FolderAnnotation(new QualifiedSelection(project.QualifiedModuleName, new Selection(1, 1)), null, new[] { folder }) };
|
300 | 365 |
|
| 366 | + return GetNewClassDeclaration(project, name, annotations); |
| 367 | + } |
| 368 | + |
| 369 | + private static Declaration GetNewClassDeclaration(Declaration project, string name, IEnumerable<IAnnotation> annotations) |
| 370 | + { |
301 | 371 | var declaration =
|
302 | 372 | new ClassModuleDeclaration(new QualifiedMemberName(project.QualifiedModuleName, name), project, name, true, annotations, new Attributes());
|
303 | 373 |
|
|
0 commit comments