Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Damion 90 posts 324 karma points
    Jul 28, 2020 @ 09:17
    Damion
    0

    How to mock Examine search results

    I have a test where I create a mock Examine search result and test some code which should run if there are any results

    line of code I need to test:

    if (results.Any())
    {
        ...do stuff
    }
    

    And in the test:

    private Mock<ISearchResults> _mockSearchResults;
    

    in the setup:

    _mockSearchResults = new Mock<ISearchResults>();
    

    At this point the mock results do not contain anything so if statement won't be true, I'm guessing I need to add a search result item to the results but I'm not sure how to, or if that's even correct. Here's what I was thinking, but it gives the error 'Invalid setup on an extension method' :

    _mockSearchResults.Setup(x => x.Append(_mockSearchResult.Object)).Returns( _mockSearchResults.Object );
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies