File tree Expand file tree Collapse file tree 4 files changed +48
-14
lines changed
RetailCoder.VBE/UnitTesting Expand file tree Collapse file tree 4 files changed +48
-14
lines changed Original file line number Diff line number Diff line change @@ -67,7 +67,8 @@ public void Run(IEnumerable<TestMethod> tests)
67
67
var testCleanup = module . Key . FindTestCleanupMethods ( _state ) . ToList ( ) ;
68
68
69
69
var moduleTestMethods = testMethods
70
- . Where ( test => test . QualifiedMemberName . QualifiedModuleName . ComponentName == module . Key . ComponentName ) ;
70
+ . Where ( test => test . QualifiedMemberName . QualifiedModuleName . ProjectId == module . Key . ProjectId
71
+ && test . QualifiedMemberName . QualifiedModuleName . ComponentName == module . Key . ComponentName ) ;
71
72
72
73
Run ( module . Key . FindModuleInitializeMethods ( _state ) ) ;
73
74
foreach ( var test in moduleTestMethods )
Original file line number Diff line number Diff line change @@ -12,17 +12,6 @@ public struct QualifiedModuleName
12
12
{
13
13
private static string GetDisplayName ( VBProject project )
14
14
{
15
- //Try reading the filename first
16
- try
17
- {
18
- if ( ! string . IsNullOrEmpty ( Path . GetDirectoryName ( project . BuildFileName ) ) )
19
- {
20
- return Path . GetFileName ( project . FileName ) ;
21
- }
22
- }
23
- catch
24
- { //The GetFileName getter probably threw
25
- }
26
15
27
16
if ( project . Protection == vbext_ProjectProtection . vbext_pp_none )
28
17
{
@@ -77,6 +66,19 @@ private static string GetDisplayName(VBProject project)
77
66
//The Properties collection either wasn't available, or didn't have the expected properties
78
67
}
79
68
}
69
+
70
+ //Try reading the filename
71
+ try
72
+ {
73
+ if ( ! string . IsNullOrEmpty ( Path . GetDirectoryName ( project . BuildFileName ) ) )
74
+ {
75
+ return Path . GetFileName ( project . FileName ) ;
76
+ }
77
+ }
78
+ catch
79
+ { //The GetFileName getter probably threw
80
+ }
81
+
80
82
return null ;
81
83
}
82
84
Original file line number Diff line number Diff line change @@ -9,7 +9,14 @@ public ExcelApp(VBE vbe) : base(vbe, "Excel") { }
9
9
10
10
public override void Run ( QualifiedMemberName qualifiedMemberName )
11
11
{
12
- Application . Run ( qualifiedMemberName . ToString ( ) ) ;
12
+ string call = GenerateMethodCall ( qualifiedMemberName ) ;
13
+ Application . Run ( call ) ;
14
+ }
15
+
16
+ protected virtual string GenerateMethodCall ( QualifiedMemberName qualifiedMemberName )
17
+ {
18
+ var documentName = qualifiedMemberName . QualifiedModuleName . ProjectDisplayName ;
19
+ return string . Concat ( documentName , "!" , qualifiedMemberName . ToString ( ) ) ;
13
20
}
14
21
}
15
22
}
Original file line number Diff line number Diff line change 1
1
using Microsoft . Vbe . Interop ;
2
+ using Microsoft . Office . Interop . Word ;
3
+ using System . Linq ;
2
4
3
5
namespace Rubberduck . VBEditor . VBEHost
4
6
{
@@ -10,13 +12,35 @@ public WordApp(VBE vbe) : base(vbe, "Word") { }
10
12
public override void Run ( QualifiedMemberName qualifiedMemberName )
11
13
{
12
14
var call = GenerateMethodCall ( qualifiedMemberName ) ;
13
- Application . Run ( call ) ;
15
+
16
+ ActivateProjectDocument ( qualifiedMemberName ) ;
17
+ //Prevent TE hanging should Application.Run fail
18
+ try
19
+ {
20
+ Application . Run ( call ) ;
21
+ }
22
+ //TODO - Let TestEngine know that the method failed
23
+ catch { } ;
14
24
}
15
25
16
26
protected virtual string GenerateMethodCall ( QualifiedMemberName qualifiedMemberName )
17
27
{
18
28
var moduleName = qualifiedMemberName . QualifiedModuleName . Component . Name ;
19
29
return string . Concat ( moduleName , "." , qualifiedMemberName . MemberName ) ;
20
30
}
31
+
32
+ protected virtual void ActivateProjectDocument ( QualifiedMemberName qualifiedMemberName )
33
+ {
34
+ // Word requires that the document be active for Application.Run to find the target Method in scope.
35
+ // Check the project's document or a document referring to a project's template is active.
36
+ var activeDoc = Application . ActiveDocument ;
37
+ var template = activeDoc . get_AttachedTemplate ( ) ;
38
+ var targetDoc = Application . Documents . Cast < Document > ( )
39
+ . FirstOrDefault ( doc => doc . Name == qualifiedMemberName . QualifiedModuleName . ProjectDisplayName
40
+ || doc . get_AttachedTemplate ( ) . Name == qualifiedMemberName . QualifiedModuleName . ProjectDisplayName ) ;
41
+ if ( activeDoc != targetDoc ) {
42
+ targetDoc . Activate ( ) ;
43
+ }
44
+ }
21
45
}
22
46
}
You can’t perform that action at this time.
0 commit comments