I am trying to unit test code that uses SearchClient.SearchAsync()
method. I am using AutoFixture.AutoMoq nuget package.
Here is what I tried:
mockSearchClient.Setup(msc => msc.SearchAsync<MyModel>(
It.IsAny<string>(),
It.IsAny<SearchOptions>(),
It.IsAny<CancellationToken>()
)).Returns(Task.FromResult(<<PROBLEM HERE>>));
The problem lies in the parameter .Returns(Task.FromResult(<<PROBLEM HERE>>))
part. It expects a concrete object that is returned from the .SearchAsync()
method. According to docs and autocomplete, the method returns Azure.Response
which is an abstract class. So, I cannot new it up. In actuality, the method returns a descendant class Azure.ValueResponse
, which isn't abstract, but is internal to Azure SDK, so also impossible to new up.
So how does one mock the SearchClient.SearchAsync?
P.S. Using Azure.Search.Documents, v11.1.1.0
class foo: Azure.Response {}
), but that didn't work either. If you have a different way to do it, I'd love to try it. – Sluggish