Test run can be filtered by traits

This commit is contained in:
Jared Parsons 2015-08-23 20:50:59 -07:00
Родитель 06f1c8c703
Коммит 65f3fc970e
9 изменённых файлов: 100 добавлений и 55 удалений

Просмотреть файл

@ -105,6 +105,16 @@
<TextBlock Text="{Binding DisplayName}" />
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="IsSelected" Value="{Binding Mode=TwoWay, Path=IsSelected}"/>
</Style>
</ListBox.ItemContainerStyle>
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<cmd:EventToCommand Command="{Binding TraitSelectionChangedCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</ListBox>
</Grid>
</GroupBox>

Просмотреть файл

@ -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; }

Просмотреть файл

@ -11,7 +11,7 @@ namespace xunit.runner.wpf.ViewModel
public bool IncludeFailedTests = true;
public bool IncludePassedTests = true;
public bool IncludeSkippedTests = true;
public string SearchString = string.Empty;
public HashSet<TraitViewModel> TraitSet = new HashSet<TraitViewModel>(TraitViewModelComparer.Instance);
}
}

Просмотреть файл

@ -1,6 +1,7 @@
using GalaSoft.MvvmLight;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Linq;
using System.Text;
@ -11,24 +12,28 @@ namespace xunit.runner.wpf.ViewModel
{
public class TestCaseViewModel : ViewModelBase
{
public TestCaseViewModel(string testCase, string displayName, string assemblyFileName)
private TestState _state = TestState.NotRun;
public TestCaseViewModel(string testCase, string displayName, string assemblyFileName, ImmutableArray<TraitViewModel> traits)
{
this.TestCase = testCase;
this.DisplayName = displayName;
this.AssemblyFileName = assemblyFileName;
this.Traits = traits;
}
public string DisplayName { get; }
private TestState state = TestState.NotRun;
public TestState State
{
get { return state; }
set { Set(ref state, value); }
get { return _state; }
set { Set(ref _state, value); }
}
public string AssemblyFileName { get; }
public string TestCase { get; }
public ImmutableArray<TraitViewModel> Traits { get; }
}
}

Просмотреть файл

@ -1,39 +0,0 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace xunit.runner.wpf.ViewModel
{
public partial class TraitCollectionView
{
private sealed class TraitViewModelComparer : IEqualityComparer<TraitViewModel>, IComparer<TraitViewModel>
{
private readonly StringComparer _comparer = StringComparer.Ordinal;
public int Compare(TraitViewModel x, TraitViewModel y)
{
var result = _comparer.Compare(x.Name, y.Name);
if (result != 0)
{
return result;
}
return _comparer.Compare(x.Value, y.Value);
}
public bool Equals(TraitViewModel x, TraitViewModel y)
{
return _comparer.Equals(x.Name, y.Name)
&& _comparer.Equals(x.Value, y.Value);
}
public int GetHashCode(TraitViewModel obj)
{
return obj.Name.GetHashCode();
}
}
}
}

Просмотреть файл

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
@ -10,7 +11,7 @@ namespace xunit.runner.wpf.ViewModel
{
public sealed partial class TraitCollectionView
{
private readonly TraitViewModelComparer _comparer = new TraitViewModelComparer();
private readonly TraitViewModelComparer _comparer = TraitViewModelComparer.Instance;
private readonly ObservableCollection<TraitViewModel> _collection = new ObservableCollection<TraitViewModel>();
public ObservableCollection<TraitViewModel> Collection => _collection;
@ -20,19 +21,16 @@ namespace xunit.runner.wpf.ViewModel
}
public void Add(Dictionary<string, List<string>> traitMap)
public void Add(ImmutableArray<TraitViewModel> traitList)
{
if (traitMap.Count == 0)
if (traitList.Length == 0)
{
return;
}
foreach (var pair in traitMap)
foreach (var traitViewModel in traitList)
{
foreach (var value in pair.Value)
{
TryInsert(new TraitViewModel(pair.Key, value));
}
TryInsert(traitViewModel);
}
}

Просмотреть файл

@ -15,6 +15,7 @@ namespace xunit.runner.wpf.ViewModel
public string Name => _name;
public string Value => _value;
public string DisplayName => $"{Name}={Value}";
public bool IsSelected { get; set; }
public TraitViewModel(string name, string value)
{

Просмотреть файл

@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace xunit.runner.wpf.ViewModel
{
internal sealed class TraitViewModelComparer : IEqualityComparer<TraitViewModel>, IComparer<TraitViewModel>
{
internal static readonly TraitViewModelComparer Instance = new TraitViewModelComparer();
private readonly StringComparer _comparer = StringComparer.Ordinal;
public int Compare(TraitViewModel x, TraitViewModel y)
{
var result = _comparer.Compare(x.Name, y.Name);
if (result != 0)
{
return result;
}
return _comparer.Compare(x.Value, y.Value);
}
public bool Equals(TraitViewModel x, TraitViewModel y)
{
return _comparer.Equals(x.Name, y.Name)
&& _comparer.Equals(x.Value, y.Value);
}
public int GetHashCode(TraitViewModel obj)
{
return obj.Name.GetHashCode();
}
}
}

Просмотреть файл

@ -94,7 +94,6 @@
<Compile Include="LoadingDialog.xaml.cs">
<DependentUpon>LoadingDialog.xaml</DependentUpon>
</Compile>
<Compile Include="ViewModel\TraitCollectionView.TraitViewModelComparer.cs" />
<Compile Include="ViewModel\TraitCollectionView.cs" />
<Compile Include="ViewModel\AssemblyAndConfigFile.cs" />
<Compile Include="ViewModel\MainViewModel.cs" />
@ -102,6 +101,7 @@
<Compile Include="ViewModel\TestCaseViewModel.cs" />
<Compile Include="ViewModel\TestAssemblyViewModel.cs" />
<Compile Include="ViewModel\TraitViewModel.cs" />
<Compile Include="ViewModel\TraitViewModelComparer.cs" />
<Compile Include="ViewModel\ViewModelLocator.cs" />
<Page Include="LoadingDialog.xaml">
<SubType>Designer</SubType>