diff --git a/.github/workflows/pr_validation.yml b/.github/workflows/pr_validation.yml
index a076163..fe7e5ba 100644
--- a/.github/workflows/pr_validation.yml
+++ b/.github/workflows/pr_validation.yml
@@ -30,7 +30,7 @@ jobs:
windows-latest:
name: windows-latest
runs-on: windows-latest
-
+
steps:
- name: "Checkout"
uses: actions/checkout@v4.1.1
@@ -57,11 +57,11 @@ jobs:
- name: "dotnet pack"
run: dotnet pack -c Release -o ./bin/nuget
-
+
ubuntu-latest:
name: ubuntu-latest
runs-on: ubuntu-latest
-
+
steps:
- name: "Checkout"
uses: actions/checkout@v4.1.1
@@ -81,11 +81,11 @@ jobs:
- name: "dotnet build"
run: dotnet build -c Release
-
+
# .NET Framework tests can't run reliably on Linux, so we only do .NET Core
- name: "dotnet test"
shell: bash
- run: dotnet test -c Release -f net6.0
+ run: dotnet test -c Release -f net8.0
- name: "dotnet pack"
run: dotnet pack -c Release -o ./bin/nuget
diff --git a/Directory.Build.props b/Directory.Build.props
index 73f726e..9da0f90 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -6,29 +6,23 @@
TestKit for writing tests for Akka.NET using NUnit.
akka;actors;actor model;Akka;concurrency;testkit;nunit
true
- akka.png
-
+ akka.png
https://github.com/AkkaNetContrib/Akka.TestKit.Nunit
Apache-2.0
- README.md
-
+ README.md
$(NoWarn);CS1591
- 10.0
- true
-
- $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb
-
- true
-
- true
-
+ 13.0
+ true
+ $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb
+ true
+ true
- 1.5.32
+ 1.5.33
17.12.0
3.14.0
- 4.2.2
- 4.4.0
+ 4.3.2
+ 4.5.0
4.6.0
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index 8fc8e45..9cb198e 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -1,3 +1,9 @@
+#### 1.5.33 January 4th 2025 ####
+- Safer formatting of assertion messages
+- Bump `NUnit` to [4.3.2](https://github.com/nunit/nunit/releases/tag/4.3.2)
+- Bump `NUnit.Analyzers` to [4.5.0](https://github.com/nunit/nunit.analyzers/releases/tag/4.5.0)
+- Bump `Akka.TestKit` to [1.5.33](https://github.com/akkadotnet/akka.net/releases/tag/1.5.33)
+
#### 1.5.32 December 20th 2024 ####
- Bump `Akka.TestKit` to [1.5.32](https://github.com/akkadotnet/akka.net/releases/tag/1.5.32)
- Bump `NUnit3TestAdapter` to [4.6.0](https://github.com/nunit/nunit3-vs-adapter/releases/tag/V4.6.0)
diff --git a/global.json b/global.json
index 5a6332b..051cdec 100644
--- a/global.json
+++ b/global.json
@@ -1,6 +1,6 @@
{
"sdk": {
"rollForward": "latestFeature",
- "version": "6.0.428"
+ "version": "9.0.101"
}
}
\ No newline at end of file
diff --git a/src/Akka.TestKit.NUnit.Tests/Akka.TestKit.NUnit.Tests.csproj b/src/Akka.TestKit.NUnit.Tests/Akka.TestKit.NUnit.Tests.csproj
index d760cfb..840826f 100644
--- a/src/Akka.TestKit.NUnit.Tests/Akka.TestKit.NUnit.Tests.csproj
+++ b/src/Akka.TestKit.NUnit.Tests/Akka.TestKit.NUnit.Tests.csproj
@@ -1,6 +1,6 @@
- net6.0;net462
+ net8.0;net462
diff --git a/src/Akka.TestKit.NUnit.Tests/AssertionsTests.cs b/src/Akka.TestKit.NUnit.Tests/AssertionsTests.cs
index 04645c9..0d1a187 100644
--- a/src/Akka.TestKit.NUnit.Tests/AssertionsTests.cs
+++ b/src/Akka.TestKit.NUnit.Tests/AssertionsTests.cs
@@ -12,12 +12,7 @@ namespace Akka.TestKit.NUnit.Tests
[Parallelizable(ParallelScope.All)]
public class AssertionsTests : TestKit
{
- private readonly NUnitAssertions _assertions;
-
- public AssertionsTests()
- {
- _assertions = new NUnitAssertions();
- }
+ private readonly NUnitAssertions _assertions = new();
[Test]
public void Fail_should_throw()
@@ -72,5 +67,30 @@ public void AssertEqualWithComparer_should_succeed_on_equal()
{
_assertions.AssertEqual(42, 4711, (x, y) => true);
}
+
+ [Test]
+ public void Assert_should_not_format_message_when_no_arguments_are_specified()
+ {
+ const string testMessage = "{Value} with different format placeholders {0}";
+
+ Assert.Multiple(() =>
+ {
+ Assert.That(
+ code: () => _assertions.Fail(testMessage),
+ constraint: Throws.Exception.TypeOf().And.Message.Contains(testMessage));
+ Assert.That(
+ code: () => _assertions.AssertTrue(false, testMessage),
+ constraint: Throws.Exception.TypeOf().And.Message.Contains(testMessage));
+ Assert.That(
+ code: () => _assertions.AssertFalse(true, testMessage),
+ constraint: Throws.Exception.TypeOf().And.Message.Contains(testMessage));
+ Assert.That(
+ code: () => _assertions.AssertEqual(4, 2, testMessage),
+ constraint: Throws.Exception.TypeOf().And.Message.Contains(testMessage));
+ Assert.That(
+ code: () => _assertions.AssertEqual(4, 2, (_, _) => false, testMessage),
+ constraint: Throws.Exception.TypeOf().And.Message.Contains(testMessage));
+ });
+ }
}
}
diff --git a/src/Akka.TestKit.NUnit/NUnitAssertions.cs b/src/Akka.TestKit.NUnit/NUnitAssertions.cs
index a730e24..77568f5 100644
--- a/src/Akka.TestKit.NUnit/NUnitAssertions.cs
+++ b/src/Akka.TestKit.NUnit/NUnitAssertions.cs
@@ -15,30 +15,40 @@ namespace Akka.TestKit.NUnit
///
public class NUnitAssertions : ITestKitAssertions
{
-
public void Fail(string format = "", params object[] args)
{
- Assert.Fail(string.Format(format, args));
+ Assert.Fail(NUnitAssertBase.ConvertMessageWithArgs(format, args));
}
public void AssertTrue(bool condition, string format = "", params object[] args)
{
- Assert.That(condition, Is.True, string.Format(format, args));
+ Assert.That(condition, Is.True, NUnitAssertBase.ConvertMessageWithArgs(format, args));
}
public void AssertFalse(bool condition, string format = "", params object[] args)
{
- Assert.That(condition, Is.False, string.Format(format, args));
+ Assert.That(condition, Is.False, NUnitAssertBase.ConvertMessageWithArgs(format, args));
}
public void AssertEqual(T expected, T actual, string format = "", params object[] args)
{
- Assert.That(actual, Is.EqualTo(expected), string.Format(format, args));
+ Assert.That(actual, Is.EqualTo(expected), NUnitAssertBase.ConvertMessageWithArgs(format, args));
}
public void AssertEqual(T expected, T actual, Func comparer, string format = "", params object[] args)
{
- Assert.That(actual, Is.EqualTo(expected).Using(comparer), string.Format(format, args));
+ Assert.That(actual, Is.EqualTo(expected).Using(comparer), NUnitAssertBase.ConvertMessageWithArgs(format, args));
+ }
+
+ ///
+ /// This class only exists to allow us to call NUnit.Framework.AssertBase.ConvertMessageWithArgs.
+ /// As of NUnit 4.3.1, this method is declared protected and thus cannot be called directly.
+ /// See https://github.com/nunit/nunit/blob/4.3.1/src/NUnitFramework/framework/AssertBase.cs#L10-L14.
+ ///
+ private sealed class NUnitAssertBase : AssertBase
+ {
+ public new static string ConvertMessageWithArgs(string message, object[] args) =>
+ AssertBase.ConvertMessageWithArgs(message, args);
}
}
}