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

Moq 4.2 documentation #612

Closed
IvanRibakov opened this issue Apr 7, 2018 · 3 comments
Closed

Moq 4.2 documentation #612

IvanRibakov opened this issue Apr 7, 2018 · 3 comments

Comments

@IvanRibakov
Copy link

IvanRibakov commented Apr 7, 2018

Nuget.org is hosting 4.2 version of Moq which I'm forced to use due to my project's code base being targeted for .Net 3.5.

Unfortunately, current documentation found on https://github.com/Moq/moq4/wiki doesn't seem to apply to Moq v4.2 as I'm unable to find Setup() method on Mock object. Any ideas where could I find relevant documentation?

@IvanRibakov IvanRibakov changed the title Moq 3 documentation Moq 4.2 documentation Apr 7, 2018
@stakx
Copy link
Contributor

stakx commented Apr 7, 2018

See this project's README file; more specifically, the links in the section titled Where?. The quickstart guide in the wiki definitely has a few bits on Setup.

@IvanRibakov
Copy link
Author

IvanRibakov commented Apr 7, 2018

I'm able to find documentation in general. I'm just not sure it's the right one. As I mentioned originally, Mock object doesn't have Setup() method available in my case so I'm guessing Moq v4.2 is using some other API (which?).

image

P.S. oddly, defining mock variable using var gives me access to Setup() method. I guess this solves my problem, but I would really appreciate if someone could say couple words as to why this is happening (as you might have guessed by now, I'm fairly new to C#) or point me in the direction of further reading.

image

@stakx
Copy link
Contributor

stakx commented Apr 7, 2018

[...] as I'm unable to find Setup() method on Mock object.

Mock object doesn't have Setup() method available

If you are really using Moq 4.2.1510.2205 as you claimed above, then there should definitely be a Setup method group on Mock<T> (I just verified it, Setup is definitely there):

https://github.com/moq/moq4/blob/v4.2.1510.2205/Source/Mock.Generic.cs#L253-L314

Note that Setup is defined on Mock<T> (the generic class), not on its base class Mock (which you used as the static variable type in your first example). If you use var, the variable's static type will be inferred to be Mock<Tutor> since you have an expression of that type on the right-hand side of the assignment, and therefore you see the Setup methods defined on that type.

In conclusion, it's probably very rare that you declare your variables as Mock. Usually you should use Mock<T> which defines the public API for mocks.

@stakx stakx closed this as completed Apr 7, 2018
@devlooped devlooped locked and limited conversation to collaborators Sep 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants