Skip to content

Commit 2ef8d61

Browse files
committed
Allow selecting and running multiple tests. Closes #4701
1 parent b8b12c4 commit 2ef8d61

File tree

2 files changed

+44
-31
lines changed

2 files changed

+44
-31
lines changed

Rubberduck.Core/UI/UnitTesting/TestExplorerControl.xaml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,16 +270,13 @@
270270
<Image Source="{StaticResource RunNotRunTestsImage}" />
271271
</MenuItem.Icon>
272272
</MenuItem>
273-
<MenuItem Command="{Binding RunSelectedTestCommand}" Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer ,Key=TestExplorer_RunSelectedTests}" >
273+
<MenuItem Command="{Binding RunSelectedTestsCommand}"
274+
CommandParameter="{Binding ElementName=TestGrid, Path=SelectedItems}"
275+
Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer ,Key=TestExplorer_RunSelectedTests}" >
274276
<MenuItem.Icon>
275277
<Image Source="{StaticResource RunSelectedTestImage}" />
276278
</MenuItem.Icon>
277279
</MenuItem>
278-
<MenuItem Command="{Binding RunSelectedCategoryTestsCommand}" Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer ,Key=TestExplorer_RunSelectedCategoryTests}" >
279-
<MenuItem.Icon>
280-
<Image Source="{StaticResource RunSelectedCategoryImage}" />
281-
</MenuItem.Icon>
282-
</MenuItem>
283280
<MenuItem Command="{Binding RunInconclusiveTestsCommand}" Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_RunInconclusiveTests}" >
284281
<MenuItem.Icon>
285282
<Image Source="{StaticResource RunInconclusiveTestsImage}" />
@@ -379,8 +376,10 @@
379376

380377
<Border Grid.Row="2" Padding="2">
381378
<Grid>
382-
<controls:GroupingGrid ItemsSource="{Binding Tests}"
379+
<controls:GroupingGrid x:Name="TestGrid"
380+
ItemsSource="{Binding Tests}"
383381
SelectedItem="{Binding SelectedTest}"
382+
SelectionMode="Extended"
384383
ShowGroupingItemCount="True">
385384
<DataGrid.Columns>
386385
<DataGridTemplateColumn Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_Outcome}">

Rubberduck.Core/UI/UnitTesting/TestExplorerViewModel.cs

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
using System;
2+
using System.Collections;
23
using System.Collections.Generic;
34
using System.ComponentModel;
45
using System.Globalization;
56
using System.Linq;
6-
using System.Windows;
77
using System.Windows.Data;
88
using NLog;
99
using Rubberduck.Common;
10-
using Rubberduck.Interaction;
1110
using Rubberduck.Interaction.Navigation;
1211
using Rubberduck.Parsing.VBA;
1312
using Rubberduck.Settings;
@@ -16,7 +15,7 @@
1615
using Rubberduck.UI.UnitTesting.Commands;
1716
using Rubberduck.UI.UnitTesting.ViewModels;
1817
using Rubberduck.UnitTesting;
19-
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
18+
using DataFormats = System.Windows.DataFormats;
2019

2120
namespace Rubberduck.UI.UnitTesting
2221
{
@@ -30,39 +29,29 @@ internal enum TestExplorerGrouping
3029

3130
internal sealed class TestExplorerViewModel : ViewModelBase, INavigateSelection, IDisposable
3231
{
33-
private readonly IVBE _vbe;
3432
private readonly RubberduckParserState _state;
3533
private readonly ITestEngine _testEngine;
3634
private readonly IClipboardWriter _clipboard;
3735
private readonly ISettingsFormFactory _settingsFormFactory;
38-
private readonly IMessageBox _messageBox;
39-
private readonly NavigateCommand _navigateCommand;
4036

41-
public TestExplorerViewModel(IVBE vbe,
42-
RubberduckParserState state,
37+
public TestExplorerViewModel(RubberduckParserState state,
4338
ITestEngine testEngine,
4439
TestExplorerModel model,
4540
IClipboardWriter clipboard,
4641
IGeneralConfigService configService,
47-
ISettingsFormFactory settingsFormFactory,
48-
IMessageBox messageBox,
49-
ReparseCommand reparseCommand)
42+
ISettingsFormFactory settingsFormFactory)
5043
{
51-
_vbe = vbe;
5244
_state = state;
5345
_testEngine = testEngine;
5446
_testEngine.TestCompleted += TestEngineTestCompleted;
5547
_clipboard = clipboard;
5648
_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);
6349

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);
6454
CopyResultsCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteCopyResultsCommand);
65-
6655
OpenTestSettingsCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), OpenSettings);
6756

6857
Model = model;
@@ -134,8 +123,9 @@ public TestExplorerGrouping TestGrouping
134123
public RunInconclusiveTestsCommand RunInconclusiveTestsCommand { get; set; }
135124
public RunFailedTestsCommand RunFailedTestsCommand { get; set; }
136125
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; }
139129

140130
public AddTestModuleCommand AddTestModuleCommand { get; set; }
141131
public AddTestMethodCommand AddTestMethodCommand { get; set; }
@@ -145,7 +135,7 @@ public TestExplorerGrouping TestGrouping
145135

146136
public CommandBase OpenTestSettingsCommand { get; }
147137

148-
public INavigateCommand NavigateCommand => _navigateCommand;
138+
public INavigateCommand NavigateCommand { get; }
149139

150140
private void OpenSettings(object param)
151141
{
@@ -160,12 +150,17 @@ private void OpenSettings(object param)
160150

161151
public ICollectionView Tests { get; }
162152

163-
private bool CanExecuteSelectedTestCommand(object obj)
153+
private bool CanExecuteSingleTestCommand(object obj)
164154
{
165155
return !Model.IsBusy && SelectedItem != null;
166156
}
167157

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)
169164
{
170165
if (SelectedTest == null)
171166
{
@@ -177,6 +172,25 @@ private void ExecuteSelectedTestCommand(object obj)
177172
Model.IsBusy = false;
178173
}
179174

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+
180194
private void ExecuteCopyResultsCommand(object parameter)
181195
{
182196
const string XML_SPREADSHEET_DATA_FORMAT = "XML Spreadsheet";

0 commit comments

Comments
 (0)