internal class state when mocking with moq

58 views
Skip to first unread message

Konstantinos Papacharisiou

unread,
Apr 8, 2014, 8:57:44 AM4/8/14
to moq...@googlegroups.com

I am new to mocking and i just started to use moq. The tool states that we can use moq for mocking classes without interfaces. I was wondering if it is posible when mocking to keep the internal state of the class. For example:

//define class for mocking
var mock = new Mock<ILoveThisFramework>();

//define
mock.Setup(framework => framework.DownloadExists("2.0.0.0"))
      .Returns(true)
      .AtMostOnce();

//use mocking tools to call methods and return defined results

The question: althought the results were defined, have the internal state (e.g. private class variables) changed? (keep the class state?)

Jack Hughes

unread,
Apr 8, 2014, 9:12:59 AM4/8/14
to moq...@googlegroups.com

There is no class to have state because Moq doesn't instantiate an instance of it. Instead it creates a proxy of the class (if it can) and the proxy does what you tell it to do. In your example the proxy simply returns true when the DownloadExists method is called with the appropriate argument.

--
--
Post: moq...@googlegroups.com
Unsubscribe: moqdisc-u...@googlegroups.com
---
You received this message because you are subscribed to the Google Groups "Moq Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to moqdisc+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages