This is the query I want to mock:
var readRecords = elastic.Search<GroupRecord>(s => s
.Index(indexName)
.Query(q => q.
QueryString(qs => qs.Query("*"))));
and this is the actual Moq
var groupResp = new Mock<ISearchResponse<GroupRecord>>();
var groupRecords = new[]
{
new GroupRecord
{
GroupName = "blablabla"
}
};
groupResp.SetupGet(x => x.Documents).Returns(groupRecords);
ElasticClientMock.Setup(ec => ec.Search(It.IsAny<Func<SearchDescriptor<GroupRecord>, SearchDescriptor<GroupRecord>>>())).Returns(groupResp.Object);
On NEST1.0 and ElasticSearch1.0 the query was returning all (1) documents. On the new NEST2.0 and ElasticSearch2.0 my readRecords
is null
.
Do you know why?
EDIT
On a real environment (no mocking) the query returns all the documents as expected
I think the problem is in the Setup. The following line:
ElasticClientMock.Setup(ec => ec.Search(It.IsAny<Func<SearchDescriptor<GroupRecord>, SearchDescriptor<GroupRecord>>>())).Returns(groupResp.Object);
Mock is looking for a Func<> with two SearchDescriptor
objects, which it was in NEST1. Now, I think the signature for Search is a Func<> with one SearchDescriptor
and one ISearchRequest
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.