@@ -13,11 +13,11 @@ namespace Rubberduck.UI.UnitTesting
13
13
{
14
14
public class TestExplorerDockablePresenter : DockablePresenterBase
15
15
{
16
- private ITestExplorerWindow Control { get { return UserControl as ITestExplorerWindow ; } }
17
- private GridViewSort < TestExplorerItem > _gridViewSort ;
16
+ private readonly GridViewSort < TestExplorerItem > _gridViewSort ;
18
17
private readonly ITestEngine _testEngine ;
18
+ private readonly ITestExplorerWindow _view ;
19
19
20
- public TestExplorerDockablePresenter ( VBE vbe , AddIn addin , IDockableUserControl control , ITestEngine testEngine , GridViewSort < TestExplorerItem > gridViewSort )
20
+ public TestExplorerDockablePresenter ( VBE vbe , AddIn addin , ITestExplorerWindow control , ITestEngine testEngine , GridViewSort < TestExplorerItem > gridViewSort )
21
21
: base ( vbe , addin , control )
22
22
{
23
23
_testEngine = testEngine ;
@@ -28,18 +28,19 @@ public TestExplorerDockablePresenter(VBE vbe, AddIn addin, IDockableUserControl
28
28
_testEngine . MethodInitialize += TestEngineMethodInitialize ;
29
29
_testEngine . MethodCleanup += TestEngineMethodCleanup ;
30
30
31
- Control . SortColumn += SortColumn ;
31
+ _view = control ;
32
+ _view . SortColumn += SortColumn ;
32
33
33
34
RegisterTestExplorerEvents ( ) ;
34
35
}
35
36
36
37
private void SortColumn ( object sender , DataGridViewCellMouseEventArgs e )
37
38
{
38
- var columnName = Control . GridView . Columns [ e . ColumnIndex ] . Name ;
39
+ var columnName = _view . GridView . Columns [ e . ColumnIndex ] . Name ;
39
40
40
41
// type "Image" doesn't implement "IComparable", so we need to sort by the outcome instead
41
42
if ( columnName == RubberduckUI . Result ) { columnName = RubberduckUI . Outcome ; }
42
- Control . AllTests = new BindingList < TestExplorerItem > ( _gridViewSort . Sort ( Control . AllTests . AsEnumerable ( ) , columnName ) . ToList ( ) ) ;
43
+ _view . AllTests = new BindingList < TestExplorerItem > ( _gridViewSort . Sort ( _view . AllTests . AsEnumerable ( ) , columnName ) . ToList ( ) ) ;
43
44
}
44
45
45
46
@@ -70,7 +71,7 @@ private void _testEngine_ModuleInitialize(object sender, TestModuleEventArgs e)
70
71
private void Synchronize ( )
71
72
{
72
73
FindAllTests ( ) ;
73
- Control . Refresh ( _testEngine . AllTests ) ;
74
+ _view . Refresh ( _testEngine . AllTests ) ;
74
75
}
75
76
76
77
public override void Show ( )
@@ -105,15 +106,25 @@ public void RunTests()
105
106
106
107
public void RunTests ( IEnumerable < TestMethod > tests )
107
108
{
108
- Control . ClearResults ( ) ;
109
- Control . SetPlayList ( tests ) ;
110
- Control . ClearProgress ( ) ;
111
- _testEngine . Run ( tests , VBE . ActiveVBProject ) ;
109
+ _view . ClearResults ( ) ;
110
+
111
+ var testMethods = tests as IList < TestMethod > ?? tests . ToList ( ) ; //bypasses multiple enumeration
112
+ _view . SetPlayList ( testMethods ) ;
113
+
114
+ _view . ClearProgress ( ) ;
115
+
116
+ var projects = testMethods . Select ( t => t . QualifiedMemberName . QualifiedModuleName . Project ) . Distinct ( ) ;
117
+ foreach ( var project in projects )
118
+ {
119
+ project . EnsureReferenceToAddInLibrary ( ) ;
120
+ }
121
+
122
+ _testEngine . Run ( testMethods ) ;
112
123
}
113
124
114
125
private void TestComplete ( object sender , TestCompletedEventArgs e )
115
126
{
116
- Control . WriteResult ( e . Test , e . Result ) ;
127
+ _view . WriteResult ( e . Test , e . Result ) ;
117
128
}
118
129
119
130
private void OnExplorerRefreshListButtonClick ( object sender , EventArgs e )
@@ -219,20 +230,20 @@ private void OnExplorerAddTestModuleButtonClick(object sender, EventArgs e)
219
230
220
231
private void RegisterTestExplorerEvents ( )
221
232
{
222
- Control . OnRefreshListButtonClick += OnExplorerRefreshListButtonClick ;
233
+ _view . OnRefreshListButtonClick += OnExplorerRefreshListButtonClick ;
223
234
224
- Control . OnRunAllTestsButtonClick += OnExplorerRunAllTestsButtonClick ;
225
- Control . OnRunFailedTestsButtonClick += OnExplorerRunFailedTestsButtonClick ;
226
- Control . OnRunLastRunTestsButtonClick += OnExplorerRunLastRunTestsButtonClick ;
227
- Control . OnRunNotRunTestsButtonClick += OnExplorerRunNotRunTestsButtonClick ;
228
- Control . OnRunPassedTestsButtonClick += OnExplorerRunPassedTestsButtonClick ;
229
- Control . OnRunSelectedTestButtonClick += OnExplorerRunSelectedTestButtonClick ;
235
+ _view . OnRunAllTestsButtonClick += OnExplorerRunAllTestsButtonClick ;
236
+ _view . OnRunFailedTestsButtonClick += OnExplorerRunFailedTestsButtonClick ;
237
+ _view . OnRunLastRunTestsButtonClick += OnExplorerRunLastRunTestsButtonClick ;
238
+ _view . OnRunNotRunTestsButtonClick += OnExplorerRunNotRunTestsButtonClick ;
239
+ _view . OnRunPassedTestsButtonClick += OnExplorerRunPassedTestsButtonClick ;
240
+ _view . OnRunSelectedTestButtonClick += OnExplorerRunSelectedTestButtonClick ;
230
241
231
- Control . OnGoToSelectedTest += OnExplorerGoToSelectedTest ;
242
+ _view . OnGoToSelectedTest += OnExplorerGoToSelectedTest ;
232
243
233
- Control . OnAddExpectedErrorTestMethodButtonClick += OnExplorerAddExpectedErrorTestMethodButtonClick ;
234
- Control . OnAddTestMethodButtonClick += OnExplorerAddTestMethodButtonClick ;
235
- Control . OnAddTestModuleButtonClick += OnExplorerAddTestModuleButtonClick ;
244
+ _view . OnAddExpectedErrorTestMethodButtonClick += OnExplorerAddExpectedErrorTestMethodButtonClick ;
245
+ _view . OnAddTestMethodButtonClick += OnExplorerAddTestMethodButtonClick ;
246
+ _view . OnAddTestModuleButtonClick += OnExplorerAddTestModuleButtonClick ;
236
247
237
248
_testEngine . TestComplete += TestComplete ;
238
249
}
0 commit comments