From 7d428719c3c9dee00370ed1f12238177e34d2c46 Mon Sep 17 00:00:00 2001
From: skwasjer <11424653+skwasjer@users.noreply.github.com>
Date: Thu, 10 Aug 2023 06:41:53 +0200
Subject: [PATCH] chore(deps): replace Moq with NSubstitute
---
test/Directory.Build.targets | 8 +++-
.../IbanAttributeTests.cs | 48 +++++++++----------
.../Specs/ShouldResolveCustomService.cs | 8 ++--
.../Specs/ShouldResolveCustomService.cs | 8 ++--
.../FluentIbanValidatorTests.cs | 10 ++--
.../RuleBuilderExtensionsTests.cs | 12 ++---
.../Builders/BuilderExtensionsTests.cs | 15 +++---
.../DependencyResolverAdapterTests.cs | 28 +++++------
.../IbanNetOptionsBuilderStubAssertions.cs | 8 ++--
.../IbanNetOptionsBuilderStubExtensions.cs | 2 +-
.../IbanNetOptionsBuilderTests.cs | 34 +++++++------
test/IbanNet.Tests/IbanParserTests.cs | 17 ++++---
test/IbanNet.Tests/IbanTests.cs | 4 +-
test/IbanNet.Tests/IbanValidatorTests.cs | 21 ++++----
.../Json/IbanJsonConverterTests.cs | 18 ++++---
.../Registry/IbanRegistryTests.cs | 6 +--
.../Registry/Patterns/PatternTests.cs | 25 +++++-----
.../TypeConverters/IbanTypeConverterTests.cs | 31 ++++++------
.../DefaultValidationRuleResolverTests.cs | 10 ++--
.../Validation/Rules/Mod97RuleTests.cs | 22 ++++-----
.../FluentAssertions/DelegateAssertions.cs | 6 +--
test/TestHelpers/IbanValidatorStub.cs | 38 +++++++--------
.../Specs/ConfiguredMultipleRulesSpec.cs | 2 +-
.../ShouldPreserveStaticValidatorSpec.cs | 2 +-
.../Specs/ShouldResolveCustomService.cs | 34 ++++++-------
.../Specs/ShouldSetStaticValidatorSpec.cs | 2 +-
test/TestHelpers/TestValues.cs | 6 +--
27 files changed, 205 insertions(+), 220 deletions(-)
diff --git a/test/Directory.Build.targets b/test/Directory.Build.targets
index 37a31ea8..72757035 100644
--- a/test/Directory.Build.targets
+++ b/test/Directory.Build.targets
@@ -8,13 +8,17 @@
-
+
-
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
diff --git a/test/IbanNet.DataAnnotations.Tests/IbanAttributeTests.cs b/test/IbanNet.DataAnnotations.Tests/IbanAttributeTests.cs
index 2f607da5..9a985b7f 100644
--- a/test/IbanNet.DataAnnotations.Tests/IbanAttributeTests.cs
+++ b/test/IbanNet.DataAnnotations.Tests/IbanAttributeTests.cs
@@ -7,21 +7,21 @@ namespace IbanNet.DataAnnotations;
[Collection(nameof(SetsStaticValidator))]
public class IbanAttributeTests
{
- private readonly Mock _serviceProviderMock;
+ private readonly IServiceProvider _serviceProviderMock;
private readonly IbanAttribute _sut;
- private readonly IbanValidatorStub _ibanValidatorStub;
+ private readonly IIbanValidator _ibanValidatorStub;
private ValidationContext _validationContext;
protected IbanAttributeTests()
{
- _ibanValidatorStub = new IbanValidatorStub();
- _serviceProviderMock = new Mock();
+ _ibanValidatorStub = IbanValidatorStub.Create();
+ _serviceProviderMock = Substitute.For();
_serviceProviderMock
- .Setup(m => m.GetService(typeof(IIbanValidator)))
+ .GetService(typeof(IIbanValidator))
.Returns(_ibanValidatorStub);
- _validationContext = new ValidationContext(new object(), _serviceProviderMock.Object, null);
+ _validationContext = new ValidationContext(new object(), _serviceProviderMock, null);
_sut = new IbanAttribute();
}
@@ -35,7 +35,7 @@ public void It_should_not_call_validator()
_sut.GetValidationResult(null, _validationContext);
// Assert
- _ibanValidatorStub.VerifyNoOtherCalls();
+ _ibanValidatorStub.ReceivedCalls().Should().BeEmpty();
}
[Fact]
@@ -45,7 +45,7 @@ public void It_should_not_resolve_the_validator()
_sut.GetValidationResult(null, _validationContext);
// Assert
- _serviceProviderMock.Verify(m => m.GetService(It.IsAny()), Times.Never);
+ _serviceProviderMock.DidNotReceiveWithAnyArgs().GetService(default!);
}
[Fact]
@@ -78,8 +78,8 @@ public void It_should_call_validator()
_sut.GetValidationResult(TestValues.ValidIban, _validationContext);
// Assert
- _ibanValidatorStub.Verify(m => m.Validate(TestValues.ValidIban), Times.Once);
- _ibanValidatorStub.VerifyNoOtherCalls();
+ _ibanValidatorStub.Received(1).Validate(TestValues.ValidIban);
+ _ibanValidatorStub.ReceivedCalls().Should().HaveCount(1);
}
[Fact]
@@ -89,8 +89,8 @@ public void It_should_resolve_the_validator()
_sut.GetValidationResult(TestValues.ValidIban, _validationContext);
// Assert
- _serviceProviderMock.Verify(m => m.GetService(typeof(IIbanValidator)));
- _serviceProviderMock.VerifyNoOtherCalls();
+ _serviceProviderMock.Received(1).GetService(typeof(IIbanValidator));
+ _serviceProviderMock.ReceivedCalls().Should().HaveCount(1);
}
[Fact]
@@ -123,8 +123,8 @@ public void It_should_call_validator()
_sut.GetValidationResult(TestValues.InvalidIban, _validationContext);
// Assert
- _ibanValidatorStub.Verify(m => m.Validate(TestValues.InvalidIban), Times.Once);
- _ibanValidatorStub.VerifyNoOtherCalls();
+ _ibanValidatorStub.Received(1).Validate(TestValues.InvalidIban);
+ _ibanValidatorStub.ReceivedCalls().Should().HaveCount(1);
}
[Fact]
@@ -156,8 +156,8 @@ public void It_should_resolve_the_validator()
_sut.GetValidationResult(TestValues.InvalidIban, _validationContext);
// Assert
- _serviceProviderMock.Verify(m => m.GetService(typeof(IIbanValidator)));
- _serviceProviderMock.VerifyNoOtherCalls();
+ _serviceProviderMock.Received(1).GetService(typeof(IIbanValidator));
+ _serviceProviderMock.ReceivedCalls().Should().HaveCount(1);
}
[Fact]
@@ -215,8 +215,8 @@ public void It_should_throw()
// Assert
act.Should().Throw();
- _serviceProviderMock.Verify(m => m.GetService(It.IsAny()), Times.Never);
- _ibanValidatorStub.VerifyNoOtherCalls();
+ _serviceProviderMock.DidNotReceiveWithAnyArgs().GetService(default!);
+ _ibanValidatorStub.ReceivedCalls().Should().BeEmpty();
}
}
@@ -227,9 +227,8 @@ public void It_should_throw()
{
// Arrange
_serviceProviderMock
- .Setup(m => m.GetService(typeof(IIbanValidator)))
- .Returns(null)
- .Verifiable();
+ .GetService(Arg.Any())
+ .Returns(null);
// Act
Action act = () => _sut.GetValidationResult(TestValues.ValidIban, _validationContext);
@@ -238,8 +237,8 @@ public void It_should_throw()
act.Should()
.Throw()
.WithMessage("Failed to get an instance of *");
- _serviceProviderMock.Verify();
- _ibanValidatorStub.VerifyNoOtherCalls();
+ _serviceProviderMock.Received(1).GetService(typeof(IIbanValidator));
+ _ibanValidatorStub.ReceivedCalls().Should().BeEmpty();
}
}
@@ -258,8 +257,7 @@ public void It_should_throw()
act.Should()
.Throw()
.WithMessage("Failed to get an instance of *");
- _ibanValidatorStub.VerifyNoOtherCalls();
- }
+ _ibanValidatorStub.ReceivedCalls().Should().BeEmpty(); }
}
public class Requires_validation_context : IbanAttributeTests
diff --git a/test/IbanNet.DependencyInjection.Autofac.Tests/Specs/ShouldResolveCustomService.cs b/test/IbanNet.DependencyInjection.Autofac.Tests/Specs/ShouldResolveCustomService.cs
index eca26430..e3adbbd0 100644
--- a/test/IbanNet.DependencyInjection.Autofac.Tests/Specs/ShouldResolveCustomService.cs
+++ b/test/IbanNet.DependencyInjection.Autofac.Tests/Specs/ShouldResolveCustomService.cs
@@ -19,10 +19,10 @@ public CustomServicesDependencyInjectionFixture() : base(false)
protected override void Configure(ContainerBuilder containerBuilder, Action configurer)
{
- containerBuilder.RegisterInstance(Mock.Of());
- containerBuilder.RegisterInstance(Mock.Of());
- containerBuilder.RegisterInstance(Mock.Of());
- containerBuilder.RegisterInstance(Mock.Of());
+ containerBuilder.RegisterInstance(Substitute.For());
+ containerBuilder.RegisterInstance(Substitute.For());
+ containerBuilder.RegisterInstance(Substitute.For());
+ containerBuilder.RegisterInstance(Substitute.For());
base.Configure(containerBuilder, configurer);
}
diff --git a/test/IbanNet.DependencyInjection.ServiceProvider.Tests/Specs/ShouldResolveCustomService.cs b/test/IbanNet.DependencyInjection.ServiceProvider.Tests/Specs/ShouldResolveCustomService.cs
index 493d81bb..4ca4800d 100644
--- a/test/IbanNet.DependencyInjection.ServiceProvider.Tests/Specs/ShouldResolveCustomService.cs
+++ b/test/IbanNet.DependencyInjection.ServiceProvider.Tests/Specs/ShouldResolveCustomService.cs
@@ -19,10 +19,10 @@ public CustomServicesDependencyInjectionFixture() : base(false)
protected override void Configure(IServiceCollection services, Action configurer)
{
- services.AddSingleton(Mock.Of());
- services.AddSingleton(Mock.Of());
- services.AddSingleton(Mock.Of());
- services.AddSingleton(Mock.Of());
+ services.AddSingleton(Substitute.For());
+ services.AddSingleton(Substitute.For());
+ services.AddSingleton(Substitute.For());
+ services.AddSingleton(Substitute.For());
base.Configure(services, configurer);
}
diff --git a/test/IbanNet.FluentValidation.Tests/FluentIbanValidatorTests.cs b/test/IbanNet.FluentValidation.Tests/FluentIbanValidatorTests.cs
index 61ab8d1f..0f97c125 100644
--- a/test/IbanNet.FluentValidation.Tests/FluentIbanValidatorTests.cs
+++ b/test/IbanNet.FluentValidation.Tests/FluentIbanValidatorTests.cs
@@ -9,12 +9,12 @@ namespace IbanNet.FluentValidation;
[Collection(nameof(SetsStaticValidator))]
public class FluentIbanValidatorTests
{
- private readonly IbanValidatorStub _ibanValidatorStub;
+ private readonly IIbanValidator _ibanValidatorStub;
private readonly TestModelValidator _validator;
protected FluentIbanValidatorTests()
{
- _ibanValidatorStub = new IbanValidatorStub();
+ _ibanValidatorStub = IbanValidatorStub.Create();
var sut = new FluentIbanValidator(_ibanValidatorStub);
_validator = new TestModelValidator(sut);
}
@@ -32,7 +32,7 @@ public void It_should_call_validator()
_validator.Validate(obj);
// Assert
- _ibanValidatorStub.Verify(m => m.Validate(AttemptedIbanValue), Times.Once);
+ _ibanValidatorStub.Received(1).Validate(AttemptedIbanValue);
}
[Fact]
@@ -72,7 +72,7 @@ public void It_should_call_validator()
_validator.Validate(obj);
// Assert
- _ibanValidatorStub.Verify(m => m.Validate(AttemptedIbanValue), Times.Once);
+ _ibanValidatorStub.Received(1).Validate(AttemptedIbanValue);
}
[Fact]
@@ -100,7 +100,7 @@ public void It_should_not_call_validator()
_validator.Validate(obj);
// Assert
- _ibanValidatorStub.Verify(m => m.Validate(It.IsAny()), Times.Never);
+ _ibanValidatorStub.DidNotReceiveWithAnyArgs().Validate(default);
}
[Fact]
diff --git a/test/IbanNet.FluentValidation.Tests/RuleBuilderExtensionsTests.cs b/test/IbanNet.FluentValidation.Tests/RuleBuilderExtensionsTests.cs
index ea9303a3..46bf1c75 100644
--- a/test/IbanNet.FluentValidation.Tests/RuleBuilderExtensionsTests.cs
+++ b/test/IbanNet.FluentValidation.Tests/RuleBuilderExtensionsTests.cs
@@ -11,7 +11,7 @@ public void Given_null_builder_when_registering_validator_it_should_throw()
IRuleBuilder