Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test for issue #716 #846

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion tests/NSubstitute.Acceptance.Specs/ArgumentMatching.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -828,6 +830,25 @@ public void Does_not_support_matching_ArgAny_of_type_derived_from_base_type_with
service.DidNotReceive().MyMethod(Arg.Any<MySampleClassArgument>());
}

[Test]
public void Does_support_out_method_with_base_override()
{
var controlFactory = Substitute.For<MyHasMethodWithOutParameter>();

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()
{
Expand Down Expand Up @@ -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;
}
}
}
Loading