Skip to content

Commit 983ee81

Browse files
authored
Merge branch 'next' into fixCommandBar
2 parents b1ca072 + b445137 commit 983ee81

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

RetailCoder.VBE/UI/Command/AddTestMethodCommand.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ protected override bool CanExecuteImpl(object parameter)
3434
d.DeclarationType == DeclarationType.ProceduralModule &&
3535
d.Annotations.Any(a => a.AnnotationType == AnnotationType.TestModule));
3636

37-
return testModules.Any(a => a.QualifiedName.QualifiedModuleName.Component == _vbe.SelectedVBComponent);
37+
// the code modules consistently match correctly, but the components don't
38+
return testModules.Any(a => a.QualifiedName.QualifiedModuleName.Component.CodeModule == _vbe.SelectedVBComponent.CodeModule);
3839
}
3940

4041
protected override void ExecuteImpl(object parameter)

RetailCoder.VBE/UI/Command/AddTestMethodExpectedErrorCommand.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ protected override bool CanExecuteImpl(object parameter)
3434
d.DeclarationType == DeclarationType.ProceduralModule &&
3535
d.Annotations.Any(a => a.AnnotationType == AnnotationType.TestModule));
3636

37-
return testModules.Any(a => a.QualifiedName.QualifiedModuleName.Component == _vbe.SelectedVBComponent);
37+
// the code modules consistently match correctly, but the components don't
38+
return testModules.Any(a => a.QualifiedName.QualifiedModuleName.Component.CodeModule == _vbe.SelectedVBComponent.CodeModule);
3839
}
3940

4041
protected override void ExecuteImpl(object parameter)

RetailCoder.VBE/UnitTesting/NewTestMethodCommand.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Runtime.InteropServices;
33
using Microsoft.Vbe.Interop;
44
using Rubberduck.Parsing.Annotations;
5+
using Rubberduck.Parsing.Symbols;
56
using Rubberduck.Parsing.VBA;
67
using Rubberduck.UI;
78

@@ -67,11 +68,12 @@ public void NewTestMethod()
6768

6869
try
6970
{
70-
var declaration = _state.AllUserDeclarations.First(f =>
71-
f.DeclarationType == Parsing.Symbols.DeclarationType.ProceduralModule &&
71+
var declaration = _state.AllUserDeclarations.FirstOrDefault(f =>
7272
f.QualifiedName.QualifiedModuleName.Component.CodeModule == _vbe.ActiveCodePane.CodeModule);
7373

74-
if (declaration.Annotations.Any(a => a.AnnotationType == AnnotationType.TestModule))
74+
if (declaration != null &&
75+
declaration.DeclarationType == DeclarationType.ProceduralModule &&
76+
declaration.Annotations.Any(a => a.AnnotationType == AnnotationType.TestModule))
7577
{
7678
var module = _vbe.ActiveCodePane.CodeModule;
7779
var name = GetNextTestMethodName(module.Parent);
@@ -95,11 +97,12 @@ public void NewExpectedErrorTestMethod()
9597

9698
try
9799
{
98-
var declaration = _state.AllUserDeclarations.First(f =>
99-
f.DeclarationType == Parsing.Symbols.DeclarationType.ProceduralModule &&
100+
var declaration = _state.AllUserDeclarations.FirstOrDefault(f =>
100101
f.QualifiedName.QualifiedModuleName.Component.CodeModule == _vbe.ActiveCodePane.CodeModule);
101102

102-
if (declaration.Annotations.Any(a => a.AnnotationType == AnnotationType.TestModule))
103+
if (declaration != null &&
104+
declaration.DeclarationType == DeclarationType.ProceduralModule &&
105+
declaration.Annotations.Any(a => a.AnnotationType == AnnotationType.TestModule))
103106
{
104107
var module = _vbe.ActiveCodePane.CodeModule;
105108
var name = GetNextTestMethodName(module.Parent);

0 commit comments

Comments
 (0)