Actually make trait filter work and get rid of lots unnecessary allocation
This commit is contained in:
@@ -1,14 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Threading;
|
||||
using xunit.runner.data;
|
||||
using xunit.runner.wpf.ViewModel;
|
||||
|
||||
namespace xunit.runner.wpf
|
||||
{
|
||||
@@ -17,16 +12,16 @@ namespace xunit.runner.wpf
|
||||
/// <summary>
|
||||
/// Discover the list of test cases which are available in the specified assembly.
|
||||
/// </summary>
|
||||
Task Discover(string assemblyPath, Action<List<TestCaseData>> callback, CancellationToken cancellationToken = default(CancellationToken));
|
||||
Task Discover(string assemblyPath, Action<IEnumerable<TestCaseData>> callback, CancellationToken cancellationToken = default(CancellationToken));
|
||||
|
||||
/// <summary>
|
||||
/// Begin a run of all unit tests for the given assembly.
|
||||
/// </summary>
|
||||
Task RunAll(string assemblyPath, Action<List<TestResultData>> callback, CancellationToken cancellationToken = default(CancellationToken));
|
||||
Task RunAll(string assemblyPath, Action<IEnumerable<TestResultData>> callback, CancellationToken cancellationToken = default(CancellationToken));
|
||||
|
||||
/// <summary>
|
||||
/// Begin a run of specific unit tests for the given assembly.
|
||||
/// </summary>
|
||||
Task RunSpecific(string assemblyPath, ImmutableArray<string> testCaseDisplayNames, Action<List<TestResultData>> callback, CancellationToken cancellationToken = default(CancellationToken));
|
||||
Task RunSpecific(string assemblyPath, ImmutableArray<string> testCaseDisplayNames, Action<IEnumerable<TestResultData>> callback, CancellationToken cancellationToken = default(CancellationToken));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,15 +3,11 @@ using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.Pipes;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Threading;
|
||||
using xunit.runner.data;
|
||||
using xunit.runner.wpf.ViewModel;
|
||||
|
||||
namespace xunit.runner.wpf.Impl
|
||||
{
|
||||
@@ -137,17 +133,17 @@ namespace xunit.runner.wpf.Impl
|
||||
|
||||
#region ITestUtil
|
||||
|
||||
Task ITestUtil.Discover(string assemblyPath, Action<List<TestCaseData>> callback, CancellationToken cancellationToken)
|
||||
Task ITestUtil.Discover(string assemblyPath, Action<IEnumerable<TestCaseData>> callback, CancellationToken cancellationToken)
|
||||
{
|
||||
return Discover(assemblyPath, callback, cancellationToken);
|
||||
}
|
||||
|
||||
Task ITestUtil.RunAll(string assemblyPath, Action<List<TestResultData>> callback, CancellationToken cancellationToken)
|
||||
Task ITestUtil.RunAll(string assemblyPath, Action<IEnumerable<TestResultData>> callback, CancellationToken cancellationToken)
|
||||
{
|
||||
return RunCore(Constants.ActionRunAll, assemblyPath, ImmutableArray<string>.Empty, callback, cancellationToken);
|
||||
}
|
||||
|
||||
Task ITestUtil.RunSpecific(string assemblyPath, ImmutableArray<string> testCaseDisplayNames, Action<List<TestResultData>> callback, CancellationToken cancellationToken)
|
||||
Task ITestUtil.RunSpecific(string assemblyPath, ImmutableArray<string> testCaseDisplayNames, Action<IEnumerable<TestResultData>> callback, CancellationToken cancellationToken)
|
||||
{
|
||||
return RunCore(Constants.ActionRunSpecific, assemblyPath, testCaseDisplayNames, callback, cancellationToken);
|
||||
}
|
||||
|
||||
@@ -477,57 +477,42 @@ namespace xunit.runner.wpf.ViewModel
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTestDiscovered(List<TestCaseData> testCaseDataList)
|
||||
private void OnTestDiscovered(IEnumerable<TestCaseData> testCases)
|
||||
{
|
||||
var allTraits = new SortedDictionary<string, SortedSet<string>>();
|
||||
foreach (var data in testCaseDataList)
|
||||
var traitWorkerList = new List<TraitViewModel>();
|
||||
|
||||
foreach (var testCase in testCases)
|
||||
{
|
||||
AddTraits(allTraits, data);
|
||||
}
|
||||
traitWorkerList.Clear();
|
||||
|
||||
this.allTestCases.AddRange(testCaseDataList.Select(d =>
|
||||
new TestCaseViewModel(d.DisplayName, d.AssemblyPath, Convert(CreateSortedTraits(d)))));
|
||||
|
||||
this.traitCollectionView.AddRange(Convert(allTraits));
|
||||
}
|
||||
|
||||
private SortedDictionary<string, SortedSet<string>> CreateSortedTraits(TestCaseData data)
|
||||
{
|
||||
var traits = new SortedDictionary<string, SortedSet<string>>();
|
||||
AddTraits(traits, data);
|
||||
return traits;
|
||||
}
|
||||
|
||||
private static IEnumerable<TraitViewModel> Convert(SortedDictionary<string, SortedSet<string>> allTraits)
|
||||
{
|
||||
foreach (var trait in allTraits)
|
||||
{
|
||||
var name = trait.Key;
|
||||
var values = trait.Value;
|
||||
|
||||
var viewModel = new TraitViewModel(name);
|
||||
viewModel.AddValues(values);
|
||||
|
||||
yield return viewModel;
|
||||
}
|
||||
}
|
||||
|
||||
private static void AddTraits(SortedDictionary<string, SortedSet<string>> allTraits, TestCaseData data)
|
||||
{
|
||||
foreach (var kvp in data.TraitMap)
|
||||
{
|
||||
SortedSet<string> values;
|
||||
if (!allTraits.TryGetValue(kvp.Key, out values))
|
||||
// Get or create traits.
|
||||
if (testCase.TraitMap?.Count > 0)
|
||||
{
|
||||
values = new SortedSet<string>();
|
||||
allTraits.Add(kvp.Key, values);
|
||||
foreach (var kvp in testCase.TraitMap)
|
||||
{
|
||||
var name = kvp.Key;
|
||||
var values = kvp.Value;
|
||||
|
||||
var parentTraitViewModel = traitCollectionView.GetOrAdd(name);
|
||||
|
||||
foreach (var value in values)
|
||||
{
|
||||
var traitViewModel = parentTraitViewModel.GetOrAdd(value);
|
||||
traitWorkerList.Add(traitViewModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
values.AddRange(kvp.Value);
|
||||
var testCaseViewModel = new TestCaseViewModel(
|
||||
testCase.DisplayName,
|
||||
testCase.AssemblyPath,
|
||||
traitWorkerList);
|
||||
|
||||
this.allTestCases.Add(testCaseViewModel);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTestFinished(List<TestResultData> testResultData)
|
||||
private void OnTestFinished(IEnumerable<TestResultData> testResultData)
|
||||
{
|
||||
foreach (var data in testResultData)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
|
||||
@@ -26,6 +27,20 @@ namespace xunit.runner.wpf.ViewModel
|
||||
}
|
||||
}
|
||||
|
||||
public TraitViewModel GetOrAdd(string text)
|
||||
{
|
||||
var index = this.Collection.BinarySearch(text, StringComparer.Ordinal, vm => vm.Text);
|
||||
|
||||
if (index < 0)
|
||||
{
|
||||
var viewModel = new TraitViewModel(text);
|
||||
this.Collection.Insert(~index, viewModel);
|
||||
return viewModel;
|
||||
}
|
||||
|
||||
return this.Collection[index];
|
||||
}
|
||||
|
||||
public ISet<TraitViewModel> GetCheckedTraits()
|
||||
{
|
||||
return new HashSet<TraitViewModel>(
|
||||
|
||||
@@ -87,6 +87,20 @@ namespace xunit.runner.wpf.ViewModel
|
||||
}
|
||||
}
|
||||
|
||||
public TraitViewModel GetOrAdd(string text)
|
||||
{
|
||||
var index = this.Children.BinarySearch(text, StringComparer.Ordinal, vm => vm.Text);
|
||||
|
||||
if (index < 0)
|
||||
{
|
||||
var viewModel = new TraitViewModel(this, text);
|
||||
this.Children.Insert(~index, viewModel);
|
||||
return viewModel;
|
||||
}
|
||||
|
||||
return this.Children[index];
|
||||
}
|
||||
|
||||
public bool? IsChecked
|
||||
{
|
||||
get { return _isChecked; }
|
||||
|
||||
Reference in New Issue
Block a user