Below is code snippet
ICluster cluster = await _bucketFactory.GetClusterAsync();
IQueryResult result = await cluster.QueryAsync(query, usedQueryOptions);
await foreach (var row in result.Rows)
{
var rowValue = row;
if (row.id == null) continue;
searchResults.Add((string)row.id);
}
return searchResults;
I am using nunit for test case
Snippet of unit test
Mock<IQueryResult<object>> queryResultMock = new Mock<IQueryResult<object>>();
queryResultMock.Setup(m => m.Rows).Returns(rowsList.ToAsyncEnumerable());
// Set up the behavior of the cluster mock
_clustertMock.Setup(c => c.QueryAsync<dynamic>(It.IsAny<string>(), It.IsAny<QueryOptions>()))
.ReturnsAsync(queryResultMock.Object);
// Inject the mocked cluster into the _bucketFactory
_mockDocStoreSdkBucketFactory.Setup(b => b.GetClusterAsync())
.ReturnsAsync(_clustertMock.Object);
// Act
List<string> actualResults = await GetN1qlQueryService().SearchExecuteQueryWithRetryReturnStrings(query, _bucketMock.Object);
// Assert
Assert.AreEqual(1, actualResults.Count);
I am able to get value in IQueryResult result but getting null exception for foreach condition.
Not sure hoe can i mock QueryAsync to avoid this error.