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' :
Rather than mock your search results, you can fake them like this:
private ISearchResults GetSearchResults()
{
var fakeResults = new List<ISearchResult>();
for (var idx = 0; idx < 5; idx++)
{
var result = new SearchResult(idx.ToString(), idx, () => { return new Dictionary<string, List<string>>(); });
fakeResults.Add(result);
}
return new LuceneSearchResults(fakeResults, fakeResults.Count);
}
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:
And in the test:
in the setup:
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' :
Rather than mock your search results, you can fake them like this:
is working on a reply...