diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 9cdb147..44811b5 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -5,10 +5,26 @@ on:
pull_request:
branches:
- master
+ workflow_call:
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..373f2d0 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -3,7 +3,10 @@ on:
tags:
- "*"
jobs:
+ test:
+ uses: ./.github/workflows/ci.yml
build:
+ needs: test
runs-on: ubuntu-latest
permissions:
id-token: write
@@ -24,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 .
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..bb94618 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
{
@@ -17,9 +17,11 @@ 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;
- [Fact]
+ [Test]
public async Task CanSendAndReceivePayloads_WithServiceBroker()
{
await CreateDatabaseAsync();
@@ -35,7 +37,7 @@ public async Task CanSendAndReceivePayloads_WithServiceBroker()
await RunCore(options, prefix);
}
- [Fact]
+ [Test]
public async Task CanSendAndReceivePayloads_WithPolling()
{
await CreateDatabaseAsync();
@@ -51,7 +53,7 @@ public async Task CanSendAndReceivePayloads_WithPolling()
}
- [Fact]
+ [Test]
public async Task CanSendAndReceivePayloads_WithServiceBroker_UnderHeavyLoad()
{
await CreateDatabaseAsync();
@@ -75,7 +77,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 +104,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 +132,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 +166,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