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

MockDefaultValueProvider will try to set 'Callbase' on auto-generated mocks for delegates. #874

Closed
dammejed opened this issue Aug 7, 2019 · 2 comments · Fixed by #875
Closed
Assignees
Labels
Milestone

Comments

@dammejed
Copy link
Contributor

dammejed commented Aug 7, 2019

Recently, it's become a blocking error to set CallBase to true on Mocks of delegates.
This causes a regression is existing code that had set CallBase to true, and the MockDefaultValueProvider was being used to provide values for items that weren't setup.

Here's an illustration of the issue:

[Fact]
public void MockDefaultValueProvide_will_not_propagate_Callback_to_delegates()
{
	var mock = new Mock<IDictionary<string, Func<string>>>()
	{
		CallBase = true,
		DefaultValue = DefaultValue.Mock
	};
	var mockedIndexResult = mock.Object["foo"]; // This line throws because it attempts to set `CallBase` to true on the auto-generated mock for the delegate.
	Assert.Null(mockedIndexResult());
}

I can submit a PR to fix the bug-- it seems fairly straightforward.

@stakx
Copy link
Contributor

stakx commented Aug 7, 2019

Hi @dammejed, thanks for reporting this problem, and for your PR. Yes, this looks like something that should be fixed!

@stakx stakx closed this as completed in #875 Aug 7, 2019
@dammejed
Copy link
Contributor Author

dammejed commented Aug 7, 2019

Cheers, thanks for your reactivity! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants