Question

When Moles framework is used, it allows any function call to be mocked up. This is aquote from here: http://msdn.microsoft.com/en-us/library/ff798308.aspx

When execution enters a method, such as the DateTime.Now property getter, the Moles framework checks to see whether the test class has defined a detour for that method. If a detour is defined, the framework redirects the call to the detour delegate. If a detour is not defined, the call is directed to the real implementation of the method.

My question is: How do you define a detour in the test class?

FYI: This question addresses how Moles is internally implemented.

Was it helpful?

Solution

You have to create a moles assembly of the assembly that has the method in it that you wish to detour. There are various ways to do this, the easiest of which is to inside your test project right click the reference to the assembly you wish to "mole" and click the "create moles assembly" option. If this doesn't work there are command line options for everything. This moled assembly will have classes that allow you to define detours on them. For example, say you have your typical static data access layer. Defining a detour would look something like this:

MEmployeeDAL.GetEmployeeGuid = (id) => return new MockEmployee();

Check out this blog post for more details: http://blogs.msdn.com/b/kristol/archive/2010/03/07/unit-testing-with-microsoft-moles.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top