@@ -29,6 +29,8 @@ public class MainViewModel : ViewModelBase
2929 private readonly HashSet < string > allTestCaseUniqueIDs = new HashSet < string > ( ) ;
3030 private readonly ObservableCollection < TestCaseViewModel > allTestCases = new ObservableCollection < TestCaseViewModel > ( ) ;
3131 private readonly TraitCollectionView traitCollectionView = new TraitCollectionView ( ) ;
32+ private readonly HashSet < string > runningTestSet = new HashSet < string > ( ) ;
33+
3234 private CancellationTokenSource filterCancellationTokenSource = new CancellationTokenSource ( ) ;
3335
3436 private CancellationTokenSource cancellationTokenSource ;
@@ -52,7 +54,7 @@ public bool AutoReloadAssemblies
5254
5355 public ObservableCollection < RecentAssemblyViewModel > RecentAssemblies { get ; } = new ObservableCollection < RecentAssemblyViewModel > ( ) ;
5456
55- private ImmutableList < TestCaseViewModel > runningTests ;
57+ private ImmutableList < TestCaseViewModel > testsToRun ;
5658
5759 public ICommand ExitCommand { get ; }
5860 public ICommand WindowLoadedCommand { get ; }
@@ -153,10 +155,13 @@ private static bool TestCaseMatches(TestCaseViewModel testCase, SearchQuery sear
153155 }
154156 }
155157
156- var noFilter = ! ( searchQuery . FilterFailedTests | searchQuery . FilterPassedTests | searchQuery . FilterSkippedTests ) ;
158+ var noFilter = ! ( searchQuery . FilterRunningTests | searchQuery . FilterFailedTests | searchQuery . FilterPassedTests | searchQuery . FilterSkippedTests ) ;
157159
158160 switch ( testCase . State )
159161 {
162+ case TestState . Running :
163+ return noFilter || searchQuery . FilterRunningTests ;
164+
160165 case TestState . Passed :
161166 return noFilter || searchQuery . FilterPassedTests ;
162167
@@ -263,6 +268,13 @@ private TaskbarProgressBarState GetTaskBarState()
263268 }
264269 }
265270
271+ private int testsRunning = 0 ;
272+ public int TestsRunning
273+ {
274+ get { return testsRunning ; }
275+ set { Set ( ref testsRunning , value ) ; }
276+ }
277+
266278 private int testsPassed = 0 ;
267279 public int TestsPassed
268280 {
@@ -560,12 +572,12 @@ private bool CanExecuteRunSelected()
560572
561573 private async void OnExecuteRunAll ( )
562574 {
563- Debug . Assert ( this . runningTests == null ) ;
575+ Debug . Assert ( this . testsToRun == null ) ;
564576 UpdateTestCaseInfo ( useSelected : false ) ;
565577
566578 await ExecuteTestSessionOperation ( RunFilteredTests ) ;
567579
568- this . runningTests = null ;
580+ this . testsToRun = null ;
569581 }
570582
571583 private List < Task > RunFilteredTests ( )
@@ -575,13 +587,13 @@ private List<Task> RunFilteredTests()
575587
576588 private async void OnExecuteRunSelected ( )
577589 {
578- Debug . Assert ( this . runningTests == null ) ;
590+ Debug . Assert ( this . testsToRun == null ) ;
579591 Debug . Assert ( this . SelectedTestCase != null ) ;
580592 UpdateTestCaseInfo ( useSelected : true ) ;
581593
582594 await ExecuteTestSessionOperation ( RunSelectedTests ) ;
583595
584- this . runningTests = null ;
596+ this . testsToRun = null ;
585597 }
586598
587599 private List < Task > RunSelectedTests ( )
@@ -593,45 +605,46 @@ private List<Task> RunTests(ImmutableList<TestCaseViewModel> tests)
593605 {
594606 Debug . Assert ( this . isBusy ) ;
595607 Debug . Assert ( this . cancellationTokenSource != null ) ;
596- Debug . Assert ( this . runningTests == null ) ;
608+ Debug . Assert ( this . testsToRun == null ) ;
597609
598610 TestsCompleted = 0 ;
611+ TestsRunning = 0 ;
599612 TestsPassed = 0 ;
600613 TestsFailed = 0 ;
601614 TestsSkipped = 0 ;
602615 CurrentRunState = TestState . NotRun ;
603616 Output = string . Empty ;
604617
605- this . runningTests = tests ;
618+ this . testsToRun = tests ;
606619
607- foreach ( var tc in this . runningTests )
620+ foreach ( var tc in this . testsToRun )
608621 {
609622 tc . State = TestState . NotRun ;
610623 }
611624
612- var runAll = this . runningTests . Count == this . allTestCases . Count ;
625+ var runAll = this . testsToRun . Count == this . allTestCases . Count ;
613626 var testSessionList = new List < Task > ( ) ;
614627
615- foreach ( var assemblyFileName in this . runningTests . Select ( x => x . AssemblyFileName ) . Distinct ( ) )
628+ foreach ( var assemblyFileName in this . testsToRun . Select ( x => x . AssemblyFileName ) . Distinct ( ) )
616629 {
617630 Task task ;
618631 if ( runAll )
619632 {
620- task = this . testUtil . RunAll ( assemblyFileName , OnTestsFinished , this . cancellationTokenSource . Token ) ;
633+ task = this . testUtil . RunAll ( assemblyFileName , OnTestStateChange , this . cancellationTokenSource . Token ) ;
621634 }
622635 else
623636 {
624637 var builder = ImmutableArray . CreateBuilder < string > ( ) ;
625638
626- foreach ( var testCase in this . runningTests )
639+ foreach ( var testCase in this . testsToRun )
627640 {
628641 if ( testCase . AssemblyFileName == assemblyFileName )
629642 {
630643 builder . Add ( testCase . UniqueID ) ;
631644 }
632645 }
633646
634- task = this . testUtil . RunSpecific ( assemblyFileName , builder . ToImmutable ( ) , OnTestsFinished , this . cancellationTokenSource . Token ) ;
647+ task = this . testUtil . RunSpecific ( assemblyFileName , builder . ToImmutable ( ) , OnTestStateChange , this . cancellationTokenSource . Token ) ;
635648 }
636649
637650 testSessionList . Add ( task ) ;
@@ -711,28 +724,43 @@ private void OnTestsDiscovered(IEnumerable<TestCaseData> testCases)
711724 }
712725 }
713726
714- private void OnTestsFinished ( IEnumerable < TestResultData > testResultData )
727+ private void OnTestStateChange ( IEnumerable < TestResultData > testResultData )
715728 {
716- Debug . Assert ( this . runningTests != null ) ;
729+ Debug . Assert ( this . testsToRun != null ) ;
717730
718731 foreach ( var result in testResultData )
719732 {
720- var testCase = this . runningTests . Single ( x => x . UniqueID == result . TestCaseUniqueID ) ;
733+ var testCase = this . testsToRun . Single ( x => x . UniqueID == result . TestCaseUniqueID ) ;
721734 testCase . State = result . TestState ;
722735
723- TestsCompleted ++ ;
724- switch ( result . TestState )
736+ if ( result . TestState == TestState . Running )
725737 {
726- case TestState . Passed :
727- TestsPassed ++ ;
728- break ;
729- case TestState . Failed :
730- TestsFailed ++ ;
731- Output = Output + result . Output ;
732- break ;
733- case TestState . Skipped :
734- TestsSkipped ++ ;
735- break ;
738+ if ( runningTestSet . Add ( result . TestCaseUniqueID ) )
739+ {
740+ TestsRunning ++ ;
741+ }
742+ }
743+ else
744+ {
745+ if ( runningTestSet . Remove ( result . TestCaseUniqueID ) )
746+ {
747+ TestsRunning -- ;
748+ }
749+
750+ TestsCompleted ++ ;
751+ switch ( result . TestState )
752+ {
753+ case TestState . Passed :
754+ TestsPassed ++ ;
755+ break ;
756+ case TestState . Failed :
757+ TestsFailed ++ ;
758+ Output = Output + result . Output ;
759+ break ;
760+ case TestState . Skipped :
761+ TestsSkipped ++ ;
762+ break ;
763+ }
736764 }
737765
738766 if ( result . TestState > CurrentRunState )
@@ -820,6 +848,18 @@ private void UpdateAutoReloadStatus()
820848 }
821849 }
822850
851+ public bool FilterRunningTests
852+ {
853+ get { return searchQuery . FilterRunningTests ; }
854+ set
855+ {
856+ if ( Set ( ref searchQuery . FilterRunningTests , value ) )
857+ {
858+ FilterAfterDelay ( ) ;
859+ }
860+ }
861+ }
862+
823863 public bool FilterPassedTests
824864 {
825865 get { return searchQuery . FilterPassedTests ; }
0 commit comments