Skip to content

Commit

Permalink
Added test for issue #716
Browse files Browse the repository at this point in the history
  • Loading branch information
rbeurskens committed Nov 28, 2024
1 parent 72d146d commit e791117
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions 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 All @@ -845,4 +866,27 @@ public class MyOtherStringArgument : IMyArgument<string> { }
public class MySampleClassArgument : IMyArgument<SampleClass> { }
public class MyOtherSampleClassArgument : IMyArgument<SampleClass> { }
public class MySampleDerivedClassArgument : MySampleClassArgument { }

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;
}
}
}

0 comments on commit e791117

Please sign in to comment.