diff --git a/.editorconfig b/.editorconfig index 36b8f56c8..f6415fa8b 100644 --- a/.editorconfig +++ b/.editorconfig @@ -256,6 +256,9 @@ dotnet_diagnostic.CA1816.severity = none # CA1859: Use concrete types when possible for improved performance dotnet_diagnostic.CA1859.severity = none + +# xUnit1051: Calls to methods which accept CancellationToken should use TestContext.Current.CancellationToken +dotnet_diagnostic.xUnit1051.severity = none [*.{cs,vb}] dotnet_style_operator_placement_when_wrapping = beginning_of_line diff --git a/src/SuperSocket.Primitives/CertificateOptions.cs b/src/SuperSocket.Primitives/CertificateOptions.cs index 46de17ead..0301c2c6d 100644 --- a/src/SuperSocket.Primitives/CertificateOptions.cs +++ b/src/SuperSocket.Primitives/CertificateOptions.cs @@ -57,7 +57,12 @@ public X509Certificate GetCertificate() filePath = Path.Combine(AppContext.BaseDirectory, filePath); } +#if NET9_0_OR_GREATER + return X509CertificateLoader.LoadPkcs12FromFile(filePath, Password, KeyStorageFlags); +#else return new X509Certificate2(filePath, Password, KeyStorageFlags); +#endif + } else if (!string.IsNullOrEmpty(Thumbprint)) // Load certificate from certificate store { diff --git a/test/SuperSocket.Benchmarks/SuperSocket.Benchmarks.csproj b/test/SuperSocket.Benchmarks/SuperSocket.Benchmarks.csproj index 31e8a416b..9e5495cb5 100644 --- a/test/SuperSocket.Benchmarks/SuperSocket.Benchmarks.csproj +++ b/test/SuperSocket.Benchmarks/SuperSocket.Benchmarks.csproj @@ -1,7 +1,7 @@ Exe - net7.0 + net9.0 false SuperSocket benchmarking project for performance testing and analysis of core components using BenchmarkDotNet. diff --git a/test/SuperSocket.Tests/ClientTest.cs b/test/SuperSocket.Tests/ClientTest.cs index 72992a77c..c1a4f4900 100644 --- a/test/SuperSocket.Tests/ClientTest.cs +++ b/test/SuperSocket.Tests/ClientTest.cs @@ -164,7 +164,7 @@ public async Task TestBindLocalEndPoint(Type hostConfiguratorType) if (e.SocketErrorCode == SocketError.AccessDenied || e.SocketErrorCode == SocketError.AddressAlreadyInUse) continue; - throw e; + throw; } break; diff --git a/test/SuperSocket.Tests/CommandTest.cs b/test/SuperSocket.Tests/CommandTest.cs index abb4388b9..97d471d38 100644 --- a/test/SuperSocket.Tests/CommandTest.cs +++ b/test/SuperSocket.Tests/CommandTest.cs @@ -101,7 +101,7 @@ public async Task TestUnknownCommands(Type hostConfiguratorType) commandOptions.AddCommand(); commandOptions.RegisterUnknownPackageHandler(async (session, package, cancellationToken) => { - await session.SendAsync(Encoding.UTF8.GetBytes("X\r\n")); + await session.SendAsync(Encoding.UTF8.GetBytes("X\r\n"), cancellationToken); }); // register all commands in one assembly @@ -384,7 +384,7 @@ public COUNT(IPackageEncoder encoder) public async ValueTask ExecuteAsync(IAppSession session, StringPackageInfo package, CancellationToken cancellationToken) { - await session.SendAsync(_encoder, "OK\r\n"); + await session.SendAsync(_encoder, "OK\r\n", cancellationToken); } } @@ -400,7 +400,7 @@ public COUNTDOWN(IPackageEncoder encoder) public async ValueTask ExecuteAsync(IAppSession session, StringPackageInfo package, CancellationToken cancellationToken) { - await session.SendAsync(_encoder, "OK\r\n"); + await session.SendAsync(_encoder, "OK\r\n", cancellationToken); } } diff --git a/test/SuperSocket.Tests/Commands.cs b/test/SuperSocket.Tests/Commands.cs index 73407b46a..1554ff2b7 100644 --- a/test/SuperSocket.Tests/Commands.cs +++ b/test/SuperSocket.Tests/Commands.cs @@ -26,7 +26,7 @@ public async ValueTask ExecuteAsync(IAppSession session, StringPackageInfo packa .Select(p => int.Parse(p)) .Sum(); - await session.SendAsync(Encoding.UTF8.GetBytes(result.ToString() + "\r\n")); + await session.SendAsync(Encoding.UTF8.GetBytes(result.ToString() + "\r\n"), cancellationToken); } } @@ -38,7 +38,7 @@ public async ValueTask ExecuteAsync(IAppSession session, StringPackageInfo packa .Select(p => int.Parse(p)) .Aggregate((x, y) => x * y); - await session.SendAsync(Encoding.UTF8.GetBytes(result.ToString() + "\r\n")); + await session.SendAsync(Encoding.UTF8.GetBytes(result.ToString() + "\r\n"), cancellationToken); } } @@ -58,7 +58,7 @@ public async ValueTask ExecuteAsync(IAppSession session, StringPackageInfo packa .Aggregate((x, y) => x - y); // encode the text message by encoder - await session.SendAsync(_encoder, result.ToString() + "\r\n"); + await session.SendAsync(_encoder, result.ToString() + "\r\n", cancellationToken); } } diff --git a/test/SuperSocket.Tests/MainTest.cs b/test/SuperSocket.Tests/MainTest.cs index 179e8999c..fb3f9956f 100644 --- a/test/SuperSocket.Tests/MainTest.cs +++ b/test/SuperSocket.Tests/MainTest.cs @@ -23,13 +23,12 @@ using SuperSocket.Server.Host; using Xunit; -/// -/// Run selected test case by command -/// dotnet test --filter 'FullyQualifiedName=SuperSocket.Tests.SessionTest.TestCloseReason' -/// - namespace SuperSocket.Tests { + /// + /// Run selected test case by command + /// dotnet test --filter 'FullyQualifiedName=SuperSocket.Tests.SessionTest.TestCloseReason' + /// [Trait("Category", "Basic")] public class MainTest : TestClassBase { @@ -800,8 +799,6 @@ public async Task TestMultipleServerHostWithConfigureServerOptions() var server1 = default(IServer); var server2 = default(IServer); - IHostEnvironment actualHostEvn = null; - var hostBuilder = MultipleServerHostBuilder.Create() .AddServer(builder => { diff --git a/test/SuperSocket.Tests/PackageHandlingContextAccessorTest.cs b/test/SuperSocket.Tests/PackageHandlingContextAccessorTest.cs index 1e01d5752..efa5b62f1 100644 --- a/test/SuperSocket.Tests/PackageHandlingContextAccessorTest.cs +++ b/test/SuperSocket.Tests/PackageHandlingContextAccessorTest.cs @@ -92,7 +92,7 @@ public async ValueTask ExecuteAsync(IAppSession session, StringPackageInfo packa Assert.Equal(packageHandlingContextAccessor.PackageHandlingContext.AppSession, session); Assert.Equal(packageHandlingContextAccessor.PackageHandlingContext.PackageInfo, package); - await session.SendAsync(Encoding.UTF8.GetBytes(package.Body + "\r\n")); + await session.SendAsync(Encoding.UTF8.GetBytes(package.Body + "\r\n"), cancellationToken); } } } diff --git a/test/SuperSocket.Tests/SessionContainerTest.cs b/test/SuperSocket.Tests/SessionContainerTest.cs index d3ca14ba8..b5f2fe5af 100644 --- a/test/SuperSocket.Tests/SessionContainerTest.cs +++ b/test/SuperSocket.Tests/SessionContainerTest.cs @@ -24,7 +24,7 @@ class SESS : IAsyncCommand { public async ValueTask ExecuteAsync(IAppSession session, StringPackageInfo package, CancellationToken cancellationToken) { - await session.SendAsync(Encoding.UTF8.GetBytes(session.SessionID + "\r\n")); + await session.SendAsync(Encoding.UTF8.GetBytes(session.SessionID + "\r\n"), cancellationToken); } } diff --git a/test/SuperSocket.Tests/WebSocket/WebSocketBasicTest.cs b/test/SuperSocket.Tests/WebSocket/WebSocketBasicTest.cs index 314c6d7cf..ba87ac17f 100644 --- a/test/SuperSocket.Tests/WebSocket/WebSocketBasicTest.cs +++ b/test/SuperSocket.Tests/WebSocket/WebSocketBasicTest.cs @@ -310,7 +310,7 @@ public async Task TestEmptyMessage(Type hostConfiguratorType) Assert.Equal(WebSocketState.Open, websocket.State); - var data = new byte[0]; + var data = Array.Empty(); var segment = new ArraySegment(data, 0, data.Length); await websocket.SendAsync(segment, WebSocketMessageType.Text, true, CancellationToken.None); @@ -1206,7 +1206,7 @@ public async ValueTask ExecuteAsync(WebSocketSession session, StringPackageInfo .Select(p => int.Parse(p)) .Sum(); - await session.SendAsync(result.ToString()); + await session.SendAsync(result.ToString(), cancellationToken); } } @@ -1218,7 +1218,7 @@ public async ValueTask ExecuteAsync(WebSocketSession session, StringPackageInfo .Select(p => int.Parse(p)) .Aggregate((x, y) => x * y); - await session.SendAsync(result.ToString()); + await session.SendAsync(result.ToString(), cancellationToken); } } @@ -1230,7 +1230,7 @@ public async ValueTask ExecuteAsync(WebSocketSession session, StringPackageInfo .Select(p => int.Parse(p)) .Aggregate((x, y) => x - y); - await session.SendAsync(result.ToString()); + await session.SendAsync(result.ToString(), cancellationToken); } }