Skip to content

Commit 3248f42

Browse files
authored
Enable Roslyn analysis - Test Applications - final (#4731)
1 parent 0542dbb commit 3248f42

File tree

122 files changed

+598
-337
lines changed

Some content is hidden

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

122 files changed

+598
-337
lines changed

build/LibraryVersions.g.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static partial class LibraryVersion
4242
[
4343
new("6.0.3"),
4444
new("7.0.0"),
45-
new("8.0.0"),
45+
new("8.0.3"),
4646
new("9.0.0"),
4747
]
4848
},

test/IntegrationTests/ContinuousProfilerTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ private static bool ContainPeriod(Profile profile, string profilingSampleType, s
112112

113113
private static List<string> CreateExpectedStackTrace()
114114
{
115-
var stackTrace = new List<string>
116-
{
115+
List<string> stackTrace =
116+
[
117117
"System.Threading.Thread.Sleep(System.TimeSpan)",
118118
"TestApplication.ContinuousProfiler.Fs.ClassFs.methodFs(System.String)",
119119
"TestApplication.ContinuousProfiler.Vb.ClassVb.MethodVb(System.String)",
@@ -126,7 +126,7 @@ private static List<string> CreateExpectedStackTrace()
126126
"My.Custom.Test.Namespace.ClassD`21.MethodD(T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, Unknown)",
127127
"My.Custom.Test.Namespace.GenericClassC`1.GenericMethodCFromGenericClass[T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20](T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, Unknown)",
128128
"My.Custom.Test.Namespace.GenericClassC`1.GenericMethodCFromGenericClass(T)"
129-
};
129+
];
130130

131131
#if NETFRAMEWORK || DEBUG
132132
stackTrace.Add("Unknown_Native_Function(unknown)");
@@ -148,7 +148,7 @@ private static List<string> CreateExpectedStackTrace()
148148
return stackTrace;
149149
}
150150

151-
private bool ContainStackTraceForClassHierarchy(Profile profile, string expectedStackTrace)
151+
private static bool ContainStackTraceForClassHierarchy(Profile profile, string expectedStackTrace)
152152
{
153153
var frames = profile.LocationTable
154154
.SelectMany(location => location.Line)

test/IntegrationTests/LibraryVersions.g.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static TheoryData<string> EntityFrameworkCorePomeloMySql
7373
#else
7474
"6.0.3",
7575
"7.0.0",
76-
"8.0.0",
76+
"8.0.3",
7777
"9.0.0",
7878
#endif
7979
];

test/IntegrationTests/Log4NetBridgeTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void SubmitLogs_ThroughLog4NetBridge_WhenLog4NetIsUsedDirectlyForLogging(
3737
// Logged with exception
3838
collector.Expect(
3939
logRecord =>
40-
VerifyBody(logRecord, "Exception occured") &&
40+
VerifyBody(logRecord, "Exception occurred") &&
4141
logRecord is { SeverityText: "ERROR", SeverityNumber: SeverityNumber.Error } &&
4242
VerifyExceptionAttributes(logRecord) &&
4343
logRecord.Attributes.Count == 4,
@@ -69,7 +69,7 @@ public void SubmitLogs_ThroughILoggerBridge_WhenLog4NetIsUsedAsILoggerAppenderFo
6969
// Logged in scope of an activity
7070
collector.Expect(
7171
logRecord =>
72-
VerifyBody(logRecord, "{0}, {1} at {2:t}!") &&
72+
VerifyBody(logRecord, "{hello}, {world} at {time:t}!") &&
7373
VerifyTraceContext(logRecord) &&
7474
logRecord is { SeverityText: "Information", SeverityNumber: SeverityNumber.Info } &&
7575
// 0 : "Hello"
@@ -81,7 +81,7 @@ public void SubmitLogs_ThroughILoggerBridge_WhenLog4NetIsUsedAsILoggerAppenderFo
8181
// Logged with exception
8282
collector.Expect(
8383
logRecord =>
84-
VerifyBody(logRecord, "Exception occured") &&
84+
VerifyBody(logRecord, "Exception occurred") &&
8585
// OtlpLogExporter adds exception related attributes (ConsoleExporter doesn't show them)
8686
logRecord is { SeverityText: "Error", SeverityNumber: SeverityNumber.Error } &&
8787
VerifyExceptionAttributes(logRecord) &&
@@ -148,7 +148,7 @@ public void TraceContext_IsInjectedIntoCurrentLog4NetLogsDestination(string pack
148148
var regex = new Regex(@"INFO TestApplication\.Log4NetBridge\.Program - Hello, world at \d{2}\:\d{2}\! span_id=[a-f0-9]{16} trace_id=[a-f0-9]{32} trace_flags=01");
149149
var output = standardOutput;
150150
Assert.Matches(regex, output);
151-
Assert.Contains("ERROR TestApplication.Log4NetBridge.Program - Exception occured span_id=(null) trace_id=(null) trace_flags=(null)", output);
151+
Assert.Contains("ERROR TestApplication.Log4NetBridge.Program - Exception occurred span_id=(null) trace_id=(null) trace_flags=(null)", output);
152152
}
153153

154154
private static bool VerifyAttributes(LogRecord logRecord)
@@ -172,7 +172,7 @@ private static bool VerifyTraceContext(LogRecord logRecord)
172172
private static void AssertStandardOutputExpectations(string standardOutput)
173173
{
174174
Assert.Contains("INFO TestApplication.Log4NetBridge.Program - Hello, world at", standardOutput);
175-
Assert.Contains("ERROR TestApplication.Log4NetBridge.Program - Exception occured", standardOutput);
175+
Assert.Contains("ERROR TestApplication.Log4NetBridge.Program - Exception occurred", standardOutput);
176176
}
177177

178178
private static bool VerifyBody(LogRecord logRecord, string expectedBody)

test/IntegrationTests/MinimalApiTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,18 @@ public async Task SubmitsLogsWithoutDuplicates(bool enableByteCodeInstrumentatio
5555
collector.AssertCollected();
5656
}
5757

58-
private static bool ValidateCombinedLogsExport(IEnumerable<LogRecord> records)
58+
private static bool ValidateCombinedLogsExport(ICollection<LogRecord> records)
5959
{
6060
return ValidateSingleAppLogExport(records) && ValidateSingleBeforeHostLogRecord(records);
6161
}
6262

63-
private static bool ValidateSingleBeforeHostLogRecord(IEnumerable<LogRecord> records)
63+
private static bool ValidateSingleBeforeHostLogRecord(ICollection<LogRecord> records)
6464
{
6565
var beforeHostLogCount = records.Count(lr => Convert.ToString(lr.Body) == "{ \"stringValue\": \"Logged before host is built.\" }");
6666
return beforeHostLogCount == 1;
6767
}
6868

69-
private static bool ValidateSingleAppLogExport(IEnumerable<LogRecord> records)
69+
private static bool ValidateSingleAppLogExport(ICollection<LogRecord> records)
7070
{
7171
var appLogCount = records.Count(lr => Convert.ToString(lr.Body) == "{ \"stringValue\": \"Request received.\" }");
7272
return appLogCount == 1;

test/IntegrationTests/NLogBridgeTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void SubmitLogs_ThroughNLogBridge_WhenNLogIsUsedDirectlyForLogging(string
4646
// Logged with exception
4747
collector.Expect(
4848
logRecord =>
49-
VerifyBody(logRecord, "Exception occured") &&
49+
VerifyBody(logRecord, "Exception occurred") &&
5050
logRecord is { SeverityText: "Error", SeverityNumber: SeverityNumber.Error } &&
5151
VerifyExceptionAttributes(logRecord) &&
5252
logRecord.Attributes.Count == 3,
@@ -80,7 +80,7 @@ public void SubmitLogs_ThroughILoggerBridge_WhenNLogIsUsedAsILoggerProviderForLo
8080
// ILogger uses "Information" for Info level, not "Info"
8181
collector.Expect(
8282
logRecord =>
83-
VerifyBody(logRecord, "{0}, {1} at {2:t}!") &&
83+
VerifyBody(logRecord, "{hello}, {world} at {time:t}!") &&
8484
VerifyTraceContext(logRecord) &&
8585
logRecord is { SeverityText: "Information", SeverityNumber: SeverityNumber.Info } &&
8686
// 0 : "Hello"
@@ -92,7 +92,7 @@ public void SubmitLogs_ThroughILoggerBridge_WhenNLogIsUsedAsILoggerProviderForLo
9292
// Logged with exception
9393
collector.Expect(
9494
logRecord =>
95-
VerifyBody(logRecord, "Exception occured") &&
95+
VerifyBody(logRecord, "Exception occurred") &&
9696
// OtlpLogExporter adds exception related attributes (ConsoleExporter doesn't show them)
9797
logRecord is { SeverityText: "Error", SeverityNumber: SeverityNumber.Error } &&
9898
VerifyExceptionAttributes(logRecord) &&
@@ -159,7 +159,7 @@ public void TraceContext_IsInjectedIntoCurrentNLogLogsDestination(string package
159159
var regex = new Regex(@"INFO TestApplication\.NLogBridge\.Program - Hello, world at \d{1,2}\:\d{2}(\s*[AP]M)?\! TraceId=[a-f0-9]{32} SpanId=[a-f0-9]{16} TraceFlags=0[01]");
160160
var output = standardOutput;
161161
Assert.Matches(regex, output);
162-
Assert.Contains("ERROR TestApplication.NLogBridge.Program - Exception occured", output);
162+
Assert.Contains("ERROR TestApplication.NLogBridge.Program - Exception occurred", output);
163163
Assert.Contains("TraceId=", output);
164164
Assert.Contains("SpanId=", output);
165165
Assert.Contains("TraceFlags=", output);
@@ -189,7 +189,7 @@ private static void AssertStandardOutputExpectations(string standardOutput, bool
189189
Assert.Contains("INFO TestApplication.NLogBridge.Program - Message via wrapperType overload", standardOutput);
190190
}
191191

192-
Assert.Contains("ERROR TestApplication.NLogBridge.Program - Exception occured", standardOutput);
192+
Assert.Contains("ERROR TestApplication.NLogBridge.Program - Exception occurred", standardOutput);
193193
}
194194

195195
private static bool VerifyBody(LogRecord logRecord, string expectedBody)

test/NuGetPackagesTests/InstrumentationTargetTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ private void CreateTestApp(string tfm)
197197
Assert.Equal(0, RunDotNetCli(
198198
$"nuget add source \"{nugetArtifactsDir}\" --name nuget-artifacts --configfile nuget.config"));
199199
Assert.Equal(0, RunDotNetCli(
200-
$"add package OpenTelemetry.AutoInstrumentation --prerelease"));
200+
"add package OpenTelemetry.AutoInstrumentation --prerelease"));
201201

202202
Assert.Equal(0, RunDotNetCli("build"));
203203
}
@@ -222,7 +222,7 @@ private int RunDotNetCli(string arguments, string? expectedOutputFragment = null
222222

223223
Assert.NotNull(process);
224224

225-
bool processTimeout = !process!.WaitForExit((int)TestTimeout.ProcessExit.TotalMilliseconds);
225+
var processTimeout = !process!.WaitForExit((int)TestTimeout.ProcessExit.TotalMilliseconds);
226226
if (processTimeout)
227227
{
228228
process.Kill();

test/test-applications/integrations/Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
<!-- CA1031: Do not catch general exception types -->
1717
<!-- CA1303: Do not pass literals as localized parameters -->
1818
<NoWarn>$(NoWarn);CA1031;CA1303</NoWarn>
19+
<AnalysisLevel>latest-All</AnalysisLevel>
1920
</PropertyGroup>
2021
</Project>

test/test-applications/integrations/TestApplication.AssemblyRedirection.NetFramework/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
var loadedAssemblyNames = new HashSet<string>();
1010
var hasMultipleInstancesOfSingleAssembly = false;
1111
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
12-
Array.Sort<Assembly>(assemblies, (l, r) => l.FullName?.CompareTo(r.FullName) ?? -1);
12+
Array.Sort<Assembly>(assemblies, static (l, r) => string.CompareOrdinal(l.FullName, r.FullName));
1313
Console.WriteLine("Loaded assemblies:");
1414
foreach (var assembly in assemblies)
1515
{

test/test-applications/integrations/TestApplication.ContinuousProfiler.ContextTracking/Program.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
using System.Diagnostics;
5+
using TestApplication.Shared;
56

67
namespace TestApplication.ContinuousProfiler.ContextTracking;
78

8-
internal class Program
9+
internal static class Program
910
{
10-
private static readonly ActivitySource Source = new ActivitySource("TestApplication.ContinuousProfiler.ContextTracking");
11+
private static readonly ActivitySource Source = new("TestApplication.ContinuousProfiler.ContextTracking");
1112

1213
public static async Task Main(string[] args)
1314
{
15+
ConsoleHelper.WriteSplashScreen(args);
1416
Thread.CurrentThread.Name = "TestName";
1517
// Start an activity that remains active until async operation completes,
1618
// and verify that trace context flows properly between threads that carry out parts of the async operation.

0 commit comments

Comments
 (0)