-
Notifications
You must be signed in to change notification settings - Fork 349
Expand file tree
/
Copy pathTestSourcesUtility.cs
More file actions
61 lines (54 loc) · 2.24 KB
/
TestSourcesUtility.cs
File metadata and controls
61 lines (54 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Utilities;
/// <summary>
/// Test sources utility class
/// </summary>
internal class TestSourcesUtility
{
/// <summary>
/// Gets test sources from adapter source map
/// </summary>
/// <param name="adapterSourceMap"> The test list. </param>
/// <returns> List of test Sources </returns>
internal static IEnumerable<string>? GetSources(Dictionary<string, IEnumerable<string>?>? adapterSourceMap)
{
IEnumerable<string> sources = new List<string>();
return adapterSourceMap?.Values?.Aggregate(sources, (current, enumerable) => enumerable is not null ? current.Concat(enumerable) : current);
}
/// <summary>
/// Gets test sources from test case list
/// </summary>
/// <param name="tests"> The test list. </param>
/// <returns> List of test Sources </returns>
[return: NotNullIfNotNull("tests")]
internal static IEnumerable<string>? GetSources(IEnumerable<TestCase>? tests)
{
return tests?.Select(tc => tc.Source).Distinct();
}
/// <summary>
/// Gets default code base path for in-proc collector from test sources
/// </summary>
/// <param name="adapterSourceMap"> The test list. </param>
/// <returns> List of test Sources </returns>
internal static string? GetDefaultCodebasePath(Dictionary<string, IEnumerable<string>?> adapterSourceMap)
{
var source = GetSources(adapterSourceMap)?.FirstOrDefault();
return Path.GetDirectoryName(source);
}
/// <summary>
/// Gets default code base path for in-proc collector from test sources
/// </summary>
/// <param name="tests"> The test list. </param>
/// <returns> List of test Sources </returns>
internal static string? GetDefaultCodebasePath(IEnumerable<TestCase> tests)
{
var source = GetSources(tests)?.FirstOrDefault();
return Path.GetDirectoryName(source);
}
}