I want to test the following logic (this is obviously a stripped-down version of my method):
public void myPublicMethod(params) {
if(some_condition)
privateMethod1();
else
privateMethod2();
}
I have all of the other dependencies in the method mocked out, and I've set this up so that I can guarantee that some_condition is true. What I want to do is verify that my privateMethod1() is called exactly once, and privateMethod2() is not called at all. Is this possible to do with Moq?
Here are some notes on the issue:
Any thoughts? Thanks in advance. I'm willing to accept that this can't be done, but I'd like to know one way or another.
Don't test private methods. They are private implementation details of the class. You should only test the results of executing public methods. As long as your results come out as expected, you shouldn't care how the result is obtained.
Building tests on private methods will lead to brittle tests that break easily when you refactor private implementations (for performance or other reasons).