Gravatar for loebrandy@gmail.com

Question by rloeb, Feb 4, 2017 2:25 PM

Coveo for sitecore within non-IIS hosted integration tests

We are trying to create some integration tests for our sitecore mvc.net project whereby from within MSTEST tests we instantiate a control and call its actions. So far we have sitecore api functionality working for some of our tests despite the non-existence of an http context.

However, we are running into some problems and exceptions with coveo libraries.

Examples:

  1. We find that the methods that are supposed to return coveo field names with hash numbers on the end are returning the wrong numbers. This seems to be because the index names are not fully translated.
  2. Linq provider complains that no user has been provided.

Is there any documentation/guidance for getting the coveo sitecore libraries to behave during integration tests hosted outside of IIS, e.g. injecting in resources etc?

Gravatar for loebrandy@gmail.com

Comment by rloeb, Feb 4, 2017 2:49 PM

Add that we get "CES::SearchServerException: No user has been provided for the search request." I believe this is because somewhere in the coveo libraries the user is retrieved from the (proxied) http session, but here we have none.

1 Reply
Gravatar for flguillemette@coveo.com

Answer by François Lachance-Guillemette, Feb 6, 2017 9:26 AM

Hi @rloeb!

I'm afraid we don't have any documentation to suggest to you about integration tests with Coveo for Sitecore. We would really like to support it, but we have not yet fully explored the possibility so I can't provide any more help than what I know about our UI models.

As you might already know, we configured our models in Sitecore to use the default controller that instantiate a model and then calls the Initialize(Rendering) method on the model.

You could instead try to use a custom controller that allows you to inject a configuration in the model. SearchModel takes a SearchModelConfiguration that has all the dependencies required to run the model.

If you could create a Mock of this configuration, this would allow you to handle your own user and bypass those context limitations.

Though I have not tested it and I am not sure that LINQ queries will be executed since they require a static context.

Good luck with the implementation! I really hope you manage to make it work, let us know if you successfully test it!

Gravatar for loebrandy@gmail.com

Comment by rloeb, Feb 6, 2017 2:01 PM

I have made some progress but am stuck on the issue where the Coveo linq libraries are using the wrong hash# postfix to non-external field names, which is presumably because the wrong host name is being used.

For example, my source name is Coveowebindex - RLOEB00195-taxsearch-rloeb

but I can see the hash#s were derived using Coveowebindex - RLOEB00195

I need to get past this hurdle.

Is there a server-side way I can add a simple plugin/pipeline that will just use a simple string replace on those #'s and replace them with the correct one?

Gravatar for flguillemette@coveo.com

Comment by François Lachance-Guillemette, Feb 6, 2017 2:57 PM

The hashed is computed in the IIndexNamesBuilder associated with the current IProviderIndex. I don't know how these are provided for Coveo in your integration tests, but if you can mock this part, this is what we use for field names with the hash.

Gravatar for loebrandy@gmail.com

Comment by rloeb, Feb 6, 2017 4:30 PM

I'm getting closer. Now I have a result coming back.

But the SearchResultItem is not being properly hydrated when the query returns.

It seems like external fields get hydrated, i.e. fields with no prefix or suffix.

Do you know where the code/class is that maps the response from coveo (i.e. the .Raw collection) to the SearchResultItem (or whatever type is used for T in GetQueryable?

Gravatar for loebrandy@gmail.com

Comment by rloeb, Feb 6, 2017 4:34 PM

Nevermind…I think I have it working.

Gravatar for flguillemette@coveo.com

Comment by François Lachance-Guillemette, Feb 6, 2017 4:43 PM

Could you tell us what you did to make it work? :)

Gravatar for loebrandy@gmail.com

Comment by rloeb, Feb 6, 2017 10:24 PM

Sure…I have to do write up for the team devs anyway so they can run the tests before commits, I'll forward that.

Do you have my email or if I email to Simon he can get it to you? Or post your email here. Thanks

Gravatar for flguillemette@coveo.com

Comment by François Lachance-Guillemette, Feb 6, 2017 10:42 PM

Wow, really cool, an email to Simon would be alright :)

Ask a question