Skip to content

Commit b22821e

Browse files
committed
Add ignore/unignore group command
Respective command displays when mouse is over group header, when applicable.
1 parent 1589ddc commit b22821e

File tree

4 files changed

+57
-18
lines changed

4 files changed

+57
-18
lines changed

Rubberduck.Core/UI/UnitTesting/TestExplorerControl.xaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,14 +454,16 @@
454454
<Image Source="{StaticResource UnignoreTestImage}" />
455455
</MenuItem.Icon>
456456
</MenuItem>
457-
<MenuItem Command="{Binding IgnoreSelectedGroupCommand}"
458-
Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_ContextMenuIgnoreGroup}">
459-
<MenuItem.Icon>
457+
<MenuItem Command="{Binding IgnoreSelectedGroupCommand}"
458+
Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_ContextMenuIgnoreGroup}"
459+
Visibility="{Binding DisplayIgnoreGroupLabel, Converter={StaticResource BoolToVisibility}}">
460+
<MenuItem.Icon>
460461
<Image Source="{StaticResource IgnoreTestGroupImage}" />
461462
</MenuItem.Icon>
462463
</MenuItem>
463464
<MenuItem Command="{Binding UnignoreSelectedGroupCommand}"
464-
Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_ContextMenuUnignoreGroup}">
465+
Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_ContextMenuUnignoreGroup}"
466+
Visibility="{Binding DisplayUnignoreGroupLabel, Converter={StaticResource BoolToVisibility}}">
465467
<MenuItem.Icon>
466468
<Image Source="{StaticResource UnignoreTestGroupImage}" />
467469
</MenuItem.Icon>

Rubberduck.Core/UI/UnitTesting/TestExplorerViewModel.cs

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ private void RefreshContextMenu()
140140
{
141141
OnPropertyChanged(nameof(DisplayUnignoreTestLabel));
142142
OnPropertyChanged(nameof(DisplayIgnoreTestLabel));
143+
OnPropertyChanged(nameof(DisplayUnignoreGroupLabel));
144+
OnPropertyChanged(nameof(DisplayIgnoreGroupLabel));
143145
}
144146

145147
private static readonly Dictionary<TestExplorerGrouping, PropertyGroupDescription> GroupDescriptions = new Dictionary<TestExplorerGrouping, PropertyGroupDescription>
@@ -245,6 +247,36 @@ private void HandleTestCompletion(object sender, TestCompletedEventArgs e)
245247
private TestMethod _mousedOverTestMethod => ((TestMethodViewModel)SelectedItem).Method;
246248
public bool DisplayUnignoreTestLabel => SelectedItem != null && _mousedOverTestMethod.IsIgnored;
247249
public bool DisplayIgnoreTestLabel => SelectedItem != null && !_mousedOverTestMethod.IsIgnored;
250+
251+
public bool DisplayUnignoreGroupLabel
252+
{
253+
get
254+
{
255+
if (MouseOverGroup?.Items == null)
256+
{
257+
return false;
258+
}
259+
260+
var testsInGroup = MouseOverGroup.Items.Cast<TestMethodViewModel>();
261+
262+
return testsInGroup.Where(test => test.Method.IsIgnored).Any(); ;
263+
}
264+
}
265+
266+
public bool DisplayIgnoreGroupLabel
267+
{
268+
get
269+
{
270+
if (MouseOverGroup?.Items == null)
271+
{
272+
return false;
273+
}
274+
275+
var testsInGroup = MouseOverGroup.Items.Cast<TestMethodViewModel>();
276+
277+
return testsInGroup.Where(test => test.Method.IsIgnored).Count() != MouseOverGroup.Items.Count;
278+
}
279+
}
248280

249281
#region Commands
250282

@@ -428,10 +460,19 @@ private void ExecuteIgnoreGroupCommand (object parameter)
428460

429461
foreach (TestMethodViewModel test in testGroup.Items)
430462
{
431-
// var testMethod = parameter == null
432-
// ? _mousedOverTestMethod
433-
// : (parameter as TestMethodViewModel).Method;
434-
AnnotationUpdater.AddAnnotation(rewriteSession, test.Method.Declaration, ignoreTestAnnotation);
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+
}
435476
}
436477

437478
rewriteSession.TryRewrite();
@@ -441,15 +482,11 @@ private void ExecuteUnignoreGroupCommand(object parameter)
441482
{
442483
var rewriteSession = RewritingManager.CheckOutCodePaneSession();
443484
var testGroup = GroupContainingSelectedTest(MouseOverTest);
485+
444486
foreach (TestMethodViewModel test in testGroup.Items)
445487
{
446-
//ExecuteUnignoreTestCommand(test);
447-
//var ignoreTestAnnotations = test.Method.Declaration.Annotations
448-
// .Where(iannotations => iannotations.AnnotationType == Parsing.Annotations.AnnotationType.IgnoreTest);
449-
450488
var ignoreTestAnnotations = test.Method.Declaration.Annotations
451-
.Where(pta => pta.Annotation.Target == AnnotationTarget.Member
452-
&& pta.AnnotationArguments.Contains("'@IgnoreTest"));
489+
.Where(pta => pta.Annotation is IgnoreTestAnnotation);
453490

454491
foreach (var ignoreTestAnnotation in ignoreTestAnnotations)
455492
{

Rubberduck.Resources/UnitTesting/TestExplorer.Designer.cs

Lines changed: 2 additions & 2 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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,9 @@
352352
<value>Unignore test</value>
353353
</data>
354354
<data name="TestExplorer_ContextMenuIgnoreGroup" xml:space="preserve">
355-
<value>Ignore all tests in group</value>
355+
<value>Ignore group tests</value>
356356
</data>
357357
<data name="TestExplorer_ContextMenuUnignoreGroup" xml:space="preserve">
358-
<value>Unignore all tests in group</value>
358+
<value>Unignore group tests</value>
359359
</data>
360360
</root>

0 commit comments

Comments
 (0)