Skip to content

Commit f3040a1

Browse files
committed
Add ignore/unignore selection commands
1 parent 01bd980 commit f3040a1

File tree

4 files changed

+123
-32
lines changed

4 files changed

+123
-32
lines changed

Rubberduck.Core/UI/UnitTesting/TestExplorerControl.xaml

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,9 @@
5555
<BitmapImage x:Key="OutcomeSucceeded" UriSource="pack://application:,,,/Rubberduck.Resources;component/Icons/Fugue/tick-circle.png" />
5656

5757
<BitmapImage x:Key="IgnoreTestImage" UriSource="pack://application:,,,/Rubberduck.Resources;component/Icons/Fugue/flask-empty.png" />
58-
<BitmapImage x:Key="UnignoreTestImage" UriSource="pack://application:,,,/Rubberduck.Resources;component/Icons/Fugue/flask-undo.png" />
58+
<BitmapImage x:Key="UnignoreTestImage" UriSource="pack://application:,,,/Rubberduck.Resources;component/Icons/Fugue/flask-undo.png" />
5959

60-
<BitmapImage x:Key="IgnoreTestGroupImage" UriSource="pack://application:,,,/Rubberduck.Resources;component/Icons/Fugue/flask-empty.png" />
61-
<BitmapImage x:Key="UnignoreTestGroupImage" UriSource="pack://application:,,,/Rubberduck.Resources;component/Icons/Fugue/flask-undo.png" />
62-
63-
<local:TestOutcomeImageSourceConverter x:Key="OutcomeIconConverter" />
60+
<local:TestOutcomeImageSourceConverter x:Key="OutcomeIconConverter" />
6461
<converters:MillisecondToTimeMagnitudeConverter x:Key="FormattedTime" />
6562
<converters:InvertBoolValueConverter x:Key="InvertBoolValue" />
6663
<BooleanToVisibilityConverter x:Key="BoolToVisibility" />
@@ -459,17 +456,32 @@
459456
Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_ContextMenuIgnoreGroup}"
460457
Visibility="{Binding DisplayIgnoreGroupLabel, Converter={StaticResource BoolToVisibility}}">
461458
<MenuItem.Icon>
462-
<Image Source="{StaticResource IgnoreTestGroupImage}" />
459+
<Image Source="{StaticResource IgnoreTestImage}" />
463460
</MenuItem.Icon>
464461
</MenuItem>
465462
<MenuItem Command="{Binding UnignoreGroupCommand}"
466463
Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_ContextMenuUnignoreGroup}"
467464
Visibility="{Binding DisplayUnignoreGroupLabel, Converter={StaticResource BoolToVisibility}}">
468465
<MenuItem.Icon>
469-
<Image Source="{StaticResource UnignoreTestGroupImage}" />
466+
<Image Source="{StaticResource UnignoreTestImage}" />
470467
</MenuItem.Icon>
471468
</MenuItem>
472-
</ContextMenu>
469+
470+
<MenuItem Command="{Binding IgnoreSelectedTestsCommand}"
471+
CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu}, Path=PlacementTarget.SelectedItems}"
472+
Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_ContextMenuIgnoreSelectedTests}" >
473+
<MenuItem.Icon>
474+
<Image Source="{StaticResource IgnoreTestImage}" />
475+
</MenuItem.Icon>
476+
</MenuItem>
477+
<MenuItem Command="{Binding UnignoreSelectedTestsCommand}"
478+
CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu}, Path=PlacementTarget.SelectedItems}"
479+
Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_ContextMenuUnignoreSelectedTests}" >
480+
<MenuItem.Icon>
481+
<Image Source="{StaticResource UnignoreTestImage}" />
482+
</MenuItem.Icon>
483+
</MenuItem>
484+
</ContextMenu>
473485
</DataGrid.ContextMenu>
474486
<i:Interaction.Behaviors>
475487
<local:TestExplorerRowMouseOverBehavior MouseOverTest="{Binding MouseOverTest, Mode=TwoWay}" MouseOverGroup="{Binding MouseOverGroup, Mode=TwoWay}" />

Rubberduck.Core/UI/UnitTesting/TestExplorerViewModel.cs

Lines changed: 79 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ public TestExplorerViewModel(ISelectionService selectionService,
7878
UnignoreTestCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteUnignoreTestCommand);
7979
IgnoreGroupCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteIgnoreGroupCommand, CanIgnoreGroupCommand);
8080
UnignoreGroupCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteUnignoreGroupCommand, CanUnignoreGroupCommand);
81+
IgnoreSelectedTestsCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteIgnoreSelectedTestsCommand, CanExecuteSelectedTestsCommand);
82+
UnignoreSelectedTestsCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteUnignoreSelectedTestsCommand, CanUnignoreSelectedTestsCommand);
8183

8284
RewritingManager = rewritingManager;
8385
AnnotationUpdater = annotationUpdater;
@@ -259,7 +261,7 @@ public bool DisplayUnignoreGroupLabel
259261

260262
var testsInGroup = MouseOverGroup.Items.Cast<TestMethodViewModel>();
261263

262-
return testsInGroup.Where(test => test.Method.IsIgnored).Any(); ;
264+
return testsInGroup.Any(test => test.Method.IsIgnored);
263265
}
264266
}
265267

@@ -274,7 +276,7 @@ public bool DisplayIgnoreGroupLabel
274276

275277
var testsInGroup = MouseOverGroup.Items.Cast<TestMethodViewModel>();
276278

277-
return testsInGroup.Where(test => test.Method.IsIgnored).Count() != MouseOverGroup.Items.Count;
279+
return testsInGroup.Count(test => test.Method.IsIgnored) != MouseOverGroup.ItemCount;
278280
}
279281
}
280282

@@ -315,6 +317,9 @@ public bool DisplayIgnoreGroupLabel
315317
public CommandBase IgnoreGroupCommand { get; }
316318
public CommandBase UnignoreGroupCommand { get; }
317319

320+
public CommandBase IgnoreSelectedTestsCommand { get; }
321+
public CommandBase UnignoreSelectedTestsCommand { get; }
322+
318323
#endregion
319324

320325
#region Delegates
@@ -329,6 +334,11 @@ private bool CanExecuteSelectedTestsCommand(object obj)
329334
return !Model.IsBusy && obj is IList viewModels && viewModels.Count > 0;
330335
}
331336

