|
1 | 1 | using System;
|
2 | 2 | using System.Collections;
|
3 | 3 | using System.Collections.Generic;
|
| 4 | +using System.Collections.ObjectModel; |
4 | 5 | using System.ComponentModel;
|
5 | 6 | using System.Globalization;
|
6 | 7 | using System.Linq;
|
@@ -66,20 +67,20 @@ public TestExplorerViewModel(ISelectionService selectionService,
|
66 | 67 |
|
67 | 68 | NavigateCommand = new NavigateCommand(selectionService);
|
68 | 69 | RunSingleTestCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteSingleTestCommand, CanExecuteSingleTest);
|
69 |
| - RunSelectedTestsCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteSelectedTestsCommand, CanExecuteSelectionCommand); |
| 70 | + RunSelectedTestsCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteSelectedTestsCommand, CanExecuteSelectedCommands); |
70 | 71 | RunSelectedGroupCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteRunSelectedGroupCommand, CanExecuteGroupCommand);
|
71 | 72 | CancelTestRunCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteCancelTestRunCommand, CanExecuteCancelTestRunCommand);
|
72 | 73 | ResetResultsCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteResetResultsCommand, CanExecuteResetResultsCommand);
|
73 | 74 | CopyResultsCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteCopyResultsCommand);
|
74 | 75 | OpenTestSettingsCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), OpenSettings);
|
75 | 76 | CollapseAllCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteCollapseAll);
|
76 | 77 | ExpandAllCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteExpandAll);
|
77 |
| - IgnoreTestCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteIgnoreTestCommand); |
78 |
| - UnignoreTestCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteUnignoreTestCommand); |
79 |
| - IgnoreGroupCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteIgnoreGroupCommand, CanExecuteGroupCommand); |
80 |
| - UnignoreGroupCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteUnignoreGroupCommand, CanExecuteGroupCommand); |
81 |
| - IgnoreSelectedTestsCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteIgnoreSelectedTestsCommand, CanExecuteSelectionCommand); |
82 |
| - UnignoreSelectedTestsCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteUnignoreSelectedTestsCommand, CanExecuteSelectionCommand); |
| 78 | + IgnoreTestCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteIgnoreTestCommand, CanExecuteIgnoreTestCommand); |
| 79 | + UnignoreTestCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteUnignoreTestCommand, CanExecuteUnignoreTestCommand); |
| 80 | + IgnoreSelectedTestsCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteIgnoreSelectedTestsCommand, CanExecuteIgnoreSelectedTests); |
| 81 | + UnignoreSelectedTestsCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteUnignoreSelectedTestsCommand, CanExecuteUnignoreSelectedTests); |
| 82 | + IgnoreGroupCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteIgnoreGroupCommand, CanExecuteIgnoreGroupCommand); |
| 83 | + UnignoreGroupCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteUnignoreGroupCommand, CanExecuteUnignoreGroupCommand); |
83 | 84 |
|
84 | 85 | RewritingManager = rewritingManager;
|
85 | 86 | AnnotationUpdater = annotationUpdater;
|
@@ -140,10 +141,10 @@ public CollectionViewGroup MouseOverGroup
|
140 | 141 |
|
141 | 142 | private void RefreshContextMenu()
|
142 | 143 | {
|
143 |
| - OnPropertyChanged(nameof(DisplayUnignoreTestLabel)); |
144 |
| - OnPropertyChanged(nameof(DisplayIgnoreTestLabel)); |
145 |
| - OnPropertyChanged(nameof(DisplayUnignoreGroupLabel)); |
146 |
| - OnPropertyChanged(nameof(DisplayIgnoreGroupLabel)); |
| 144 | + OnPropertyChanged(nameof(CanExecuteUnignoreTestCommand)); |
| 145 | + OnPropertyChanged(nameof(CanExecuteIgnoreTestCommand)); |
| 146 | + OnPropertyChanged(nameof(CanExecuteUnignoreGroupCommand)); |
| 147 | + OnPropertyChanged(nameof(CanExecuteIgnoreGroupCommand)); |
147 | 148 | }
|
148 | 149 |
|
149 | 150 | private static readonly Dictionary<TestExplorerGrouping, PropertyGroupDescription> GroupDescriptions = new Dictionary<TestExplorerGrouping, PropertyGroupDescription>
|
@@ -247,37 +248,41 @@ private void HandleTestCompletion(object sender, TestCompletedEventArgs e)
|
247 | 248 | public IAnnotationUpdater AnnotationUpdater { get; }
|
248 | 249 |
|
249 | 250 | private TestMethod _mousedOverTestMethod => ((TestMethodViewModel)SelectedItem).Method;
|
250 |
| - public bool DisplayUnignoreTestLabel => SelectedItem != null && _mousedOverTestMethod.IsIgnored; |
251 |
| - public bool DisplayIgnoreTestLabel => SelectedItem != null && !_mousedOverTestMethod.IsIgnored; |
| 251 | + public bool CanExecuteUnignoreTestCommand(object obj) => SelectedItem != null && _mousedOverTestMethod.IsIgnored; |
| 252 | + public bool CanExecuteIgnoreTestCommand(object obj) => SelectedItem != null && !_mousedOverTestMethod.IsIgnored; |
252 | 253 |
|
253 |
| - public bool DisplayUnignoreGroupLabel |
| 254 | + public bool CanExecuteIgnoreSelectedTests(object obj) |
254 | 255 | {
|
255 |
| - get |
| 256 | + if (!Model.IsBusy && obj is IList viewModels && viewModels.Count > 0) |
256 | 257 | {
|
257 |
| - if (MouseOverGroup?.Items == null) |
258 |
| - { |
259 |
| - return false; |
260 |
| - } |
261 |
| - |
262 |
| - var testsInGroup = MouseOverGroup.Items.Cast<TestMethodViewModel>(); |
| 258 | + return viewModels.Cast<TestMethodViewModel>().Count(test => test.Method.IsIgnored) != viewModels.Count; |
| 259 | + } |
263 | 260 |
|
264 |
| - return testsInGroup.Any(test => test.Method.IsIgnored); |
| 261 | + return false; |
| 262 | + } |
| 263 | + public bool CanExecuteUnignoreSelectedTests(object obj) |
| 264 | + { |
| 265 | + if (!Model.IsBusy && obj is IList viewModels && viewModels.Count > 0) |
| 266 | + { |
| 267 | + return viewModels.Cast<TestMethodViewModel>().Any(test => test.Method.IsIgnored); |
265 | 268 | }
|
| 269 | + |
| 270 | + return false; |
266 | 271 | }
|
267 | 272 |
|
268 |
| - public bool DisplayIgnoreGroupLabel |
| 273 | + public bool CanExecuteIgnoreGroupCommand(object obj) |
269 | 274 | {
|
270 |
| - get |
271 |
| - { |
272 |
| - if (MouseOverGroup?.Items == null) |
273 |
| - { |
274 |
| - return false; |
275 |
| - } |
| 275 | + var groupItems = MouseOverGroup?.Items |
| 276 | + ?? GroupContainingSelectedTest(MouseOverTest).Items; |
276 | 277 |
|
277 |
| - var testsInGroup = MouseOverGroup.Items.Cast<TestMethodViewModel>(); |
| 278 | + return groupItems.Cast<TestMethodViewModel>().Count(test => test.Method.IsIgnored) != groupItems.Count; |
| 279 | + } |
| 280 | + public bool CanExecuteUnignoreGroupCommand(object obj) |
| 281 | + { |
| 282 | + var groupItems = MouseOverGroup?.Items |
| 283 | + ?? GroupContainingSelectedTest(MouseOverTest).Items; |
278 | 284 |
|
279 |
| - return testsInGroup.Count(test => test.Method.IsIgnored) != MouseOverGroup.ItemCount; |
280 |
| - } |
| 285 | + return groupItems.Cast<TestMethodViewModel>().Any(test => test.Method.IsIgnored); |
281 | 286 | }
|
282 | 287 |
|
283 | 288 | #region Commands
|
@@ -329,7 +334,7 @@ private bool CanExecuteSingleTest(object obj)
|
329 | 334 | return !Model.IsBusy && MouseOverTest != null;
|
330 | 335 | }
|
331 | 336 |
|
332 |
| - private bool CanExecuteSelectionCommand(object obj) |
| 337 | + private bool CanExecuteSelectedCommands(object obj) |
333 | 338 | {
|
334 | 339 | return !Model.IsBusy && obj is IList viewModels && viewModels.Count > 0;
|
335 | 340 | }
|
@@ -452,7 +457,7 @@ private void ExecuteUnignoreTestCommand(object parameter)
|
452 | 457 | rewriteSession.TryRewrite();
|
453 | 458 | }
|
454 | 459 |
|
455 |
| - private void ExecuteIgnoreGroupCommand (object parameter) |
| 460 | + private void ExecuteIgnoreGroupCommand(object parameter) |
456 | 461 | {
|
457 | 462 | var rewriteSession = RewritingManager.CheckOutCodePaneSession();
|
458 | 463 | var testGroup = GroupContainingSelectedTest(MouseOverTest);
|
|
0 commit comments