-
-
Notifications
You must be signed in to change notification settings - Fork 794
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
Proposal Verifiable return an IVerifier #534
Comments
Having a per-setup var mock = new Mock<T>(MockBehavior.Strict);
var setup1 = mock.Setup(m => …).….Verifiable();
var setup2 = mock.Setup(m => …).….Verifiable();
…
setup1.Verify(Times.…);
setup2.Verify(Times.…);
… If something like this is really required, IMHO we'd do better with either #373/#401 ( Do you see any scenario(s) where your proposition would be preferable to the alternatives just mentioned? |
#373/#401 would be my preferred, but they were rejected....so thinking of something different. #527 i think is a must, but doesn't solve my stub and then verify times requirements. Seeing the examples, your right, it's not nice. #527 is more about not needing a strict mock and not needing to setup a void, but still verify that no extra methods called. |
There's no need to reinvent the wheel, #401 probably comes very close to an ideal solution for specifying
Could you post an example that shows what you're unhappy with? |
It's the bits I put into #530 (after I realised sequence existed) If you have a complex function your setting up, the expression in the setup might be long. So far my only workarounds are to add an extension/superclass to a mock which creates a Func to do a verify when calling setup or to put the expression into a variable. Neither are elegant. The only reason I was thinking of other language constructs was because I thought that proposal was rejected (as the issue and or were closed) |
Just one thought as an aside: Perhaps it is a good thing to feel that pain. Perhaps it means that you should make that function less complex. I happen to think that while Moq shouldn't be too opinionated, it's OK to nudge people to consider better / cleaner designs. In the past, Moq was changed in a way to help steer people towards a better separation of the Arrange and Assert phases of a test. (For example, That's why I'm reluctant to merge anything that takes Moq back in the other direction. It's perhaps the main reason why I closed #401, and it's the reason why I was asking for your specific use case—I want to be sure this is really needed before we go on. |
The case I am working on right now isn't complex per say. The message is a piece of text. I'm coming from a different framework (Rhino) and I'm thinking in that mindset, which as you say may not be correct, and maybe the functions/tests are too complex. When you mark something as verifiable, does that mean 1 invocation or any number when you call verify? |
TL;DR: at least one invocation. You're looking at a part of Moq that perhaps isn't very easy to understand. You can perform verification against setups. This is what You can perform verification against invocations. This is what the other |
@stakx Ok, thanks. Maybe i am trying to compare and contrast to what i am used to (which may not be the best way to work) I'm going to try and embrace the difference and see how i get on. |
@stakx how would you feel about a .VerifyAll which takes a times? So you could go .VerifyAll(Times.Once) NB: leaving closed as i am curious and want to a place to discuss as i'm getting some good ideas from you :) (thanks!!) |
This doesn't work. The only scenario where this might make good sense is the distinction between |
@stakx yeah very true... |
Could the verifiable method return an object (IVerifier) which has already been setup with the function call details.
You could then state (after execution of code) verifier.Verify(Times.Once)
This means you don't need to specify the expression and arguments twice, but keeps sortation of setup and verify.
The text was updated successfully, but these errors were encountered: