1
1
using System ;
2
+ using System . Collections ;
2
3
using System . Collections . Generic ;
3
4
using System . ComponentModel ;
4
5
using System . Globalization ;
5
6
using System . Linq ;
6
- using System . Windows ;
7
7
using System . Windows . Data ;
8
8
using NLog ;
9
9
using Rubberduck . Common ;
10
- using Rubberduck . Interaction ;
11
10
using Rubberduck . Interaction . Navigation ;
12
11
using Rubberduck . Parsing . VBA ;
13
12
using Rubberduck . Settings ;
16
15
using Rubberduck . UI . UnitTesting . Commands ;
17
16
using Rubberduck . UI . UnitTesting . ViewModels ;
18
17
using Rubberduck . UnitTesting ;
19
- using Rubberduck . VBEditor . SafeComWrappers . Abstract ;
18
+ using DataFormats = System . Windows . DataFormats ;
20
19
21
20
namespace Rubberduck . UI . UnitTesting
22
21
{
@@ -30,39 +29,29 @@ internal enum TestExplorerGrouping
30
29
31
30
internal sealed class TestExplorerViewModel : ViewModelBase , INavigateSelection , IDisposable
32
31
{
33
- private readonly IVBE _vbe ;
34
32
private readonly RubberduckParserState _state ;
35
33
private readonly ITestEngine _testEngine ;
36
34
private readonly IClipboardWriter _clipboard ;
37
35
private readonly ISettingsFormFactory _settingsFormFactory ;
38
- private readonly IMessageBox _messageBox ;
39
- private readonly NavigateCommand _navigateCommand ;
40
36
41
- public TestExplorerViewModel ( IVBE vbe ,
42
- RubberduckParserState state ,
37
+ public TestExplorerViewModel ( RubberduckParserState state ,
43
38
ITestEngine testEngine ,
44
39
TestExplorerModel model ,
45
40
IClipboardWriter clipboard ,
46
41
IGeneralConfigService configService ,
47
- ISettingsFormFactory settingsFormFactory ,
48
- IMessageBox messageBox ,
49
- ReparseCommand reparseCommand )
42
+ ISettingsFormFactory settingsFormFactory )
50
43
{
51
- _vbe = vbe ;
52
44
_state = state ;
53
45
_testEngine = testEngine ;
54
46
_testEngine . TestCompleted += TestEngineTestCompleted ;
55
47
_clipboard = clipboard ;
56
48
_settingsFormFactory = settingsFormFactory ;
57
- _messageBox = messageBox ;
58
-
59
- _navigateCommand = new NavigateCommand ( _state . ProjectsProvider ) ;
60
-
61
- RunSelectedTestCommand = new DelegateCommand ( LogManager . GetCurrentClassLogger ( ) , ExecuteSelectedTestCommand , CanExecuteSelectedTestCommand ) ;
62
- RunSelectedCategoryTestsCommand = new DelegateCommand ( LogManager . GetCurrentClassLogger ( ) , ExecuteRunSelectedCategoryTestsCommand , CanExecuteRunSelectedCategoryTestsCommand ) ;
63
49
50
+ NavigateCommand = new NavigateCommand ( _state . ProjectsProvider ) ;
51
+ RunSingleTestCommand = new DelegateCommand ( LogManager . GetCurrentClassLogger ( ) , ExecuteSingleTestCommand , CanExecuteSingleTestCommand ) ;
52
+ RunSelectedTestsCommand = new DelegateCommand ( LogManager . GetCurrentClassLogger ( ) , ExecuteSelectedTestsCommand , CanExecuteSelectedTestsCommand ) ;
53
+ RunSelectedGroupCommand = new DelegateCommand ( LogManager . GetCurrentClassLogger ( ) , ExecuteRunSelectedCategoryTestsCommand , CanExecuteRunSelectedCategoryTestsCommand ) ;
64
54
CopyResultsCommand = new DelegateCommand ( LogManager . GetCurrentClassLogger ( ) , ExecuteCopyResultsCommand ) ;
65
-
66
55
OpenTestSettingsCommand = new DelegateCommand ( LogManager . GetCurrentClassLogger ( ) , OpenSettings ) ;
67
56
68
57
Model = model ;
@@ -134,8 +123,9 @@ public TestExplorerGrouping TestGrouping
134
123
public RunInconclusiveTestsCommand RunInconclusiveTestsCommand { get ; set ; }
135
124
public RunFailedTestsCommand RunFailedTestsCommand { get ; set ; }
136
125
public RunSucceededTestsCommand RunPassedTestsCommand { get ; set ; }
137
- public CommandBase RunSelectedTestCommand { get ; }
138
- public CommandBase RunSelectedCategoryTestsCommand { get ; }
126
+ public CommandBase RunSingleTestCommand { get ; }
127
+ public CommandBase RunSelectedTestsCommand { get ; }
128
+ public CommandBase RunSelectedGroupCommand { get ; }
139
129
140
130
public AddTestModuleCommand AddTestModuleCommand { get ; set ; }
141
131
public AddTestMethodCommand AddTestMethodCommand { get ; set ; }
@@ -145,7 +135,7 @@ public TestExplorerGrouping TestGrouping
145
135
146
136
public CommandBase OpenTestSettingsCommand { get ; }
147
137
148
- public INavigateCommand NavigateCommand => _navigateCommand ;
138
+ public INavigateCommand NavigateCommand { get ; }
149
139
150
140
private void OpenSettings ( object param )
151
141
{
@@ -160,12 +150,17 @@ private void OpenSettings(object param)
160
150
161
151
public ICollectionView Tests { get ; }
162
152
163
- private bool CanExecuteSelectedTestCommand ( object obj )
153
+ private bool CanExecuteSingleTestCommand ( object obj )
164
154
{
165
155
return ! Model . IsBusy && SelectedItem != null ;
166
156
}
167
157
168
- private void ExecuteSelectedTestCommand ( object obj )
158
+ private bool CanExecuteSelectedTestsCommand ( object obj )
159
+ {
160
+ return ! Model . IsBusy && obj is IList viewModels && viewModels . Count > 0 ;
161
+ }
162
+
163
+ private void ExecuteSingleTestCommand ( object obj )
169
164
{
170
165
if ( SelectedTest == null )
171
166
{
@@ -177,6 +172,25 @@ private void ExecuteSelectedTestCommand(object obj)
177
172
Model . IsBusy = false ;
178
173
}
179
174
175
+ private void ExecuteSelectedTestsCommand ( object obj )
176
+ {
177
+ if ( Model . IsBusy || ! ( obj is IList viewModels && viewModels . Count > 0 ) )
178
+ {
179
+ return ;
180
+ }
181
+
182
+ var models = viewModels . OfType < TestMethodViewModel > ( ) . Select ( model => model . Method ) . ToArray ( ) ;
183
+
184
+ if ( ! models . Any ( ) )
185
+ {
186
+ return ;
187
+ }
188
+
189
+ Model . IsBusy = true ;
190
+ _testEngine . Run ( models ) ;
191
+ Model . IsBusy = false ;
192
+ }
193
+
180
194
private void ExecuteCopyResultsCommand ( object parameter )
181
195
{
182
196
const string XML_SPREADSHEET_DATA_FORMAT = "XML Spreadsheet" ;
0 commit comments