How to mock FindClient search queries in Optimizely?

Vote:
 

Hello,

I am currently working on mocking optimizely search client interface IClient for my unit tests that are using xunit. 
Specfically this statement right here:

  var cmsContent = _client.Search<IContent>()
    .For(query)
    .GetResult();

I have tried using Moq, and NSubstitute but with I cant seem to mock the statement above.

Anyone have any idea how to mock the above statement?

Any help is appreciated. 

#319640
Mar 28, 2024 13:50
Vote:
 

Find relies heavily on extension methods so I don't think you can unit test it easily and effectively. I think you could do a wrapper class for search functionality and mock that in your tests instead 

#319641
Mar 28, 2024 16:09
Vote:
 

Optimizely Find is very hard to write unit tests for.  Instead I keep my search logic separate to my mobel builder logic.  That way I can test everything around the search query even though I can't test the query itself.

#319642
Mar 28, 2024 16:42
Taher.elhares - Mar 31, 2024 9:29
Could you please Elaborate on that? Also, is it possible to show a code snippet?
* 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.