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

Verify(It.Is<T>(t => t.SomeProperty.Equals("SomeValue")), Times.Exactly(x)) isn't working as expected #1331

Closed
orleviad opened this issue Feb 5, 2023 · 1 comment

Comments

@orleviad
Copy link

orleviad commented Feb 5, 2023

I've set up a mock when upon receiving a specific value of a property should return a value.
The test went as expected (objects with the specific valued property received the expected value, all others got null).
Issue is that the Verify isn't working as expected:
The tested object property value was changed thoughout the test. I expected the verify to count calls with specific value. It only counted the total number of calls made to the function with the object with any value!

Snippet:
m.Setup(s => s.SomeFunction(It.Is<T>(t => t.SomeProperty.Equals("SomeValue")))).Returns("ExpectedValue");
...
Call function that uses m
....
m.Verify(s => s.SomeFunction(It.Is<T>(t => t.SomeProperty.Equals("SomeValue"))), Times.Exactly(2));

The output of test:
Expected invocation on the mock exactly 2 times, but was 4 times: s => s.SomeFunction(It.Is<T>(t => t.SomeProperty.Equals("SomeValue")))

The mock was indeed called 4 times during the test, 2 out of them was with the "SomeValue" in t.SomeProperty (validated in debug)

Performed invocations:

   Mock<m:1> (s):
      m.SomeFunction(T)
      m.SomeFunction(T)
      m.SomeFunction(T)
      m.SomeFunction(T)
@stakx
Copy link
Contributor

stakx commented Feb 5, 2023

We get this report about once every two weeks. Do a search (including closed issues) and you'll find an answer.

@stakx stakx closed this as completed Feb 5, 2023
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

No branches or pull requests

2 participants