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

Write exact values into exception messages #636

Closed
pinki opened this issue Jul 2, 2018 · 3 comments · Fixed by #637
Closed

Write exact values into exception messages #636

pinki opened this issue Jul 2, 2018 · 3 comments · Fixed by #637

Comments

@pinki
Copy link

pinki commented Jul 2, 2018

I had this exception:

Moq.MockException:
Expected invocation on the mock exactly 22 times, but was 21 times: p => p.Report(It.IsInRange(0, 1, Range.Inclusive))

Configured setups:
p => p.Report(It.IsInRange(0, 1, Range.Inclusive))

Performed invocations:
IProgress`1.Report(0)
IProgress`1.Report(0,05)
IProgress`1.Report(0,1)
IProgress`1.Report(0,15)
IProgress`1.Report(0,2)
IProgress`1.Report(0,25)
IProgress`1.Report(0,3)
IProgress`1.Report(0,35)
IProgress`1.Report(0,4)
IProgress`1.Report(0,45)
IProgress`1.Report(0,5)
IProgress`1.Report(0,55)
IProgress`1.Report(0,6)
IProgress`1.Report(0,65)
IProgress`1.Report(0,7)
IProgress`1.Report(0,75)
IProgress`1.Report(0,8)
IProgress`1.Report(0,85)
IProgress`1.Report(0,9)
IProgress`1.Report(0,95)
IProgress`1.Report(1)
IProgress`1.Report(1)

I was wondering why the validation didn't pass.
It turned out, that the first 1 was 1.000[...]2.

It took me a long time to find that out.
If the exact value was inside the exception message, it would have saved me much time.

@stakx
Copy link
Contributor

stakx commented Jul 2, 2018

AFAIK Moq doesn't have any special logic for rounding floating point numbers, it just performs a regular .ToString() on the arguments. Not sure what can be done about this. Suggestions?

@stakx
Copy link
Contributor

stakx commented Jul 8, 2018

@pinki: This will be "fixed" in the next release of Moq (version > 4.8.3).

(The "fix" consists of using round-tripping when formatting floating point values for inclusion in diagnostic messages. The Visual Studio IDE does the same for floats in e.g. the Watch window, so it seemed like a reasonable change to do the same in Moq.)

@stakx
Copy link
Contributor

stakx commented Jul 13, 2018

@pinki - I've just published Moq v4.9.0 on NuGet.

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

Successfully merging a pull request may close this issue.

2 participants