-
-
Notifications
You must be signed in to change notification settings - Fork 798
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
Always record calls to += and -= event accessors #1082
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you elaborate why CallBase makes such a difference for the event raising?
I looked around, e.g. the quick start guide but couldn't figure out why it makes a difference
I'll try, but keep in mind that I didn't implement that part of Moq and, like you, had to try and make sense of it; so it's possible that the following explanations aren't entirely accurate. First, consider how one raises an event from outside the class that defines it. The short version is, it can't be done; not without reflecting over private members, whose names you can only guess. C#'s That's why Moq builds a completely separate event handling mechanism for its Now you've got a problem, however. If you are mocking a class, and that class has some methods that raise That's where |
Thank you for the explanation. That clear things up for me. |
@siprbaum, that's a good question, and I don't have the answer. Generally speaking, mocking classes tends to be more complicated than mocking interfaces because you have a base implementation to consider at all stages. For that reason, the first recommendation should be to write / refactor your code in such a way that you can work with (and mock) interfaces. That's generally helpful re: testability, and regarding mocked events, it makes things conceptually straightforward again (as you won't need nor have the choice whether to use But for those users mocking classes... after all these years, Moq still doesn't have proper documentation. I suspect the quickstart in the wiki was only ever meant to demonstrate the most common, straightforward usages; it probably isn't a good place for more in-depth looks at those aspects of Moq that aren't very intuitive. That being said, the wiki can be edited by everyone. Feel free to cook up some documentation and add it as a new wiki page. |
dd7c69c
to
06d3ce3
Compare
Resolves #1058.