Testing / mocking EPiServer Find

Vote:
 

Hi,

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.

Thanks

#115862
Jan 20, 2015 15:09
Vote:
 

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.

#115880
Jan 20, 2015 23:22
Vote:
 

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

http://world.episerver.com/blogs/Henrik-Fransas/Dates/2015/1/how-to-do-unit-testing-on-episerver-find/

#116062
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.