Moq: Missing Expect methods (Expect, ExpectGet, ExpectSet)
I got stuck on a really stupid problem yesterday and I just figured it out as I was writing a post on the Moq forums. It seems really dumb and maybe that's why I couldn't find any help on it, but since I didn't find anything anywhere I decided to at least put it somewhere to save someone else a little bit of time.
I've been using Moq for about a month now and I'm loving it. But it seems all of a sudden I can't use the Expect methods (Expect, ExpectGet, ExpectSet). If I open up a brand new Test project and reference Moq.dll (v 2.6.1014.1), then create a public interface like this:
Then if I create a test method like this:
The Expect methods are all missing from Intellisense. If I write it out anyway, it won't compile. I get the error:
'Moq.Mock' does not contain a definition for Expect() and no extension method for Expect() accepting a first argument of type 'Moq.Mock' could be found (are you missing a using directive or assembly reference?)
It turns out that most likely my problem was the cold medication I was on. But when you’re using Generics that Mock doesn’t equal Mock<IMyInterface>. So here’s what my test method should have been:
It’s just a good thing for me that a laptop is not included in the “Heavy Machinery” warning on my cold medicine.