337+
private bool CanUnignoreSelectedTestsCommand(object obj)
338+
{
339+
return true;
340+
}
341+
332342
private bool CanExecuteGroupCommand(object obj)
333343
{
334344
return !Model.IsBusy && (MouseOverTest != null || MouseOverGroup != null);
@@ -432,22 +442,27 @@ private void ExecuteIgnoreTestCommand(object parameter)
432442
{
433443
var rewriteSession = RewritingManager.CheckOutCodePaneSession();
434444

435-
AnnotationUpdater.AddAnnotation(rewriteSession, _mousedOverTestMethod.Declaration, new IgnoreTestAnnotation());
445+
var testMethod = parameter is null
446+
? _mousedOverTestMethod
447+
: (TestMethod)parameter;
448+
449+
AnnotationUpdater.AddAnnotation(rewriteSession, testMethod.Declaration, new IgnoreTestAnnotation());
436450

437451
rewriteSession.TryRewrite();
438452
}
439453

440454
private void ExecuteUnignoreTestCommand(object parameter)
441455
{
442-
var rewriteSession = RewritingManager.CheckOutCodePaneSession();
443-
444-
var ignoreTestAnnotations = _mousedOverTestMethod.Declaration.Annotations
456+
var testMethod = parameter is null
457+
? _mousedOverTestMethod
458+
: (TestMethod)parameter;
459+
460+
var ignoreTestAnnotations = testMethod.Declaration.Annotations
445461
.Where(pta => pta.Annotation is IgnoreTestAnnotation);
446462

447-
foreach (var ignoreTestAnnotation in ignoreTestAnnotations)
448-
{
449-
AnnotationUpdater.RemoveAnnotation(rewriteSession, ignoreTestAnnotation);
450-
}
463+
var rewriteSession = RewritingManager.CheckOutCodePaneSession();
464+
465+
AnnotationUpdater.RemoveAnnotations(rewriteSession, ignoreTestAnnotations);
451466

452467
rewriteSession.TryRewrite();
453468
}
@@ -460,20 +475,6 @@ private void ExecuteIgnoreGroupCommand (object parameter)
460475

461476
foreach (TestMethodViewModel test in testGroup.Items)
462477
{
463-
//var needsIgnoreAnnotationAdded = true;
464-
//foreach (var annotation in test.Method.Declaration.Annotations)
465-
//{
466-
// if (annotation.Annotation is IgnoreTestAnnotation)
467-
// {
468-
// needsIgnoreAnnotationAdded = false;
469-
// };
470-
//}
471-
472-
//if (needsIgnoreAnnotationAdded)
473-
//{
474-
// AnnotationUpdater.AddAnnotation(rewriteSession, test.Method.Declaration, ignoreTestAnnotation);
475-
//}
476-
477478
if (!test.Method.IsIgnored)
478479
{
479480
AnnotationUpdater.AddAnnotation(rewriteSession, test.Method.Declaration, ignoreTestAnnotation);
@@ -502,6 +503,60 @@ private void ExecuteUnignoreGroupCommand(object parameter)
502503
rewriteSession.TryRewrite();
503504
}
504505

506+
private void ExecuteUnignoreSelectedTestsCommand(object parameter)
507+
{
508+
if (Model.IsBusy || !(parameter is IList viewModels && viewModels.Count > 0))
509+
{
510+
return;
511+
}
512+
513+
var ignoredModels = viewModels.OfType<TestMethodViewModel>()
514+
.Where(model => model.Method.IsIgnored);
515+
516+
if (!ignoredModels.Any())
517+
{
518+
return;
519+
}
520+
521+
var rewriteSession = RewritingManager.CheckOutCodePaneSession();
522+
523+
foreach (var test in ignoredModels)
524+
{
525+
var ignoreTestAnnotations = test.Method.Declaration.Annotations
526+
.Where(pta => pta.Annotation is IgnoreTestAnnotation);
527+
528+
AnnotationUpdater.RemoveAnnotations(rewriteSession, ignoreTestAnnotations);
529+
}
530+
531+
rewriteSession.TryRewrite();
532+
}
533+
534+
private void ExecuteIgnoreSelectedTestsCommand(object parameter)
535+
{
536+
if (Model.IsBusy || !(parameter is IList viewModels && viewModels.Count > 0))
537+
{
538+
return;
539+
}
540+
541+
var unignoredModels = viewModels.OfType<TestMethodViewModel>()
542+
.Where(model => !model.Method.IsIgnored);
543+
544+
if (!unignoredModels.Any())
545+
{
546+
return;
547+
}
548+
549+
var rewriteSession = RewritingManager.CheckOutCodePaneSession();
550+
var ignoreTestAnnotation = new IgnoreTestAnnotation();
551+
552+
foreach (var test in unignoredModels)
553+
{
554+
AnnotationUpdater.AddAnnotation(rewriteSession, test.Method.Declaration, ignoreTestAnnotation);
555+
}
556+
557+
rewriteSession.TryRewrite();
558+
}
559+
505560
private void ExecuteCopyResultsCommand(object parameter)
506561
{
507562
const string XML_SPREADSHEET_DATA_FORMAT = "XML Spreadsheet";

Rubberduck.Resources/UnitTesting/TestExplorer.Designer.cs

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Rubberduck.Resources/UnitTesting/TestExplorer.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,4 +357,10 @@
357357
<data name="TestExplorer_ContextMenuUnignoreGroup" xml:space="preserve">
358358
<value>Unignore group tests</value>
359359
</data>
360+
<data name="TestExplorer_ContextMenuUnignoreSelectedTests" xml:space="preserve">
361+
<value>Unignore selected tests</value>
362+
</data>
363+
<data name="TestExplorer_ContextMenuIgnoreSelectedTests" xml:space="preserve">
364+
<value>Ignore selected tests</value>
365+
</data>
360366
</root>

0 commit comments

Comments
 (0)