Mocking aids testing. How or which thing to mock depends on which part of code is the code under test and which classes are the dependencies. Understanding dependency injection helps. As you implied, not all designs are easily testable.
Can you express a test case in the following form?
Given <initial condition>
When <action>
Then <expected result>
This will help me understand what you are trying to test.
And I also need to understand which class is the code under test and which class is the dependency. I am also unclear which class contains the InsertOnSubmit method.
Let's say you have a
public class Foo{
public void Save(IContext context){ context.SubmitChanges();}
...}
And you wish to do the following test
Given a Foo, which depends on an IContext object
When we call foo.Save()
Then we expect that the contextObject.SubmitChanges is called.
Then your code under test is Foo.Save(IContext context). and your dependency is IContext. You can mock your IContext object and do two very cool things: 1) make sure that it pretends to act in certain ways, 2) verify that it has been used in certain ways.
Notice, however, this mocking business has some challenges. Your context object must be an interface or abstract class to be mocked by MOQ. There are tools that can mock concrete objects. But MOQ is not one of them.
So regarding those methods like Save() that return void. What you will want to do is mock the objects on which they depend, and test that those objects were used as expected. If the class you are testing is both the class under test and contains also the method you are verififying, there is a way to use MOQ to do that. In other words, to call the REAL implementation of Add(), and verify that another method in that same class is called when Add is called. This post illustrates what I am talking about
http://stackoverflow.com/questions/2462602/moq-how-to-mock-a-function-call-on-a-concrete-object
There were a lot of ideas there. This stuff is cool. So don't get discouraged. Give us a real test case and we can help you see how to do it. But we first need to know what your are testing.
regards,
David Kreth Allen
--
David Kreth Allen
http://codecontracts.info