views:

64

answers:

1

I have searched the forums and all over the web and have not really seen a straight answer for this.

I have just been introduced to moles and I read that it can mock any .NET class or function call. However, I am wondering if it is possible to use Moles to mock classes that I have created myself.

I have used MOQ before and I have read that some people use both Moles and [insert other mocking framework] in tandem but I was thinking it would be more convenient to stick with just one.

So my central question is this:

Can Moles be used to mock classes/functions that I created myself?

edit: I have seen the process done several times with DateTime and creating a .moles file with the mscorlib in the xml file. Since a user-made class does not come from a .NET library, how is this done?

+1  A: 

Yes, as you said, Moles can mock any .NET type including types created by the end user.


Update:

After installing Moles:

  1. Create a new class library project to hold the unit tests for the code you want to test;
  2. On this project add a reference to the library or executable containing the code that will be under test;
  3. Build the test project in order to copy the referenced library to the local output directory;
  4. Right-click the added reference to invoke context menu where you will be presented with the option to Add Moles Assembly.
João Angelo
In examples I have seen (all of them are about mocking DateTime) and they use moles to create an xml file and change a line to say AssemblyName="mscorlib"Since a user-made class does not come from a .NET library, I am not sure what to do at this point.
Brian