Skip to content

Commit a76f653

Browse files
committed
Allow latest C# syntax
1 parent 1c36051 commit a76f653

File tree

89 files changed

+1643
-1566
lines changed

Some content is hidden

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

89 files changed

+1643
-1566
lines changed

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[*.cs]
2+
3+
# IDE0063: Use simple 'using' statement
4+
dotnet_diagnostic.IDE0063.severity = warning

TestPlatform.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{EE49
9797
EndProject
9898
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E344E0A2-7715-4C7F-BAF7-D64EA94CB19B}"
9999
ProjectSection(SolutionItems) = preProject
100+
.editorconfig = .editorconfig
100101
Nuget.config = Nuget.config
101102
EndProjectSection
102103
EndProject

scripts/build/TestPlatform.Settings.targets

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
at the start of new iteration to the goal number. This is also used to version the local packages. This version needs to be statically
77
readable when we read the file as xml, don't move it to a .props file, unless you change the build server process -->
88
<TPVersionPrefix>17.2.0</TPVersionPrefix>
9+
<LangVersion>latest</LangVersion>
910
</PropertyGroup>
1011
<PropertyGroup>
1112
<!-- Versioning is defined from the build script. Use a default dev build if it's not defined.
@@ -37,7 +38,7 @@
3738

3839
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
3940
<DefineConstants>$(DefineConstants);CODE_ANALYSIS</DefineConstants>
40-
</PropertyGroup>
41+
</PropertyGroup>
4142

4243
<!-- Package dependency versions -->
4344
<Import Project="$(MSBuildThisFileDirectory)TestPlatform.Dependencies.props" Condition=" '$(DependencyVersionsImported)' != 'true' "/>
@@ -62,13 +63,13 @@
6263
<PrivateAssets>all</PrivateAssets>
6364
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
6465
</PackageReference>
65-
</ItemGroup>
66+
</ItemGroup>
6667
</When>
6768
</Choose>
6869

6970
<!-- Test project settings -->
7071
<Choose>
71-
<When Condition="$(TestProject) == 'true'">
72+
<When Condition="$(TestProject) == 'true'">
7273
<PropertyGroup>
7374
<GenerateDocumentationFile>false</GenerateDocumentationFile>
7475
</PropertyGroup>

src/DataCollectors/DumpMinitool/Program.cs

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -29,63 +29,61 @@ static int Main(string[] args)
2929

3030
var process = Process.GetProcessById(processId);
3131

