From e9858d9d66ad75ff13f6becc311c50d8dd75caa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Silva?= <2493377+askpt@users.noreply.github.com> Date: Tue, 15 Aug 2023 15:57:18 +0100 Subject: [PATCH] test: Replace Moq with NSubstitute (#142) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com> --- .../OpenFeature.Tests/OpenFeatureHookTests.cs | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/test/OpenFeature.Tests/OpenFeatureHookTests.cs b/test/OpenFeature.Tests/OpenFeatureHookTests.cs index e81c5d3c..aa0c75c4 100644 --- a/test/OpenFeature.Tests/OpenFeatureHookTests.cs +++ b/test/OpenFeature.Tests/OpenFeatureHookTests.cs @@ -482,34 +482,33 @@ public async Task Hook_Hints_May_Be_Optional() [Specification("4.4.7", "If an error occurs in the `before` hooks, the default value MUST be returned.")] public async Task When_Error_Occurs_In_Before_Hook_Should_Return_Default_Value() { - var featureProvider = new Mock(MockBehavior.Strict); - var hook = new Mock(MockBehavior.Strict); + var featureProvider = Substitute.For(); + var hook = Substitute.For(); var exceptionToThrow = new Exception("Fails during default"); - var sequence = new MockSequence(); - - featureProvider.Setup(x => x.GetMetadata()) - .Returns(new Metadata(null)); - - hook.InSequence(sequence) - .Setup(x => x.Before(It.IsAny>(), It.IsAny>())) - .ThrowsAsync(exceptionToThrow); - - hook.InSequence(sequence) - .Setup(x => x.Error(It.IsAny>(), It.IsAny(), null)).Returns(Task.CompletedTask); + featureProvider.GetMetadata().Returns(new Metadata(null)); - hook.InSequence(sequence) - .Setup(x => x.Finally(It.IsAny>(), null)).Returns(Task.CompletedTask); + // Sequence + hook.Before(Arg.Any>(), Arg.Any>()).ThrowsAsync(exceptionToThrow); + hook.Error(Arg.Any>(), Arg.Any(), null).Returns(Task.CompletedTask); + hook.Finally(Arg.Any>(), null).Returns(Task.CompletedTask); var client = Api.Instance.GetClient(); - client.AddHooks(hook.Object); + client.AddHooks(hook); var resolvedFlag = await client.GetBooleanValue("test", true); + Received.InOrder(() => + { + hook.Before(Arg.Any>(), Arg.Any>()); + hook.Error(Arg.Any>(), Arg.Any(), null); + hook.Finally(Arg.Any>(), null); + }); + resolvedFlag.Should().BeTrue(); - hook.Verify(x => x.Before(It.IsAny>(), null), Times.Once); - hook.Verify(x => x.Error(It.IsAny>(), exceptionToThrow, null), Times.Once); - hook.Verify(x => x.Finally(It.IsAny>(), null), Times.Once); + _ = hook.Received(1).Before(Arg.Any>(), null); + _ = hook.Received(1).Error(Arg.Any>(), exceptionToThrow, null); + _ = hook.Received(1).Finally(Arg.Any>(), null); } [Fact]