Skip to content

Commit c211b20

Browse files
SimonCroppnohwnd
andauthored
use some collection expressions (#5055)
* use some collection expressions * Update RunSpecificTestsArgumentProcessor.cs * Update Converter.cs * Update RunSettingsUtilities.cs * Update DiscovererEnumerator.cs * Update PostProcessingTestRunAttachmentsProcessingEventsHandler.cs * Update RunSpecificTestsArgumentProcessor.cs * Update TestTaskUtilsTests.cs * Update GenerateFakesUtilitiesTests.cs * Update ProxyOperationManagerTests.cs * Update InProcessProxyDiscoveryManagerTests.cs * Update InProcessProxyexecutionManagerTests.cs * Update ProxyDiscoveryManagerTests.cs * Update ProxyDiscoveryManagerTests.cs * Update CLIRunSettingsArgumentProcessorTests.cs * Fix code style * Fix tests --------- Co-authored-by: Jakub Jareš <me@jakubjares.com>
1 parent a98de4e commit c211b20

136 files changed

Lines changed: 591 additions & 656 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

shared/NullableAttributes.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ internal sealed class MemberNotNullAttribute : Attribute
9696
/// <param name="member">
9797
/// The field or property member that is promised to be not-null.
9898
/// </param>
99-
public MemberNotNullAttribute(string member) => Members = new[] { member };
99+
public MemberNotNullAttribute(string member) => Members = [member];
100100

101101
/// <summary>Initializes the attribute with the list of field and property members.</summary>
102102
/// <param name="members">
@@ -122,7 +122,7 @@ internal sealed class MemberNotNullWhenAttribute : Attribute
122122
public MemberNotNullWhenAttribute(bool returnValue, string member)
123123
{
124124
ReturnValue = returnValue;
125-
Members = new[] { member };
125+
Members = [member];
126126
}
127127

128128
/// <summary>Initializes the attribute with the specified return value condition and list of field and property members.</summary>

src/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector/EventLogDataCollector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ protected override void Dispose(bool disposing)
326326
private static ISet<string> ParseCommaSeparatedList(string commaSeparatedList)
327327
{
328328
ISet<string> strings = new HashSet<string>();
329-
string[] items = commaSeparatedList.Split(new char[] { ',' });
329+
string[] items = commaSeparatedList.Split([',']);
330330
foreach (string item in items)
331331
{
332332
strings.Add(item.Trim());

src/Microsoft.TestPlatform.Build/Tasks/VSTestTask2.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class VSTestTask2 : ToolTask, ITestTask
4848
protected override Encoding StandardOutputEncoding => _disableUtf8ConsoleEncoding ? base.StandardOutputEncoding : Encoding.UTF8;
4949

5050
private readonly string _messageSplitter = "||||";
51-
private readonly string[] _messageSplitterArray = new[] { "||||" };
51+
private readonly string[] _messageSplitterArray = ["||||"];
5252
private readonly string _ansiReset = "\x1b[39;49m";
5353

5454
private readonly bool _disableUtf8ConsoleEncoding;
@@ -271,7 +271,7 @@ private bool TryGetMessage(string singleLine, out string name, out string?[] dat
271271
}
272272

273273
name = string.Empty;
274-
data = Array.Empty<string>();
274+
data = [];
275275
return false;
276276
}
277277

src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ public int LaunchCustomHost(TestProcessStartInfo testProcessStartInfo, Cancellat
334334
// Even if TP has a timeout here, there is no way TP can abort or stop the thread/task that is hung in IDE or LUT
335335
// Even if TP can abort the API somehow, TP is essentially putting IDEs or Clients in inconsistent state without having info on
336336
// Since the IDEs own user-UI-experience here, TP will let the custom host launch as much time as IDEs define it for their users
337-
WaitHandle.WaitAny(new WaitHandle[] { waitHandle, cancellationToken.WaitHandle });
337+
WaitHandle.WaitAny([waitHandle, cancellationToken.WaitHandle]);
338338

339339
cancellationToken.ThrowTestPlatformExceptionIfCancellationRequested();
340340

@@ -387,7 +387,7 @@ public bool AttachDebuggerToProcess(AttachDebuggerInfo attachDebuggerInfo, Cance
387387
_communicationManager.SendMessage(MessageType.EditorAttachDebugger2, payload);
388388
}
389389

390-
WaitHandle.WaitAny(new WaitHandle[] { waitHandle, cancellationToken.WaitHandle });
390+
WaitHandle.WaitAny([waitHandle, cancellationToken.WaitHandle]);
391391

392392
cancellationToken.ThrowTestPlatformExceptionIfCancellationRequested();
393393
onAttachDebuggerAckRecieved = null;

src/Microsoft.TestPlatform.Client/TestPlatform.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ private static void AddExtensionAssembliesFromExtensionDirectory()
283283
TestAdapterLoadingStrategy strategy = runConfiguration.TestAdapterLoadingStrategy;
284284

285285
FileHelper fileHelper = new();
286-
IEnumerable<string> defaultExtensionPaths = Enumerable.Empty<string>();
286+
IEnumerable<string> defaultExtensionPaths = [];
287287

288288
// Explicit adapter loading
289289
if (strategy.HasFlag(TestAdapterLoadingStrategy.Explicit))
@@ -354,7 +354,7 @@ private static IEnumerable<string> ExpandAdaptersWithExplicitStrategy(string pat
354354
{
355355
if (!strategy.HasFlag(TestAdapterLoadingStrategy.Explicit))
356356
{
357-
return Enumerable.Empty<string>();
357+
return [];
358358
}
359359

360360
if (fileHelper.Exists(path))
@@ -377,7 +377,7 @@ private static IEnumerable<string> ExpandAdaptersWithExplicitStrategy(string pat
377377
}
378378

379379
EqtTrace.Warning($"{nameof(TestPlatform)}.{nameof(ExpandAdaptersWithExplicitStrategy)} AdapterPath Not Found: {path}");
380-
return Enumerable.Empty<string>();
380+
return [];
381381
}
382382

383383
private static IEnumerable<string> ExpandAdaptersWithDefaultStrategy(string path, IFileHelper fileHelper)
@@ -388,7 +388,7 @@ private static IEnumerable<string> ExpandAdaptersWithDefaultStrategy(string path
388388
{
389389
EqtTrace.Warning($"{nameof(TestPlatform)}.{nameof(ExpandAdaptersWithDefaultStrategy)} AdapterPath Not Found: {path}");
390390

391-
return Enumerable.Empty<string>();
391+
return [];
392392
}
393393

394394
return fileHelper.EnumerateFiles(

src/Microsoft.TestPlatform.Common/ExtensionFramework/VSExtensionManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private IEnumerable<string> GetTestExtensionsInternal(string extensionType)
8585
var resolutionPaths = installContext.GetVisualStudioCommonLocations(vsInstallPath);
8686
using (var assemblyResolver = new AssemblyResolver(resolutionPaths))
8787
{
88-
var settingsManager = SettingsManagerType.GetMethod("CreateForApplication", new Type[] { typeof(string) })?.Invoke(null, new object[] { installContext.GetVisualStudioPath(vsInstallPath) });
88+
var settingsManager = SettingsManagerType.GetMethod("CreateForApplication", [typeof(string)])?.Invoke(null, [installContext.GetVisualStudioPath(vsInstallPath)]);
8989
if (settingsManager == null)
9090
{
9191
EqtTrace.Warning("VSExtensionManager : Unable to create settings manager");
@@ -99,8 +99,8 @@ private IEnumerable<string> GetTestExtensionsInternal(string extensionType)
9999

100100
if (extensionManager != null)
101101
{
102-
installedExtensions = ExtensionManagerServiceType.GetMethod("GetEnabledExtensionContentLocations", new Type[] { typeof(string) })?.Invoke(
103-
extensionManager, new object[] { extensionType }) as IEnumerable<string>;
102+
installedExtensions = ExtensionManagerServiceType.GetMethod("GetEnabledExtensionContentLocations", [typeof(string)])?.Invoke(
103+
extensionManager, [extensionType]) as IEnumerable<string>;
104104
}
105105
else
106106
{

src/Microsoft.TestPlatform.Common/Filtering/FilterExpression.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ private static void ProcessOperator(Stack<FilterExpression> filterStack, Operato
122122
if (null == properties)
123123
{
124124
// if null, initialize to empty list so that invalid properties can be found.
125-
properties = Enumerable.Empty<string>();
125+
properties = [];
126126
}
127127

128128
return IterateFilterExpression<string[]?>((current, result) =>
@@ -132,7 +132,7 @@ private static void ProcessOperator(Stack<FilterExpression> filterStack, Operato
132132
{
133133
var valid = current._condition.ValidForProperties(properties, propertyProvider);
134134
// If it's not valid will add it to the function's return array.
135-
return !valid ? new string[1] { current._condition.Name } : null;
135+
return !valid ? [current._condition.Name] : null;
136136
}
137137

138138
// Concatenate the children node's result to get their parent result.

src/Microsoft.TestPlatform.Common/Utilities/AssemblyResolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ internal class AssemblyResolver : IDisposable
4040

4141
private readonly IAssemblyLoadContext _platformAssemblyLoadContext;
4242

43-
private static readonly string[] SupportedFileExtensions = { ".dll", ".exe" };
43+
private static readonly string[] SupportedFileExtensions = [".dll", ".exe"];
4444

4545
/// <summary>
4646
/// Initializes a new instance of the <see cref="AssemblyResolver"/> class.

src/Microsoft.TestPlatform.Common/Utilities/FakesUtilities.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ private static void EnsureSettingsNode(XmlDocument settings, TestRunSettings set
231231
{
232232
var assembly = LoadTestPlatformAssembly();
233233
var type = assembly?.GetType(ConfiguratorAssemblyQualifiedName, false);
234-
var method = type?.GetMethod(NetFrameworkConfiguratorMethodName, new Type[] { typeof(IEnumerable<string>) });
234+
var method = type?.GetMethod(NetFrameworkConfiguratorMethodName, [typeof(IEnumerable<string>)]);
235235
if (method != null)
236236
{
237237
return (Func<IEnumerable<string>, string>)method.CreateDelegate(typeof(Func<IEnumerable<string>, string>));
@@ -251,7 +251,7 @@ private static void EnsureSettingsNode(XmlDocument settings, TestRunSettings set
251251
{
252252
var assembly = LoadTestPlatformAssembly();
253253
var type = assembly?.GetType(ConfiguratorAssemblyQualifiedName, false, false);
254-
var method = type?.GetMethod(CrossPlatformConfiguratorMethodName, new Type[] { typeof(IDictionary<string, FrameworkVersion>) });
254+
var method = type?.GetMethod(CrossPlatformConfiguratorMethodName, [typeof(IDictionary<string, FrameworkVersion>)]);
255255
if (method != null)
256256
{
257257
return (Func<IDictionary<string, FrameworkVersion>, DataCollectorSettings>)method.CreateDelegate(typeof(Func<IDictionary<string, FrameworkVersion>, DataCollectorSettings>));

src/Microsoft.TestPlatform.Common/Utilities/InstallationContext.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ public string GetVisualStudioPath(string visualStudioDirectory)
4848
[SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Part of the public API")]
4949
public string[] GetVisualStudioCommonLocations(string visualStudioDirectory)
5050
{
51-
return new[]
52-
{
51+
return
52+
[
5353
Path.Combine(visualStudioDirectory, PrivateAssembliesDirName),
5454
Path.Combine(visualStudioDirectory, PublicAssembliesDirName),
5555
Path.Combine(visualStudioDirectory, "CommonExtensions", "Microsoft", "TestWindow"),
5656
Path.Combine(visualStudioDirectory, "CommonExtensions", "Microsoft", "TeamFoundation", "Team Explorer"),
5757
visualStudioDirectory
58-
};
58+
];
5959
}
6060
}

0 commit comments

Comments
 (0)