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

ToString() on SetupPhrase does not return expression #810

Closed
jacob-ewald opened this issue Apr 17, 2019 · 2 comments · Fixed by #812
Closed

ToString() on SetupPhrase does not return expression #810

jacob-ewald opened this issue Apr 17, 2019 · 2 comments · Fixed by #812
Assignees
Milestone

Comments

@jacob-ewald
Copy link
Contributor

We have a unit test that verifies the message we receive when a sequenced setup is not run, but with version 4.10+ the message is no longer displaying the expression. Instead, it displays the full name of the type and method, which is the default ToString() output. I originally thought this may be an issue with Moq.Sequences, however it seems to be originating inside Moq.

To reproduce the issue here is a simple unit test:

[Fact]
public void SetupPhraseConvertsExpressionToDescriptiveString()
{
	var setupPhrase = new Mock<IFoo>().Setup(x => x.DoThings(null));

	Assert.Equal("x => x.DoThings(null)", setupPhrase.ToString());
}

Expected:

x => x.DoThings(null)

Actual:

Moq.Language.Flow.VoidSetupPhrase`1[Moq.Tests.Regressions.IssueReportsFixture+IFoo]

I can submit a PR to fix this (simply overridding the ToString() on SetupPhrase), but wanted to see if that would be welcome first. Thanks!

@stakx
Copy link
Contributor

stakx commented Apr 17, 2019

@jacob-ewald: Sounds like a reasonable enhancement! I suppose it would make sense for all fluent API types' ToString methods to simply delegate to the ToString method of the setup that they're wrapping. Your PR would be welcome. It'd be great if you could make the change for all ...Phrase classes.

@jacob-ewald
Copy link
Contributor Author

Thanks @stakx. I created PR #812. I did not add handling for WhenPhrase because that works on Func<bool>, which doesn't play nicely with the ExpressionStringBuilder.

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

Successfully merging a pull request may close this issue.

2 participants