From 6b0e3114d805cf311e3b1636af40e3ceaa0e560c Mon Sep 17 00:00:00 2001
From: skwasjer <11424653+skwasjer@users.noreply.github.com>
Date: Sat, 18 Nov 2023 07:31:37 +0100
Subject: [PATCH] test: replace Moq with NSubstitute
---
test/Directory.Build.targets | 4 +-
.../MockHttpRequestContextExtensionsTests.cs | 2 +-
.../JsonContentMatcherTests.cs | 78 +++++++---------
.../MockConfigurationExtensionsTests.cs | 13 +--
.../MockHttp.Tests/AnyRequestMatchingTests.cs | 17 ++--
.../Extensions/IRespondsExtensionsTests.cs | 14 ++-
.../Extensions/ListExtensionsTests.cs | 4 +-
.../RequestMatchingExtensionsTests.cs | 21 +++--
.../Response/FuncStreamBodyCannotReadSpec.cs | 11 +--
.../Flow/Response/NullBuilderTests.cs | 10 +--
.../Flow/Response/StreamBodyCannotReadSpec.cs | 11 +--
.../Flow/Response/StreamBodyCannotSeekSpec.cs | 13 ++-
.../Matchers/AnyMatcherTests.cs | 10 +--
.../Matchers/FakeToStringTestMatcher.cs | 20 +++++
.../Matchers/FormDataMatcherTests.cs | 88 ++++++++-----------
.../Matchers/HttpRequestMatcherTests.cs | 7 +-
.../Matchers/NotMatcherTests.cs | 17 ++--
.../MockPriorityBehaviorTests.cs | 26 ------
test/MockHttp.Tests/RateLimitedStreamTests.cs | 30 +++----
test/MockHttp.Tests/RequestMatchingTests.cs | 17 ++--
.../Responses/EmptyContentTests.cs | 9 +-
.../Responses/TimeoutBehaviorTests.cs | 12 +--
22 files changed, 182 insertions(+), 252 deletions(-)
create mode 100644 test/MockHttp.Tests/Matchers/FakeToStringTestMatcher.cs
diff --git a/test/Directory.Build.targets b/test/Directory.Build.targets
index f4f4b349..a86e5b8f 100644
--- a/test/Directory.Build.targets
+++ b/test/Directory.Build.targets
@@ -13,13 +13,13 @@
-
+
-
+
diff --git a/test/MockHttp.Json.Tests/Extensions/MockHttpRequestContextExtensionsTests.cs b/test/MockHttp.Json.Tests/Extensions/MockHttpRequestContextExtensionsTests.cs
index ce8a6ba4..8d1f0f01 100644
--- a/test/MockHttp.Json.Tests/Extensions/MockHttpRequestContextExtensionsTests.cs
+++ b/test/MockHttp.Json.Tests/Extensions/MockHttpRequestContextExtensionsTests.cs
@@ -26,7 +26,7 @@ public void Given_that_adapter_is_not_registered_when_getting_adapter_it_should_
public void Given_that_adapter_is_registered_when_getting_adapter_it_should_return_same_instance()
{
using var msg = new HttpRequestMessage();
- IJsonAdapter adapter = Mock.Of();
+ IJsonAdapter adapter = Substitute.For();
var items = new Dictionary { { typeof(IJsonAdapter), adapter } };
var sut = new MockHttpRequestContext(msg, items);
sut.Services.Should().NotBeEmpty();
diff --git a/test/MockHttp.Json.Tests/JsonContentMatcherTests.cs b/test/MockHttp.Json.Tests/JsonContentMatcherTests.cs
index bde5fb06..dc1ba740 100644
--- a/test/MockHttp.Json.Tests/JsonContentMatcherTests.cs
+++ b/test/MockHttp.Json.Tests/JsonContentMatcherTests.cs
@@ -4,22 +4,21 @@ namespace MockHttp.Json;
public sealed class JsonContentMatcherTests : IDisposable
{
- private readonly Mock _adapterMock;
- private readonly Mock> _equalityComparerMock;
- private readonly Dictionary _services;
+ private readonly IJsonAdapter _adapterMock;
+ private readonly IEqualityComparer _equalityComparerMock;
+ private readonly Dictionary _services = new();
private readonly HttpRequestMessage _requestMessage;
private readonly MockHttpRequestContext _requestContext;
public JsonContentMatcherTests()
{
- _adapterMock = new Mock();
+ _adapterMock = Substitute.For();
- _equalityComparerMock = new Mock>();
+ _equalityComparerMock = Substitute.For>();
_equalityComparerMock
- .Setup(m => m.Equals(It.IsAny()!, It.IsAny()!))
+ .Equals(Arg.Any(), Arg.Any())
.Returns(true);
- _services = new Dictionary();
_requestMessage = new HttpRequestMessage();
_requestContext = new MockHttpRequestContext(_requestMessage, _services);
}
@@ -30,25 +29,21 @@ public async Task Given_that_adapter_is_provided_to_ctor_when_matching_it_should
var jsonContentAsObject = new { PropertyName = "value" };
const string serializedJson = "{\"modifiedPropertyName\":\"modifiedValue\"}";
_adapterMock
- .Setup(m => m.Serialize(jsonContentAsObject))
- .Returns(serializedJson)
- .Verifiable();
+ .Serialize(Arg.Any