Skip to content

Commit 7e4c572

Browse files
committed
Fix CE tests broken in last commit
The problem was that they passed null as the parser state, which caused an NRE with the new setup.
1 parent 6efdf24 commit 7e4c572

File tree

7 files changed

+220
-149
lines changed

7 files changed

+220
-149
lines changed

Rubberduck.Core/CodeAnalysis/CodeMetrics/CodeMetricsViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private void Synchronize(IEnumerable<Declaration> declarations)
8484

8585
foreach (var project in adding)
8686
{
87-
var model = new CodeExplorerProjectViewModel(project, ref updates, _state, _vbe, false);
87+
var model = new CodeExplorerProjectViewModel(project, ref updates, _state, _vbe, _state.ProjectsProvider,false);
8888
Projects.Add(model);
8989
}
9090
}).Wait();

Rubberduck.Core/Navigation/CodeExplorer/CodeExplorerProjectViewModel.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Rubberduck.Navigation.Folders;
66
using Rubberduck.Parsing.Symbols;
77
using Rubberduck.Parsing.VBA;
8+
using Rubberduck.VBEditor.ComManagement;
89
using Rubberduck.VBEditor.SafeComWrappers;
910
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
1011

@@ -21,17 +22,20 @@ public class CodeExplorerProjectViewModel : CodeExplorerItemViewModel
2122
};
2223

2324
private readonly IVBE _vbe;
25+
private readonly IProjectsProvider _projectsProvider;
2426

2527
public CodeExplorerProjectViewModel(
2628
Declaration project,
2729
ref List<Declaration> declarations,
2830
RubberduckParserState state,
2931
IVBE vbe,
32+
IProjectsProvider projectsProvider,
3033
bool references = true)
3134
: base(null, project)
3235
{
33-
State = state;
36+
State = state;
3437
_vbe = vbe;
38+
_projectsProvider = projectsProvider;
3539
ShowReferences = references;
3640

3741
SetName();
@@ -58,7 +62,7 @@ public override FontWeight FontWeight
5862
return base.FontWeight;
5963
}
6064

61-
var project = State.ProjectsProvider.Project(Declaration.ProjectId);
65+
var project = _projectsProvider.Project(Declaration.ProjectId);
6266
if (project == null)
6367
{
6468
return base.FontWeight;
@@ -158,7 +162,7 @@ private List<ReferenceModel> GetProjectReferenceModels()
158162
return new List<ReferenceModel>();
159163
}
160164

161-
var project = State.ProjectsProvider.Project(Declaration.ProjectId);
165+
var project = _projectsProvider.Project(Declaration.ProjectId);
162166
if (project == null)
163167
{
164168
return new List<ReferenceModel>();

Rubberduck.Core/Navigation/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ private void Synchronize(IEnumerable<Declaration> declarations)
286286

287287
foreach (var project in adding)
288288
{
289-
var model = new CodeExplorerProjectViewModel(project, ref updates, _state, _vbe) { Filter = Search };
289+
var model = new CodeExplorerProjectViewModel(project, ref updates, _state, _vbe, _state.ProjectsProvider) { Filter = Search };
290290
Projects.Add(model);
291291
}
292292

RubberduckTests/CodeExplorer/CodeExplorerCustomFolderViewModelTests.cs

Lines changed: 173 additions & 109 deletions
Large diffs are not rendered by default.

RubberduckTests/CodeExplorer/CodeExplorerProjectViewModelTests.cs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System.Collections.Generic;
22
using NUnit.Framework;
33
using System.Linq;
4-
using System.Runtime.InteropServices;
54
using Rubberduck.AddRemoveReferences;
65
using Rubberduck.Parsing.Symbols;
76
using Rubberduck.Navigation.CodeExplorer;
@@ -21,7 +20,7 @@ public void Constructor_SetsDeclaration()
2120
var declarations = CodeExplorerTestSetup.TestProjectOneDeclarations;
2221
var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);
2322

24-
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null);
23+
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null, CodeExplorerTestSetup.ProjectOneProvider);
2524

2625
Assert.AreSame(projectDeclaration, project.Declaration);
2726
}
@@ -33,7 +32,7 @@ public void Constructor_SetsName()
3332
var declarations = CodeExplorerTestSetup.TestProjectOneDeclarations;
3433
var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);
3534

36-
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null);
35+
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null, CodeExplorerTestSetup.ProjectOneProvider);
3736

3837
Assert.AreEqual(CodeExplorerTestSetup.TestProjectOneName, project.Name);
3938
}
@@ -45,7 +44,7 @@ public void Constructor_NameWithSignatureIsSet()
4544
var declarations = CodeExplorerTestSetup.TestProjectOneDeclarations;
4645
var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);
4746

