From db2978281b5aadfccd500932b87642060c614d44 Mon Sep 17 00:00:00 2001 From: Andrew Scott Date: Fri, 20 Nov 2026 16:44:21 -0800 Subject: [PATCH 1/3] Migrate tests from xUnit v3 to TUnit Converted with TUnit's TUXU0001 code fixer plus manual fixes. global.json opts dotnet test into Microsoft.Testing.Platform, which TUnit requires. --- IntelliTect.AspNetCore.SignalR.SqlServer.slnx | 1 + global.json | 5 ++ ....AspNetCore.SignalR.SqlServer.Tests.csproj | 11 +--- .../SqlServerEndToEndTests.cs | 26 ++++---- .../SqlServerProtocolTests.cs | 63 ++++++++++--------- 5 files changed, 52 insertions(+), 54 deletions(-) create mode 100644 global.json diff --git a/IntelliTect.AspNetCore.SignalR.SqlServer.slnx b/IntelliTect.AspNetCore.SignalR.SqlServer.slnx index 1aa2ced..16288bb 100644 --- a/IntelliTect.AspNetCore.SignalR.SqlServer.slnx +++ b/IntelliTect.AspNetCore.SignalR.SqlServer.slnx @@ -8,6 +8,7 @@ + diff --git a/global.json b/global.json new file mode 100644 index 0000000..3140116 --- /dev/null +++ b/global.json @@ -0,0 +1,5 @@ +{ + "test": { + "runner": "Microsoft.Testing.Platform" + } +} diff --git a/test/IntelliTect.AspNetCore.SignalR.SqlServer.Tests/IntelliTect.AspNetCore.SignalR.SqlServer.Tests.csproj b/test/IntelliTect.AspNetCore.SignalR.SqlServer.Tests/IntelliTect.AspNetCore.SignalR.SqlServer.Tests.csproj index 4666a16..61d0390 100644 --- a/test/IntelliTect.AspNetCore.SignalR.SqlServer.Tests/IntelliTect.AspNetCore.SignalR.SqlServer.Tests.csproj +++ b/test/IntelliTect.AspNetCore.SignalR.SqlServer.Tests/IntelliTect.AspNetCore.SignalR.SqlServer.Tests.csproj @@ -8,16 +8,7 @@ - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - + diff --git a/test/IntelliTect.AspNetCore.SignalR.SqlServer.Tests/SqlServerEndToEndTests.cs b/test/IntelliTect.AspNetCore.SignalR.SqlServer.Tests/SqlServerEndToEndTests.cs index ff4ba0f..a403ef4 100644 --- a/test/IntelliTect.AspNetCore.SignalR.SqlServer.Tests/SqlServerEndToEndTests.cs +++ b/test/IntelliTect.AspNetCore.SignalR.SqlServer.Tests/SqlServerEndToEndTests.cs @@ -2,13 +2,13 @@ using Microsoft.Data.SqlClient; using Microsoft.Extensions.Logging.Abstractions; using System; +using TUnit.Assertions.Enums; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; -using Xunit; namespace IntelliTect.AspNetCore.SignalR.SqlServer.Tests { @@ -19,7 +19,7 @@ public class SqlServerEndToEndTests private static readonly string connectionString = "Server=localhost;Database=" + databaseName + ";Trusted_Connection=True;Timeout=5;TrustServerCertificate=True"; - [Fact] + [Test] public async Task CanSendAndReceivePayloads_WithServiceBroker() { await CreateDatabaseAsync(); @@ -35,7 +35,7 @@ public async Task CanSendAndReceivePayloads_WithServiceBroker() await RunCore(options, prefix); } - [Fact] + [Test] public async Task CanSendAndReceivePayloads_WithPolling() { await CreateDatabaseAsync(); @@ -51,7 +51,7 @@ public async Task CanSendAndReceivePayloads_WithPolling() } - [Fact] + [Test] public async Task CanSendAndReceivePayloads_WithServiceBroker_UnderHeavyLoad() { await CreateDatabaseAsync(); @@ -75,7 +75,7 @@ public async Task CanSendAndReceivePayloads_WithServiceBroker_UnderHeavyLoad() return Task.CompletedTask; }); // Give the receiver time to reach a steady state (waiting). - await Task.Delay(150, TestContext.Current.CancellationToken); + await Task.Delay(150, TestContext.Current!.Execution.CancellationToken); var cts = new CancellationTokenSource(); @@ -102,13 +102,13 @@ public async Task CanSendAndReceivePayloads_WithServiceBroker_UnderHeavyLoad() var payload = new byte[255]; new Random().NextBytes(payload); - await Task.Delay(10000, TestContext.Current.CancellationToken); + await Task.Delay(10000, TestContext.Current!.Execution.CancellationToken); cts.Cancel(); // Give the receiver time to reach a steady state (waiting). - await Task.Delay(1000, TestContext.Current.CancellationToken); + await Task.Delay(1000, TestContext.Current!.Execution.CancellationToken); - Assert.Equal(numSent, receivedMessages.Count); + await Assert.That(receivedMessages.Count).IsEqualTo(numSent); receiver.Dispose(); await receiverTask; @@ -130,18 +130,18 @@ private async Task RunCore(SqlServerOptions options, string prefix) return Task.CompletedTask; }); // Give the receiver time to reach a steady state (waiting). - await Task.Delay(150, TestContext.Current.CancellationToken); + await Task.Delay(150, TestContext.Current!.Execution.CancellationToken); var payload = new byte[255]; new Random().NextBytes(payload); await sender.Send(payload); await receivedEvent.WaitAsync(); - var message = Assert.Single(receivedMessages); - Assert.Equal(payload, message); + var message = await Assert.That(receivedMessages).HasSingleItem(); + await Assert.That(message).IsEquivalentTo(payload, CollectionOrdering.Matching); // Give the receiver time to reach a steady state (waiting). - await Task.Delay(50, TestContext.Current.CancellationToken); + await Task.Delay(50, TestContext.Current!.Execution.CancellationToken); receiver.Dispose(); await receiverTask; @@ -164,7 +164,7 @@ private static async Task CreateDatabaseAsync() || ex.Message.Contains("The server was not found or was not accessible") ) { - Assert.Skip(ex.Message); + Skip.Test(ex.Message); } } } diff --git a/test/IntelliTect.AspNetCore.SignalR.SqlServer.Tests/SqlServerProtocolTests.cs b/test/IntelliTect.AspNetCore.SignalR.SqlServer.Tests/SqlServerProtocolTests.cs index f518d98..429eade 100644 --- a/test/IntelliTect.AspNetCore.SignalR.SqlServer.Tests/SqlServerProtocolTests.cs +++ b/test/IntelliTect.AspNetCore.SignalR.SqlServer.Tests/SqlServerProtocolTests.cs @@ -5,71 +5,72 @@ using Microsoft.AspNetCore.SignalR.Protocol; using Microsoft.Extensions.Logging.Abstractions; using System; +using TUnit.Assertions.Enums; using System.Buffers; using System.Collections.Generic; using System.Linq; -using Xunit; +using System.Threading.Tasks; namespace IntelliTect.AspNetCore.SignalR.SqlServer.Tests { public class SqlServerProtocolTests { - [Fact] - public void InvocationAllRoundTrips() + [Test] + public async Task InvocationAllRoundTrips() { var sut = new SqlServerProtocol(CreateHubMessageSerializer()); var encoded = sut.WriteInvocationAll("Method", new object[] { "s" }, new[] { "excluded" }); var decoded = sut.ReadInvocationAll(encoded); - var decodedMessage = ParseMessage(decoded.Message); + var decodedMessage = await ParseMessage(decoded.Message); - Assert.Equal(MessageType.InvocationAll, sut.ReadMessageType(encoded)); - Assert.Equal(new[] { "excluded" }, decoded.ExcludedConnectionIds); - Assert.Equal("Method", decodedMessage.Target); - Assert.Equal("s", decodedMessage.Arguments.Single()); + await Assert.That(sut.ReadMessageType(encoded)).IsEqualTo(MessageType.InvocationAll); + await Assert.That(decoded.ExcludedConnectionIds).IsEquivalentTo(new[] { "excluded" }, CollectionOrdering.Matching); + await Assert.That(decodedMessage.Target).IsEqualTo("Method"); + await Assert.That(decodedMessage.Arguments.Single()).IsEqualTo("s"); } - [Theory] - [InlineData(MessageType.InvocationConnection)] - [InlineData(MessageType.InvocationGroup)] - [InlineData(MessageType.InvocationUser)] - internal void TargetedInvocationRoundTrips(MessageType type) + [Test] + [Arguments(MessageType.InvocationConnection)] + [Arguments(MessageType.InvocationGroup)] + [Arguments(MessageType.InvocationUser)] + internal async Task TargetedInvocationRoundTrips(MessageType type) { var sut = new SqlServerProtocol(CreateHubMessageSerializer()); var encoded = sut.WriteTargetedInvocation(type, "target", "Method", new object[] { "s" }, new[] { "excluded" }); var decoded = sut.ReadTargetedInvocation(encoded); - var decodedMessage = ParseMessage(decoded.Invocation.Message); + var decodedMessage = await ParseMessage(decoded.Invocation.Message); - Assert.Equal(type, sut.ReadMessageType(encoded)); - Assert.Equal(new[] { "excluded" }, decoded.Invocation.ExcludedConnectionIds); - Assert.Equal("target", decoded.Target); - Assert.Equal("Method", decodedMessage.Target); - Assert.Equal("s", decodedMessage.Arguments.Single()); + await Assert.That(sut.ReadMessageType(encoded)).IsEqualTo(type); + await Assert.That(decoded.Invocation.ExcludedConnectionIds).IsEquivalentTo(new[] { "excluded" }, CollectionOrdering.Matching); + await Assert.That(decoded.Target).IsEqualTo("target"); + await Assert.That(decodedMessage.Target).IsEqualTo("Method"); + await Assert.That(decodedMessage.Arguments.Single()).IsEqualTo("s"); } - [Fact] - internal void AckRoundTrips() + [Test] + internal async Task AckRoundTrips() { var sut = new SqlServerProtocol(CreateHubMessageSerializer()); var encoded = sut.WriteAck(42, "server1"); var decoded = sut.ReadAck(encoded); - Assert.Equal(MessageType.Ack, sut.ReadMessageType(encoded)); - Assert.Equal(42, decoded.Id); - Assert.Equal("server1", decoded.ServerName); + await Assert.That(sut.ReadMessageType(encoded)).IsEqualTo(MessageType.Ack); + await Assert.That(decoded.Id).IsEqualTo(42); + await Assert.That(decoded.ServerName).IsEqualTo("server1"); } - [Fact] - internal void GroupRoundTrips() + [Test] + internal async Task GroupRoundTrips() { var sut = new SqlServerProtocol(CreateHubMessageSerializer()); var command = new SqlServerGroupCommand(42, "server1", GroupAction.Add, "groupName", "connection"); var encoded = sut.WriteGroupCommand(command); var decoded = sut.ReadGroupCommand(encoded); - Assert.Equal(MessageType.Group, sut.ReadMessageType(encoded)); - Assert.Equal(command, decoded); + await Assert.That(sut.ReadMessageType(encoded)).IsEqualTo(MessageType.Group); + await Assert.That(decoded).IsEqualTo(command); } private DefaultHubMessageSerializer CreateHubMessageSerializer() @@ -81,12 +82,12 @@ private DefaultHubMessageSerializer CreateHubMessageSerializer() } - private InvocationMessage ParseMessage(SerializedHubMessage serialized) + private async Task ParseMessage(SerializedHubMessage serialized) { var protocol = new MessagePackHubProtocol(); var decodedMessage = new ReadOnlySequence(serialized.GetSerializedMessage(protocol)); - Assert.True(protocol.TryParseMessage(ref decodedMessage, new DefaultInvocationBinder(), out var message)); - return Assert.IsType(message); + await Assert.That(protocol.TryParseMessage(ref decodedMessage, new DefaultInvocationBinder(), out var message)).IsTrue(); + return (await Assert.That(message).IsTypeOf())!; } private class HubProtocolResolver : IHubProtocolResolver From e8d58abd04d29b012883570c14bf5c5e85f5e649 Mon Sep 17 00:00:00 2001 From: Andrew Scott Date: Fri, 20 Nov 2026 16:48:26 -0800 Subject: [PATCH 2/3] Run end-to-end tests against a SQL Server service container in CI --- .github/workflows/ci.yml | 15 +++++++++++++++ .github/workflows/release.yml | 15 +++++++++++++++ .../SqlServerEndToEndTests.cs | 4 +++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9cdb147..83de891 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,6 +9,21 @@ jobs: build: runs-on: ubuntu-latest timeout-minutes: 15 + services: + sqlserver: + image: mcr.microsoft.com/mssql/server:2022-latest + env: + ACCEPT_EULA: "Y" + MSSQL_SA_PASSWORD: Test_Passw0rd! + ports: + - 1433:1433 + options: >- + --health-cmd "/opt/mssql-tools18/bin/sqlcmd -C -S localhost -U sa -P 'Test_Passw0rd!' -Q 'SELECT 1'" + --health-interval 10s + --health-timeout 5s + --health-retries 10 + env: + SIGNALR_TESTS_SQLSERVER: Server=localhost;User Id=sa;Password=Test_Passw0rd!;TrustServerCertificate=True steps: - name: Checkout uses: actions/checkout@v7 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d444980..f748537 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -8,6 +8,21 @@ jobs: permissions: id-token: write contents: write + services: + sqlserver: + image: mcr.microsoft.com/mssql/server:2022-latest + env: + ACCEPT_EULA: "Y" + MSSQL_SA_PASSWORD: Test_Passw0rd! + ports: + - 1433:1433 + options: >- + --health-cmd "/opt/mssql-tools18/bin/sqlcmd -C -S localhost -U sa -P 'Test_Passw0rd!' -Q 'SELECT 1'" + --health-interval 10s + --health-timeout 5s + --health-retries 10 + env: + SIGNALR_TESTS_SQLSERVER: Server=localhost;User Id=sa;Password=Test_Passw0rd!;TrustServerCertificate=True steps: - name: Checkout uses: actions/checkout@v7 diff --git a/test/IntelliTect.AspNetCore.SignalR.SqlServer.Tests/SqlServerEndToEndTests.cs b/test/IntelliTect.AspNetCore.SignalR.SqlServer.Tests/SqlServerEndToEndTests.cs index a403ef4..bb94618 100644 --- a/test/IntelliTect.AspNetCore.SignalR.SqlServer.Tests/SqlServerEndToEndTests.cs +++ b/test/IntelliTect.AspNetCore.SignalR.SqlServer.Tests/SqlServerEndToEndTests.cs @@ -17,7 +17,9 @@ public class SqlServerEndToEndTests // Per-runtime database: each target framework's test run executes in parallel. private static readonly string databaseName = "SignalRUnitTestsDb_net" + Environment.Version.Major; private static readonly string connectionString = - "Server=localhost;Database=" + databaseName + ";Trusted_Connection=True;Timeout=5;TrustServerCertificate=True"; + (Environment.GetEnvironmentVariable("SIGNALR_TESTS_SQLSERVER") + ?? "Server=localhost;Trusted_Connection=True;Timeout=5;TrustServerCertificate=True") + + ";Database=" + databaseName; [Test] public async Task CanSendAndReceivePayloads_WithServiceBroker() From 76bdd71f518ee2b2623aacbebdc3fd54955425d8 Mon Sep 17 00:00:00 2001 From: Andrew Scott Date: Fri, 20 Nov 2026 16:55:17 -0800 Subject: [PATCH 3/3] Reuse the CI workflow for release tests --- .github/workflows/ci.yml | 1 + .github/workflows/release.yml | 20 +++----------------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 83de891..44811b5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,6 +5,7 @@ on: pull_request: branches: - master + workflow_call: jobs: build: runs-on: ubuntu-latest diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f748537..373f2d0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,26 +3,14 @@ on: tags: - "*" jobs: + test: + uses: ./.github/workflows/ci.yml build: + needs: test runs-on: ubuntu-latest permissions: id-token: write contents: write - services: - sqlserver: - image: mcr.microsoft.com/mssql/server:2022-latest - env: - ACCEPT_EULA: "Y" - MSSQL_SA_PASSWORD: Test_Passw0rd! - ports: - - 1433:1433 - options: >- - --health-cmd "/opt/mssql-tools18/bin/sqlcmd -C -S localhost -U sa -P 'Test_Passw0rd!' -Q 'SELECT 1'" - --health-interval 10s - --health-timeout 5s - --health-retries 10 - env: - SIGNALR_TESTS_SQLSERVER: Server=localhost;User Id=sa;Password=Test_Passw0rd!;TrustServerCertificate=True steps: - name: Checkout uses: actions/checkout@v7 @@ -39,8 +27,6 @@ jobs: run: echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV - name: Build run: dotnet build --configuration Release /p:Version=${VERSION} - - name: Test - run: dotnet test --configuration Release /p:Version=${VERSION} --no-build - name: Pack run: dotnet pack --configuration Release /p:Version=${VERSION} --no-build --output .