Verifies that all verifiable expectations have been met.
Moq supports mocking protected methods. Changing the methods to protected , instead of private , would allow you to mock their implementation.
The Moq framework is an open source unit testing framework that works very well with .
AtLeastOnce - Specifies that a mocked method should be invoked one time as minimum. AtMost - Specifies that a mocked method should be invoked times time as maximum. AtMostOnce - Specifies that a mocked method should be invoked one time as maximum.
You're checking the wrong method. Moq requires that you Setup (and then optionally Verify) the method in the dependency class.
You should be doing something more like this:
class MyClassTest
{
[TestMethod]
public void MyMethodTest()
{
string action = "test";
Mock<SomeClass> mockSomeClass = new Mock<SomeClass>();
mockSomeClass.Setup(mock => mock.DoSomething());
MyClass myClass = new MyClass(mockSomeClass.Object);
myClass.MyMethod(action);
// Explicitly verify each expectation...
mockSomeClass.Verify(mock => mock.DoSomething(), Times.Once());
// ...or verify everything.
// mockSomeClass.VerifyAll();
}
}
In other words, you are verifying that calling MyClass#MyMethod
, your class will definitely call SomeClass#DoSomething
once in that process. Note that you don't need the Times
argument; I was just demonstrating its value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With