From 04642cd3e3d0c7955588d143d3af1b58e8544bae Mon Sep 17 00:00:00 2001 From: Remco Beurskens Date: Thu, 28 Nov 2024 18:35:58 +0100 Subject: [PATCH 1/2] Added test for issue #716 --- .../ArgumentMatching.cs | 48 ++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/tests/NSubstitute.Acceptance.Specs/ArgumentMatching.cs b/tests/NSubstitute.Acceptance.Specs/ArgumentMatching.cs index 19e3c99c..32300732 100644 --- a/tests/NSubstitute.Acceptance.Specs/ArgumentMatching.cs +++ b/tests/NSubstitute.Acceptance.Specs/ArgumentMatching.cs @@ -1,7 +1,9 @@ using NSubstitute.Acceptance.Specs.Infrastructure; using NSubstitute.Core; using NSubstitute.Core.Arguments; +using NSubstitute.ExceptionExtensions; using NSubstitute.Exceptions; +using NSubstitute.Extensions; using NUnit.Framework; namespace NSubstitute.Acceptance.Specs; @@ -828,6 +830,25 @@ public void Does_not_support_matching_ArgAny_of_type_derived_from_base_type_with service.DidNotReceive().MyMethod(Arg.Any()); } + [Test] + public void Does_support_out_method_with_base_override() + { + var controlFactory = Substitute.For(); + + Assert.That(() => controlFactory.Configure() + .MethodWithOutParameter(default, out var _) + .ReturnsForAnyArgs(ci => + { + ci[1] = 4; + return 3; + }), Throws.Nothing); + + var returned = controlFactory.MethodWithOutParameter(0, out var outArg); + using var _ = Assert.EnterMultipleScope(); + Assert.That(returned, Is.EqualTo(3)); + Assert.That(outArg, Is.EqualTo(4)); + } + [SetUp] public void SetUp() { @@ -889,4 +910,29 @@ class CustomDescribeSpecMatcher(string description) : CustomMatcher, IDescribeSp { public string DescribeSpecification() => description; } -} + + public interface IHasMethodWithOutParameter + { + int MethodWithOutParameter(int arg1, out int arg2); + } + + public class HasMethodWithOutParameter : IHasMethodWithOutParameter + { + public virtual int MethodWithOutParameter(int arg1, out int arg2) + { + arg2 = 2; + return 1; + } + } + + public class MyHasMethodWithOutParameter : HasMethodWithOutParameter + { + // The presence of his override used to throw an exception in NSubstitute 5.0.0, caused by a bug in Caste.Core < 5.2.0 + // https://github.com/nsubstitute/NSubstitute/issues/716 + public override int MethodWithOutParameter(int arg1, out int arg2) + { + arg2 = 3; + return 2; + } + } +} \ No newline at end of file From 45f87b680b9b2e207628300ca20fce40715449ba Mon Sep 17 00:00:00 2001 From: Remco Beurskens Date: Sun, 15 Dec 2024 19:51:14 +0100 Subject: [PATCH 2/2] Removed whitespace only lines in ArgumentMatching.cs suggested by CI action --- tests/NSubstitute.Acceptance.Specs/ArgumentMatching.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/NSubstitute.Acceptance.Specs/ArgumentMatching.cs b/tests/NSubstitute.Acceptance.Specs/ArgumentMatching.cs index 32300732..7ec8df48 100644 --- a/tests/NSubstitute.Acceptance.Specs/ArgumentMatching.cs +++ b/tests/NSubstitute.Acceptance.Specs/ArgumentMatching.cs @@ -910,12 +910,12 @@ class CustomDescribeSpecMatcher(string description) : CustomMatcher, IDescribeSp { public string DescribeSpecification() => description; } - + public interface IHasMethodWithOutParameter { int MethodWithOutParameter(int arg1, out int arg2); } - + public class HasMethodWithOutParameter : IHasMethodWithOutParameter { public virtual int MethodWithOutParameter(int arg1, out int arg2) @@ -924,7 +924,7 @@ public virtual int MethodWithOutParameter(int arg1, out int arg2) return 1; } } - + public class MyHasMethodWithOutParameter : HasMethodWithOutParameter { // The presence of his override used to throw an exception in NSubstitute 5.0.0, caused by a bug in Caste.Core < 5.2.0 @@ -935,4 +935,4 @@ public override int MethodWithOutParameter(int arg1, out int arg2) return 2; } } -} \ No newline at end of file +}