diff --git a/docs/logs/redaction/MyClassWithRedactionEnumerator.cs b/docs/logs/redaction/MyClassWithRedactionEnumerator.cs index e8030a01581..d354e4f5748 100644 --- a/docs/logs/redaction/MyClassWithRedactionEnumerator.cs +++ b/docs/logs/redaction/MyClassWithRedactionEnumerator.cs @@ -16,45 +16,44 @@ using System.Collections; -namespace Redaction +namespace Redaction; + +internal class MyClassWithRedactionEnumerator : IReadOnlyList> { - internal class MyClassWithRedactionEnumerator : IReadOnlyList> - { - private readonly IReadOnlyList> state; + private readonly IReadOnlyList> state; - public MyClassWithRedactionEnumerator(IReadOnlyList> state) - { - this.state = state; - } + public MyClassWithRedactionEnumerator(IReadOnlyList> state) + { + this.state = state; + } - public int Count => this.state.Count; + public int Count => this.state.Count; - public KeyValuePair this[int index] + public KeyValuePair this[int index] + { + get { - get + var item = this.state[index]; + var entryVal = item.Value; + if (entryVal != null && entryVal.ToString() != null && entryVal.ToString().Contains("")) { - var item = this.state[index]; - var entryVal = item.Value; - if (entryVal != null && entryVal.ToString() != null && entryVal.ToString().Contains("")) - { - return new KeyValuePair(item.Key, "newRedactedValueHere"); - } - - return item; + return new KeyValuePair(item.Key, "newRedactedValueHere"); } - } - public IEnumerator> GetEnumerator() - { - for (var i = 0; i < this.Count; i++) - { - yield return this[i]; - } + return item; } + } - IEnumerator IEnumerable.GetEnumerator() + public IEnumerator> GetEnumerator() + { + for (var i = 0; i < this.Count; i++) { - return this.GetEnumerator(); + yield return this[i]; } } + + IEnumerator IEnumerable.GetEnumerator() + { + return this.GetEnumerator(); + } } diff --git a/test/OpenTelemetry.AotCompatibility.Tests/AotCompatibilityTests.cs b/test/OpenTelemetry.AotCompatibility.Tests/AotCompatibilityTests.cs index a9d715b5357..fd9cb63c1be 100644 --- a/test/OpenTelemetry.AotCompatibility.Tests/AotCompatibilityTests.cs +++ b/test/OpenTelemetry.AotCompatibility.Tests/AotCompatibilityTests.cs @@ -18,74 +18,73 @@ using Xunit; using Xunit.Abstractions; -namespace OpenTelemetry.AotCompatibility.Tests +namespace OpenTelemetry.AotCompatibility.Tests; + +public class AotCompatibilityTests { - public class AotCompatibilityTests + private readonly ITestOutputHelper testOutputHelper; + + public AotCompatibilityTests(ITestOutputHelper testOutputHelper) + { + this.testOutputHelper = testOutputHelper; + } + + /// + /// This test ensures that the intended APIs of the OpenTelemetry.AotCompatibility.TestApp libraries are + /// trimming and NativeAOT compatible. + /// + /// This test follows the instructions in https://learn.microsoft.com/dotnet/core/deploying/trimming/prepare-libraries-for-trimming#show-all-warnings-with-sample-application + /// + /// If this test fails, it is due to adding trimming and/or AOT incompatible changes + /// to code that is supposed to be compatible. + /// + /// To diagnose the problem, inspect the test output which will contain the trimming and AOT errors. For example: + /// + /// error IL2091: 'T' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors'. + /// + [Fact] + public void EnsureAotCompatibility() { - private readonly ITestOutputHelper testOutputHelper; + string[] paths = { @"..", "..", "..", "..", "OpenTelemetry.AotCompatibility.TestApp" }; + string testAppPath = Path.Combine(paths); + string testAppProject = "OpenTelemetry.AotCompatibility.TestApp.csproj"; - public AotCompatibilityTests(ITestOutputHelper testOutputHelper) + // ensure we run a clean publish every time + DirectoryInfo testObjDir = new DirectoryInfo(Path.Combine(testAppPath, "obj")); + if (testObjDir.Exists) { - this.testOutputHelper = testOutputHelper; + testObjDir.Delete(recursive: true); } - /// - /// This test ensures that the intended APIs of the OpenTelemetry.AotCompatibility.TestApp libraries are - /// trimming and NativeAOT compatible. - /// - /// This test follows the instructions in https://learn.microsoft.com/dotnet/core/deploying/trimming/prepare-libraries-for-trimming#show-all-warnings-with-sample-application - /// - /// If this test fails, it is due to adding trimming and/or AOT incompatible changes - /// to code that is supposed to be compatible. - /// - /// To diagnose the problem, inspect the test output which will contain the trimming and AOT errors. For example: - /// - /// error IL2091: 'T' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors'. - /// - [Fact] - public void EnsureAotCompatibility() + var process = new Process { - string[] paths = { @"..", "..", "..", "..", "OpenTelemetry.AotCompatibility.TestApp" }; - string testAppPath = Path.Combine(paths); - string testAppProject = "OpenTelemetry.AotCompatibility.TestApp.csproj"; - - // ensure we run a clean publish every time - DirectoryInfo testObjDir = new DirectoryInfo(Path.Combine(testAppPath, "obj")); - if (testObjDir.Exists) + // set '-nodereuse:false /p:UseSharedCompilation=false' so the MSBuild and Roslyn server processes don't hang around, which may hang the test in CI + StartInfo = new ProcessStartInfo("dotnet", $"publish {testAppProject} --self-contained -nodereuse:false /p:UseSharedCompilation=false") { - testObjDir.Delete(recursive: true); - } - - var process = new Process - { - // set '-nodereuse:false /p:UseSharedCompilation=false' so the MSBuild and Roslyn server processes don't hang around, which may hang the test in CI - StartInfo = new ProcessStartInfo("dotnet", $"publish {testAppProject} --self-contained -nodereuse:false /p:UseSharedCompilation=false") - { - RedirectStandardOutput = true, - UseShellExecute = false, - CreateNoWindow = true, - WorkingDirectory = testAppPath, - }, - }; + RedirectStandardOutput = true, + UseShellExecute = false, + CreateNoWindow = true, + WorkingDirectory = testAppPath, + }, + }; - var expectedOutput = new System.Text.StringBuilder(); - process.OutputDataReceived += (sender, e) => + var expectedOutput = new System.Text.StringBuilder(); + process.OutputDataReceived += (sender, e) => + { + if (!string.IsNullOrEmpty(e.Data)) { - if (!string.IsNullOrEmpty(e.Data)) - { - this.testOutputHelper.WriteLine(e.Data); - expectedOutput.AppendLine(e.Data); - } - }; + this.testOutputHelper.WriteLine(e.Data); + expectedOutput.AppendLine(e.Data); + } + }; - process.Start(); - process.BeginOutputReadLine(); + process.Start(); + process.BeginOutputReadLine(); - Assert.True(process.WaitForExit(milliseconds: 240_000), "dotnet publish command timed out after 240 seconds."); - Assert.True(process.ExitCode == 0, "Publishing the AotCompatibility app failed. See test output for more details."); + Assert.True(process.WaitForExit(milliseconds: 240_000), "dotnet publish command timed out after 240 seconds."); + Assert.True(process.ExitCode == 0, "Publishing the AotCompatibility app failed. See test output for more details."); - var warnings = expectedOutput.ToString().Split('\n', '\r').Where(line => line.Contains("warning IL")); - Assert.Equal(30, warnings.Count()); - } + var warnings = expectedOutput.ToString().Split('\n', '\r').Where(line => line.Contains("warning IL")); + Assert.Equal(30, warnings.Count()); } }