/
githubmirror
/
PowerShell
Обзор
Документация
Войти
/
githubmirror
/
PowerShell
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
test/xUnit/Asserts/PriorityOrderer.cs
56 строк
2 KB
xtqqczze
Enable CA1050: Declare types in namespaces (#13872)
26 окт 2020, 20:34
Не верифицирован
26 окт 2020, 20:34
9932560
Код
Авторство
О чём код?
// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using System; using System.Collections.Generic; using System.Linq; using PSTests.Internal; using Xunit.Abstractions; using Xunit.Sdk; namespace TestOrder.TestCaseOrdering { public class PriorityOrderer : ITestCaseOrderer { public IEnumerable<TTestCase> OrderTestCases<TTestCase>(IEnumerable<TTestCase> testCases) where TTestCase : ITestCase { var sortedMethods = new SortedDictionary<int, List<TTestCase>>(); foreach (TTestCase testCase in testCases) { int priority = 0; foreach (IAttributeInfo attr in testCase.TestMethod.Method.GetCustomAttributes(typeof(PriorityAttribute).AssemblyQualifiedName)) { priority = attr.GetNamedArgument<int>("Priority"); } GetOrCreate(sortedMethods, priority).Add(testCase); } foreach (var list in sortedMethods.Keys.Select(priority => sortedMethods[priority])) { list.Sort((x, y) => StringComparer.OrdinalIgnoreCase.Compare(x.TestMethod.Method.Name, y.TestMethod.Method.Name)); foreach (TTestCase testCase in list) { yield return testCase; } } } private static TValue GetOrCreate<TKey, TValue>(IDictionary<TKey, TValue> dictionary, TKey key) where TValue : new() { TValue result; if (dictionary.TryGetValue(key, out result)) { return result; } result = new TValue(); dictionary[key] = result; return result; } } }