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

Account for by-ref params in MethodExpectation.CreateFrom(Invocation) #1251

Merged
merged 3 commits into from Apr 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -10,6 +10,7 @@ The format is loosely based on [Keep a Changelog](http://keepachangelog.com/en/1
#### Fixed

* Regression: Property stubs not working on sub mock (@aaronburro, #1240)
* Failure when invoking a method with by-ref parameter & mockable return type on a mock with `CallBase` and `DefaultValue.Mock` configured (@IanKemp, #1249)


## 4.17.1 (2022-02-26)
Expand Down
4 changes: 3 additions & 1 deletion src/Moq/MethodExpectation.cs
Expand Up @@ -37,7 +37,9 @@ public static MethodExpectation CreateFrom(Invocation invocation)
arguments = new Expression[n];
for (int i = 0; i < n; ++i)
{
arguments[i] = E.Constant(invocation.Arguments[i], parameterTypes[i]);
var parameterType = parameterTypes[i];
if (parameterType.IsByRef) parameterType = parameterType.GetElementType();
arguments[i] = E.Constant(invocation.Arguments[i], parameterType);
}
}

Expand Down
21 changes: 21 additions & 0 deletions tests/Moq.Tests/Regressions/IssueReportsFixture.cs
Expand Up @@ -3782,6 +3782,27 @@ public void Property_on_submock_should_be_stubbed_2()

#endregion

#region 1249

public class Issue1249
{
public class NonSealedType { }

public interface IFoo
{
NonSealedType Method(in int arg);
}

[Fact]
public void No_ArgumentException_due_to_parameter_refness()
{
var mock = new Mock<IFoo>() { CallBase = true, DefaultValue = DefaultValue.Mock };
_ = mock.Object.Method(default);
}
}

#endregion

// Old @ Google Code

#region #47
Expand Down