Test run can be filtered by traits

This commit is contained in:
Jared Parsons
2015-08-23 20:50:59 -07:00
parent 06f1c8c703
commit 65f3fc970e
9 changed files with 100 additions and 55 deletions
+34 -2
View File
@@ -49,6 +49,7 @@ namespace xunit.runner.wpf.ViewModel
this.WindowLoadedCommand = new RelayCommand(OnExecuteWindowLoaded);
this.RunCommand = new RelayCommand(OnExecuteRun, CanExecuteRun);
this.CancelCommand = new RelayCommand(OnExecuteCancel, CanExecuteCancel);
this.TraitSelectionChangedCommand = new RelayCommand(OnTraitSelectionChanged);
}
private static bool TestCaseMatches(TestCaseViewModel testCase, SearchQuery searchQuery)
@@ -58,6 +59,24 @@ namespace xunit.runner.wpf.ViewModel
return false;
}
if (searchQuery.TraitSet.Count > 0)
{
var anyMatch = false;
foreach (var cur in testCase.Traits)
{
if (searchQuery.TraitSet.Contains(cur))
{
anyMatch = true;
break;
}
}
if (!anyMatch)
{
return false;
}
}
switch (testCase.State)
{
case TestState.Passed:
@@ -88,6 +107,7 @@ namespace xunit.runner.wpf.ViewModel
public ICommand WindowLoadedCommand { get; }
public RelayCommand RunCommand { get; }
public RelayCommand CancelCommand { get; }
public ICommand TraitSelectionChangedCommand { get; }
public CommandBindingCollection CommandBindings { get; }
@@ -364,8 +384,12 @@ namespace xunit.runner.wpf.ViewModel
private void OnTestDiscovered(object sender, TestCaseDataEventArgs e)
{
var t = e.TestCaseData;
this.allTestCases.Add(new TestCaseViewModel(t.SerializedForm, t.DisplayName, t.AssemblyPath));
this.traitCollectionView.Add(t.TraitMap);
var traitMap = t.TraitMap.Count == 0
? ImmutableArray<TraitViewModel>.Empty
: t.TraitMap.SelectMany(pair => pair.Value.Select(value => new TraitViewModel(pair.Key, value))).ToImmutableArray();
this.allTestCases.Add(new TestCaseViewModel(t.SerializedForm, t.DisplayName, t.AssemblyPath, traitMap));
this.traitCollectionView.Add(traitMap);
}
private void OnTestFinished(object sender, TestResultDataEventArgs e)
@@ -405,6 +429,14 @@ namespace xunit.runner.wpf.ViewModel
this.cancellationTokenSource.Cancel();
}
private void OnTraitSelectionChanged()
{
this.searchQuery.TraitSet = new HashSet<TraitViewModel>(
this.traitCollectionView.Collection.Where(x => x.IsSelected),
TraitViewModelComparer.Instance);
FilterAfterDelay();
}
public bool IncludePassedTests
{
get { return searchQuery.IncludePassedTests; }