32-
using (var stream = new FileStream(outputFile, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
32+
using var stream = new FileStream(outputFile, FileMode.Create, FileAccess.ReadWrite, FileShare.None);
33+
NativeMethods.MINIDUMP_EXCEPTION_INFORMATION exceptionInfo = default;
34+
35+
NativeMethods.MINIDUMP_TYPE dumpType = NativeMethods.MINIDUMP_TYPE.MiniDumpNormal;
36+
switch (type)
3337
{
34-
NativeMethods.MINIDUMP_EXCEPTION_INFORMATION exceptionInfo = default;
38+
case DumpTypeOption.Full:
39+
dumpType = NativeMethods.MINIDUMP_TYPE.MiniDumpWithFullMemory |
40+
NativeMethods.MINIDUMP_TYPE.MiniDumpWithDataSegs |
41+
NativeMethods.MINIDUMP_TYPE.MiniDumpWithHandleData |
42+
NativeMethods.MINIDUMP_TYPE.MiniDumpWithUnloadedModules |
43+
NativeMethods.MINIDUMP_TYPE.MiniDumpWithFullMemoryInfo |
44+
NativeMethods.MINIDUMP_TYPE.MiniDumpWithThreadInfo |
45+
NativeMethods.MINIDUMP_TYPE.MiniDumpWithTokenInformation;
46+
break;
47+
case DumpTypeOption.WithHeap:
48+
dumpType = NativeMethods.MINIDUMP_TYPE.MiniDumpWithPrivateReadWriteMemory |
49+
NativeMethods.MINIDUMP_TYPE.MiniDumpWithDataSegs |
50+
NativeMethods.MINIDUMP_TYPE.MiniDumpWithHandleData |
51+
NativeMethods.MINIDUMP_TYPE.MiniDumpWithUnloadedModules |
52+
NativeMethods.MINIDUMP_TYPE.MiniDumpWithFullMemoryInfo |
53+
NativeMethods.MINIDUMP_TYPE.MiniDumpWithThreadInfo |
54+
NativeMethods.MINIDUMP_TYPE.MiniDumpWithTokenInformation;
55+
break;
56+
case DumpTypeOption.Mini:
57+
dumpType = NativeMethods.MINIDUMP_TYPE.MiniDumpWithThreadInfo;
58+
break;
59+
}
3560

36-
NativeMethods.MINIDUMP_TYPE dumpType = NativeMethods.MINIDUMP_TYPE.MiniDumpNormal;
37-
switch (type)
61+
// Retry the write dump on ERROR_PARTIAL_COPY
62+
for (int i = 0; i < 5; i++)
63+
{
64+
// Dump the process!
65+
if (NativeMethods.MiniDumpWriteDump(process.Handle, (uint)process.Id, stream.SafeFileHandle, dumpType, ref exceptionInfo, IntPtr.Zero, IntPtr.Zero))
3866
{
39-
case DumpTypeOption.Full:
40-
dumpType = NativeMethods.MINIDUMP_TYPE.MiniDumpWithFullMemory |
41-
NativeMethods.MINIDUMP_TYPE.MiniDumpWithDataSegs |
42-
NativeMethods.MINIDUMP_TYPE.MiniDumpWithHandleData |
43-
NativeMethods.MINIDUMP_TYPE.MiniDumpWithUnloadedModules |
44-
NativeMethods.MINIDUMP_TYPE.MiniDumpWithFullMemoryInfo |
45-
NativeMethods.MINIDUMP_TYPE.MiniDumpWithThreadInfo |
46-
NativeMethods.MINIDUMP_TYPE.MiniDumpWithTokenInformation;
47-
break;
48-
case DumpTypeOption.WithHeap:
49-
dumpType = NativeMethods.MINIDUMP_TYPE.MiniDumpWithPrivateReadWriteMemory |
50-
NativeMethods.MINIDUMP_TYPE.MiniDumpWithDataSegs |
51-
NativeMethods.MINIDUMP_TYPE.MiniDumpWithHandleData |
52-
NativeMethods.MINIDUMP_TYPE.MiniDumpWithUnloadedModules |
53-
NativeMethods.MINIDUMP_TYPE.MiniDumpWithFullMemoryInfo |
54-
NativeMethods.MINIDUMP_TYPE.MiniDumpWithThreadInfo |
55-
NativeMethods.MINIDUMP_TYPE.MiniDumpWithTokenInformation;
56-
break;
57-
case DumpTypeOption.Mini:
58-
dumpType = NativeMethods.MINIDUMP_TYPE.MiniDumpWithThreadInfo;
59-
break;
67+
Console.WriteLine("Dumped process.");
68+
return 0;
6069
}
61-
62-
// Retry the write dump on ERROR_PARTIAL_COPY
63-
for (int i = 0; i < 5; i++)
70+
else
6471
{
65-
// Dump the process!
66-
if (NativeMethods.MiniDumpWriteDump(process.Handle, (uint)process.Id, stream.SafeFileHandle, dumpType, ref exceptionInfo, IntPtr.Zero, IntPtr.Zero))
72+
int err = Marshal.GetHRForLastWin32Error();
73+
if (err != NativeMethods.ERROR_PARTIAL_COPY)
6774
{
68-
Console.WriteLine("Dumped process.");
69-
return 0;
75+
Console.WriteLine($"Error dumping process {err}");
76+
Marshal.ThrowExceptionForHR(err);
7077
}
7178
else
7279
{
73-
int err = Marshal.GetHRForLastWin32Error();
74-
if (err != NativeMethods.ERROR_PARTIAL_COPY)
75-
{
76-
Console.WriteLine($"Error dumping process {err}");
77-
Marshal.ThrowExceptionForHR(err);
78-
}
79-
else
80-
{
81-
Console.WriteLine($"Error dumping process, was ERROR_PARTIAL_COPY, retrying.");
82-
}
80+
Console.WriteLine($"Error dumping process, was ERROR_PARTIAL_COPY, retrying.");
8381
}
8482
}
85-
86-
Console.WriteLine($"Error dumping process after 5 retries.");
87-
return 1;
8883
}
84+
85+
Console.WriteLine($"Error dumping process after 5 retries.");
86+
return 1;
8987
}
9088

9189
private static class NativeMethods

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,10 @@ protected virtual void Dispose(bool disposing)
260260

261261
private void CreateEventLog(string eventLogName)
262262
{
263-
this.eventLog = new EventLog(eventLogName);
264-
this.eventLog.EnableRaisingEvents = true;
263+
this.eventLog = new EventLog(eventLogName)
264+
{
265+
EnableRaisingEvents = true
266+
};
265267
this.eventLog.EntryWritten += this.OnEventLogEntryWritten;
266268
int currentCount = this.eventLog.Entries.Count;
267269
this.nextEntryIndexToCollect =

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

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -34,55 +34,57 @@ internal static class EventLogXmlWriter
3434
/// </param>
3535
public static void WriteEventLogEntriesToXmlFile(string xmlFilePath, List<EventLogEntry> eventLogEntries, IFileHelper fileHelper)
3636
{
37-
using (DataTable dataTable = new DataTable())
38-
{
39-
dataTable.Locale = CultureInfo.InvariantCulture;
37+
using DataTable dataTable = new DataTable();
38+
dataTable.Locale = CultureInfo.InvariantCulture;
4039

41-
// The MaxLength of the Type and Source columns must be set to allow indices to be created on them
42-
DataColumn typeColumn = new DataColumn("Type", typeof(string));
43-
typeColumn.MaxLength = EventLogConstants.TypeColumnMaxLength;
44-
dataTable.Columns.Add(typeColumn);
40+
// The MaxLength of the Type and Source columns must be set to allow indices to be created on them
41+
DataColumn typeColumn = new DataColumn("Type", typeof(string))
42+
{
43+
MaxLength = EventLogConstants.TypeColumnMaxLength
44+
};
45+
dataTable.Columns.Add(typeColumn);
4546

46-
dataTable.Columns.Add(new DataColumn("DateTime", typeof(DateTime)));
47+
dataTable.Columns.Add(new DataColumn("DateTime", typeof(DateTime)));
4748

48-
DataColumn sourceColumn = new DataColumn("Source", typeof(string));
49-
sourceColumn.MaxLength = EventLogConstants.SourceColumnMaxLength;
50-
dataTable.Columns.Add(sourceColumn);
49+
DataColumn sourceColumn = new DataColumn("Source", typeof(string))
50+
{
51+
MaxLength = EventLogConstants.SourceColumnMaxLength
52+
};
53+
dataTable.Columns.Add(sourceColumn);
5154

52-
dataTable.Columns.Add(new DataColumn("Category", typeof(string)));
53-
dataTable.Columns.Add(new DataColumn("EventID", typeof(long)));
54-
dataTable.Columns.Add(new DataColumn("Description", typeof(string)));
55-
dataTable.Columns.Add(new DataColumn("User", typeof(string)));
56-
dataTable.Columns.Add(new DataColumn("Computer", typeof(string)));
57-
dataTable.ExtendedProperties.Add("TimestampColumnName", "DateTime");
58-
dataTable.ExtendedProperties.Add("IndexColumnNames", "Source,Type");
55+
dataTable.Columns.Add(new DataColumn("Category", typeof(string)));
56+
dataTable.Columns.Add(new DataColumn("EventID", typeof(long)));
57+
dataTable.Columns.Add(new DataColumn("Description", typeof(string)));
58+
dataTable.Columns.Add(new DataColumn("User", typeof(string)));
59+
dataTable.Columns.Add(new DataColumn("Computer", typeof(string)));
60+
dataTable.ExtendedProperties.Add("TimestampColumnName", "DateTime");
61+
dataTable.ExtendedProperties.Add("IndexColumnNames", "Source,Type");
5962

60-
foreach (EventLogEntry entry in eventLogEntries)
61-
{
62-
DataRow row = dataTable.NewRow();
63-
row["Type"] = entry.EntryType.ToString();
64-
row["DateTime"] = entry.TimeGenerated;
65-
row["Source"] = entry.Source;
66-
row["Category"] = entry.Category;
67-
row["EventID"] = entry.InstanceId;
68-
row["Description"] = entry.Message;
69-
row["User"] = entry.UserName;
70-
row["Computer"] = entry.MachineName;
71-
dataTable.Rows.Add(row);
72-
}
63+
foreach (EventLogEntry entry in eventLogEntries)
64+
{
65+
DataRow row = dataTable.NewRow();
66+
row["Type"] = entry.EntryType.ToString();
67+
row["DateTime"] = entry.TimeGenerated;
68+
row["Source"] = entry.Source;
69+
row["Category"] = entry.Category;
70+
row["EventID"] = entry.InstanceId;
71+
row["Description"] = entry.Message;
72+
row["User"] = entry.UserName;
73+
row["Computer"] = entry.MachineName;
74+
dataTable.Rows.Add(row);
75+
}
7376

74-
DataSet dataSet = new DataSet();
75-
dataSet.Locale = CultureInfo.InvariantCulture;
76-
dataSet.Tables.Add(dataTable);
77+
DataSet dataSet = new DataSet
78+
{
79+
Locale = CultureInfo.InvariantCulture
80+
};
81+
dataSet.Tables.Add(dataTable);
7782

78-
// Use UTF-16 encoding
79-
StringBuilder stringBuilder = new StringBuilder();
80-
using (StringWriter stringWriter = new StringWriter(stringBuilder))
81-
{
82-
dataSet.WriteXml(stringWriter, XmlWriteMode.WriteSchema);
83-
fileHelper.WriteAllTextToFile(xmlFilePath, stringBuilder.ToString());
84-
}
85-
}
83+
// Use UTF-16 encoding
84+
StringBuilder stringBuilder = new StringBuilder();
85+
using StringWriter stringWriter = new StringWriter(stringBuilder);
86+
dataSet.WriteXml(stringWriter, XmlWriteMode.WriteSchema);
87+
fileHelper.WriteAllTextToFile(xmlFilePath, stringBuilder.ToString());
8688
}
8789
}
8890
#endregion

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,13 @@ public int Execute()
3838
Tracing.Trace("VSTest: Starting vstest.console...");
3939
Tracing.Trace("VSTest: Arguments: " + processInfo.FileName + " " + processInfo.Arguments);
4040

41-
using (var activeProcess = new Process { StartInfo = processInfo })
42-
{
43-
activeProcess.Start();
44-
this.activeProcessId = activeProcess.Id;
41+
using var activeProcess = new Process { StartInfo = processInfo };
42+
activeProcess.Start();
43+
this.activeProcessId = activeProcess.Id;
4544

46-
activeProcess.WaitForExit();
47-
Tracing.Trace("VSTest: Exit code: " + activeProcess.ExitCode);
48-
return activeProcess.ExitCode;
49-
}
45+
activeProcess.WaitForExit();
46+
Tracing.Trace("VSTest: Exit code: " + activeProcess.ExitCode);
47+
return activeProcess.ExitCode;
5048
}
5149