48-
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null);
47+
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null, CodeExplorerTestSetup.ProjectOneProvider);
4948

5049
Assert.IsFalse(string.IsNullOrEmpty(project.NameWithSignature));
5150
}
@@ -57,7 +56,7 @@ public void Constructor_PanelTitleIsSet()
5756
var declarations = CodeExplorerTestSetup.TestProjectOneDeclarations;
5857
var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);
5958

60-
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null);
59+
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null, CodeExplorerTestSetup.ProjectOneProvider);
6160

6261
Assert.IsFalse(string.IsNullOrEmpty(project.PanelTitle));
6362
}
@@ -69,7 +68,7 @@ public void Constructor_SetsIsExpandedTrue()
6968
var declarations = CodeExplorerTestSetup.TestProjectOneDeclarations;
7069
var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);
7170

72-
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null);
71+
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null, CodeExplorerTestSetup.ProjectOneProvider);
7372

7473
Assert.IsTrue(project.IsExpanded);
7574
}
@@ -81,7 +80,7 @@ public void Constructor_ToolTipIsSet()
8180
var declarations = CodeExplorerTestSetup.TestProjectOneDeclarations;
8281
var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);
8382

84-
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null);
83+
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null, CodeExplorerTestSetup.ProjectOneProvider);
8584

8685
Assert.IsFalse(string.IsNullOrEmpty(project.ToolTip));
8786
}
@@ -99,7 +98,7 @@ public void SortComparerIsNodeType(CodeExplorerSortOrder order)
9998
var declarations = CodeExplorerTestSetup.TestProjectOneDeclarations;
10099
var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);
101100

102-
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null)
101+
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null, CodeExplorerTestSetup.ProjectOneProvider)
103102
{
104103
SortOrder = order
105104
};
@@ -117,7 +116,7 @@ public void IsNotFiltered(string filter)
117116
var declarations = CodeExplorerTestSetup.TestProjectOneDeclarations;
118117
var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);
119118

120-
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null)
119+
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null, CodeExplorerTestSetup.ProjectOneProvider)
121120
{
122121
Filter = filter
123122
};
@@ -173,7 +172,7 @@ public void Constructor_CreatesDefaultProjectFolder()
173172
var declarations = CodeExplorerTestSetup.TestProjectOneDeclarations;
174173
var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);
175174

176-
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null);
175+
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null, CodeExplorerTestSetup.ProjectOneProvider);
177176
var folder = project.Children.OfType<CodeExplorerCustomFolderViewModel>().Single();
178177

179178
Assert.AreEqual(projectDeclaration.IdentifierName, folder.Name);
@@ -187,7 +186,7 @@ public void Constructor_ClearsDeclarationList()
187186
var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);
188187

189188
// ReSharper disable once UnusedVariable
190-
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null);
189+
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null, CodeExplorerTestSetup.ProjectOneProvider);
191190

192191
Assert.AreEqual(0, declarations.Count);
193192
}
@@ -200,7 +199,7 @@ public void Synchronize_UsesDefaultProjectFolder_NoChanges()
200199
var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);
201200
var updates = declarations.ToList();
202201

203-
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null);
202+
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null, CodeExplorerTestSetup.ProjectOneProvider);
204203

205204
project.Synchronize(ref updates);
206205

@@ -216,7 +215,7 @@ public void Synchronize_ClearsPassedDeclarationList_NoChanges()
216215
var declarations = CodeExplorerTestSetup.TestProjectOneDeclarations;
217216
var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);
218217

219-
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null);
218+
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null, CodeExplorerTestSetup.ProjectOneProvider);
220219
var updates = CodeExplorerTestSetup.TestProjectOneDeclarations;
221220
project.Synchronize(ref updates);
222221

@@ -230,7 +229,7 @@ public void Synchronize_DoesNotAlterDeclarationList_DifferentProject()
230229
var declarations = CodeExplorerTestSetup.TestProjectOneDeclarations;
231230
var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);
232231

233-
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null);
232+
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null, CodeExplorerTestSetup.ProjectOneProvider);
234233
var updates = CodeExplorerTestSetup.TestProjectTwoDeclarations;
235234
project.Synchronize(ref updates);
236235

@@ -252,7 +251,7 @@ public void Constructor_PlacesAllTrackedDeclarations()
252251
var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);
253252
var results = declarations.ToList();
254253

255-
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null);
254+
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null, CodeExplorerTestSetup.ProjectOneProvider);
256255

