c# - Verify a method call using Moq - Stack Overflow
stackoverflow.com › questions › 9136674Feb 4, 2012 · Verify a method call using Moq. I am fairly new to unit testing in C# and learning to use Moq. Below is the class that I am trying to test. class MyClass { SomeClass someClass; public MyClass (SomeClass someClass) { this.someClass = someClass; } public void MyMethod (string method) { method = "test" someClass.DoSomething (method); } } class Someclass { public DoSomething (string method) { // do something...
How do I verify a method was called exactly once with Moq?
stackoverflow.com › questions › 4206193Nov 17, 2010 · Note: By default Moq will stub all the properties and methods as soon as you create a Mock object. So even without calling Setup, Moq has already stubbed the methods for IPrinter so you can just call Verify. However, as a good practice, I always set it up because we may need to enforce the parameters to the method to meet certain expectations, or the return value from the method to meet certain expectations or the number of times it has been called.