Testing / mocking EPiServer Find



I'm in the process writing unit tests for my MVC Controllers which uses EPiServer Find.

Has anyone tried to write unit tests around the GetContentResult extension? From what I understand it is not possible to mock extensions with MOQ.  Any ideas how to make the code testable?

Much appreciated.


Jan 20, 2015 15:09

If I were you, I'd isolate away the Find queries in your own ISearchService/SearchService or something, and inject that into your controllers. That way, you don't end up testing Find itself in any way, nor do you have to mock it. You simply mock your own wrapper of it, and inject that into your controllers.

Often, I see this as a good way to reuse queries over multiple places. And you can package all your search logic in there, which the controller really isn't interested in knowing ("should I search in field A and B, or include C and D too?").

Also, you can let your controllers just gather data and stack them into a view model, as they are intended to - and not do any "business logic" (as a search is, in a way) at all.

Jan 20, 2015 23:22

I have just publish a blog post on how tho do this, please read it and see if it might get you in the right direction


Jan 22, 2015 13:21
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.