257256
var expected =
258257
CodeExplorerProjectViewModel.ExtractTrackedDeclarationsForProject(projectDeclaration, ref results)
@@ -273,7 +272,7 @@ public void Synchronize_PlacesAllTrackedDeclarations_NoChanges()
273272
var declarations = CodeExplorerTestSetup.TestProjectOneDeclarations;
274273
var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);
275274

276-
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null);
275+
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null, CodeExplorerTestSetup.ProjectOneProvider);
277276
var updates = CodeExplorerTestSetup.TestProjectOneDeclarations;
278277
var results = updates.ToList();
279278

@@ -302,7 +301,7 @@ public void Synchronize_PlacesAllTrackedDeclarations_AddedComponent(string compo
302301
var declarations = CodeExplorerTestSetup.TestProjectOneDeclarations
303302
.TestProjectWithComponentDeclarations(new[] { component },out var projectDeclaration);
304303

305-
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null);
304+
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null, CodeExplorerTestSetup.ProjectOneProvider);
306305

307306
var updates = CodeExplorerTestSetup.TestProjectOneDeclarations
308307
.TestProjectWithComponentDeclarations(new[] { component, added }, out _).ToList();
@@ -335,7 +334,7 @@ public void Synchronize_AddedComponent_SingleProjectFolderExists(string componen
335334
var declarations = CodeExplorerTestSetup.TestProjectOneDeclarations
336335
.TestProjectWithComponentDeclarations(new[] { component }, out var projectDeclaration);
337336

338-
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null);
337+
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null, CodeExplorerTestSetup.ProjectOneProvider);
339338

340339
var updates = CodeExplorerTestSetup.TestProjectOneDeclarations
341340
.TestProjectWithComponentDeclarations(new[] { component, added }, out _);
@@ -359,7 +358,7 @@ public void Synchronize_RemovesComponent(string removed)
359358
var declarations = CodeExplorerTestSetup.TestProjectOneDeclarations;
360359
var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);
361360

362-
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null);
361+
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null, CodeExplorerTestSetup.ProjectOneProvider);
363362

364363
var updates = CodeExplorerTestSetup.TestProjectOneDeclarations.TestProjectWithComponentRemoved(removed);
365364
var expected = updates.Select(declaration => declaration.QualifiedName.ToString())
@@ -382,7 +381,7 @@ public void Synchronize_SetsDeclarationNull_NoDeclarationsForProject()
382381
var declarations = CodeExplorerTestSetup.TestProjectOneDeclarations;
383382
var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);
384383

385-
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null);
384+
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null, CodeExplorerTestSetup.ProjectOneProvider);
386385
if (project.Declaration is null)
387386
{
388387
Assert.Inconclusive("Project declaration is null. Fix test setup and see why no other tests failed.");
@@ -401,7 +400,7 @@ public void Synchronize_SetsDeclarationNull_DeclarationsForDifferentProject()
401400
var declarations = CodeExplorerTestSetup.TestProjectOneDeclarations;
402401
var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);
403402

404-
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null);
403+
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null, CodeExplorerTestSetup.ProjectOneProvider);
405404
if (project.Declaration is null)
406405
{
407406
Assert.Inconclusive("Project declaration is null. Fix test setup and see why no other tests failed.");
@@ -426,7 +425,7 @@ public void Constructor_CreatesReferenceFolders(bool libraries, bool projects)
426425
{
427426
var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);
428427

429-
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null);
428+
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, state, null, state.ProjectsProvider);
430429

431430
var libraryFolder = project.Children.OfType<CodeExplorerReferenceFolderViewModel>()
432431
.SingleOrDefault(folder => folder.ReferenceKind == ReferenceKind.TypeLibrary);
@@ -454,7 +453,7 @@ public void Synchronize_ReferenceFolders_NoChanges(bool libraries, bool projects
454453

455454
var expected = GetReferencesFromProjectDeclaration(projectDeclaration, state.ProjectsProvider).Select(reference => reference.Name).ToList();
456455

457-
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null);
456+
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, state, null, state.ProjectsProvider);
458457
project.Synchronize(ref updates);
459458

460459
var actual = GetReferencesFromProjectViewModel(project).OrderBy(reference => reference.Priority).Select(reference => reference.Name);
@@ -477,7 +476,7 @@ public void Synchronize_ReferenceFolderRemoved(bool libraries, bool projects)
477476
var updates = declarations.ToList();
478477
var projectDeclaration = declarations.First(declaration => declaration.DeclarationType == DeclarationType.Project);
479478

480-
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, null, null);
479+
var project = new CodeExplorerProjectViewModel(projectDeclaration, ref declarations, state, null, state.ProjectsProvider);
481480

482481
var references = state.ProjectsProvider.Project(projectDeclaration.ProjectId).References;
483482
foreach (var reference in references.ToList())

0 commit comments

Comments
 (0)