From 494642e84409a8bc5d4b2ec58b4d8480b259f08a Mon Sep 17 00:00:00 2001
From: skwasjer <11424653+skwasjer@users.noreply.github.com>
Date: Sat, 18 Nov 2023 11:24:14 +0100
Subject: [PATCH 1/5] fix(CS8604): in older runtimes, IEqualityComparer<> did
not use nullable annotation. Fix with string polyfill for Arg.Any.
---
test/MockHttp.Json.Tests/ArgAny.cs | 13 +++++++++++++
.../JsonContentMatcherTests.cs | 15 ++++++++-------
2 files changed, 21 insertions(+), 7 deletions(-)
create mode 100644 test/MockHttp.Json.Tests/ArgAny.cs
diff --git a/test/MockHttp.Json.Tests/ArgAny.cs b/test/MockHttp.Json.Tests/ArgAny.cs
new file mode 100644
index 00000000..9d693007
--- /dev/null
+++ b/test/MockHttp.Json.Tests/ArgAny.cs
@@ -0,0 +1,13 @@
+namespace MockHttp.Json;
+
+///
+/// To deal with runtime API differences around mocking with nullable.
+///
+internal static class ArgAny
+{
+#if NETCOREAPP3_1_OR_GREATER
+ public static ref string? String() => ref Arg.Any();
+#else
+ public static ref string String() => ref Arg.Any();
+#endif
+}
diff --git a/test/MockHttp.Json.Tests/JsonContentMatcherTests.cs b/test/MockHttp.Json.Tests/JsonContentMatcherTests.cs
index dc1ba740..25fb1c7f 100644
--- a/test/MockHttp.Json.Tests/JsonContentMatcherTests.cs
+++ b/test/MockHttp.Json.Tests/JsonContentMatcherTests.cs
@@ -16,7 +16,7 @@ public JsonContentMatcherTests()
_equalityComparerMock = Substitute.For>();
_equalityComparerMock
- .Equals(Arg.Any(), Arg.Any())
+ .Equals(ArgAny.String(), ArgAny.String())
.Returns(true);
_requestMessage = new HttpRequestMessage();
@@ -43,7 +43,7 @@ public async Task Given_that_adapter_is_provided_to_ctor_when_matching_it_should
// Assert
_adapterMock.Received(1).Serialize(jsonContentAsObject);
globalAdapterMock.DidNotReceiveWithAnyArgs().Serialize(Arg.Any