5250
public void Cancel()

src/Microsoft.TestPlatform.Client/Discovery/DiscoveryRequest.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,10 @@ private void HandleLoggerManagerDiscoveryComplete(DiscoveryCompletePayload disco
425425
}
426426

427427
// Send discovery complete to logger manager.
428-
var discoveryCompleteEventArgs = new DiscoveryCompleteEventArgs(discoveryCompletePayload.TotalTests, discoveryCompletePayload.IsAborted);
429-
discoveryCompleteEventArgs.Metrics = discoveryCompletePayload.Metrics;
428+
var discoveryCompleteEventArgs = new DiscoveryCompleteEventArgs(discoveryCompletePayload.TotalTests, discoveryCompletePayload.IsAborted)
429+
{
430+
Metrics = discoveryCompletePayload.Metrics
431+
};
430432
this.LoggerManager.HandleDiscoveryComplete(discoveryCompleteEventArgs);
431433
}
432434
}

src/Microsoft.TestPlatform.Common/DataCollection/TestPlatformDataCollectionLogger.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,11 @@ private void SendTextMessage(DataCollectionContext context, string text, TestMes
143143
throw new InvalidOperationException(Resources.Resources.WrongDataCollectionContextType);
144144
}
145145

146-
var args = new DataCollectionMessageEventArgs(level, text);
147-
args.Uri = this.dataCollectorConfig.TypeUri;
148-
args.FriendlyName = this.dataCollectorConfig.FriendlyName;
146+
var args = new DataCollectionMessageEventArgs(level, text)
147+
{
148+
Uri = this.dataCollectorConfig.TypeUri,
149+
FriendlyName = this.dataCollectorConfig.FriendlyName
150+
};
149151
if (context.HasTestCase)
150152
{
151153
args.TestCaseId = context.TestExecId.Id;

src/Microsoft.TestPlatform.Common/ExtensionFramework/Utilities/TestExtensions.cs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -144,36 +144,37 @@ internal Dictionary<string, TPluginInfo> AddExtension<TPluginInfo>(
144144
/// <returns> The test extensions defined the extension assembly if it is already discovered. null if not.</returns>
145145
internal TestExtensions GetExtensionsDiscoveredFromAssembly(string extensionAssembly)
146146
{
147-
var testExtensions = new TestExtensions();
148-
149-
testExtensions.TestDiscoverers =
147+
var testExtensions = new TestExtensions
148+
{
149+
TestDiscoverers =
150150
this.GetExtensionsDiscoveredFromAssembly(
151151
this.TestDiscoverers,
152-
extensionAssembly);
153-
testExtensions.TestExecutors =
152+
extensionAssembly),
153+
TestExecutors =
154154
this.GetExtensionsDiscoveredFromAssembly(
155155
this.TestExecutors,
156-
extensionAssembly);
157-
testExtensions.TestExecutors2 =
156+
extensionAssembly),
157+
TestExecutors2 =
158158
this.GetExtensionsDiscoveredFromAssembly(
159159
this.TestExecutors2,
160-
extensionAssembly);
161-
testExtensions.TestSettingsProviders =
160+
extensionAssembly),
161+
TestSettingsProviders =
162162
this.GetExtensionsDiscoveredFromAssembly(
163163
this.TestSettingsProviders,
164-
extensionAssembly);
165-
testExtensions.TestLoggers =
164+
extensionAssembly),
165+
TestLoggers =
166166
this.GetExtensionsDiscoveredFromAssembly(
167167
this.TestLoggers,
168-
extensionAssembly);
169-
testExtensions.TestHosts =
168+
extensionAssembly),
169+
TestHosts =
170170
this.GetExtensionsDiscoveredFromAssembly(
171171
this.TestHosts,
172-
extensionAssembly);
173-
testExtensions.DataCollectors =
172+
extensionAssembly),
173+
DataCollectors =
174174
this.GetExtensionsDiscoveredFromAssembly(
175175
this.DataCollectors,
176-
extensionAssembly);
176+
extensionAssembly)
177+
};
177178

178179
if (testExtensions.TestDiscoverers.Any()
179180
|| testExtensions.TestExecutors.Any()

0 commit comments

Comments
 (0)