Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mocking GetItemLinqQueryable and Extension method ToFeedIterator()

We are using Azure cosmos client V3. For fetching data we are using GetItemLinqQueryable and ToFeedIterator for making it Async. It works well however while mocking/unit testing we are getting error related to ToFeedIterator

Code:

IOrderedQueryable<T> linqQueryable = _container.GetItemLinqQueryable<T>(requestOptions: requestOptions);
var feedIterator = linqQueryable.Where(predicate).ToFeedIterator();

For mocking UnitTestCode Code:

var _mockResponse = new Mock<ItemResponse<Test>>();
mockContainer.Setup(x => x.GetItemLinqQueryable<Test>(It.IsAny<bool>(), It.IsAny<string>(), It.IsAny<QueryRequestOptions>())).Returns(queryable);

It does return 1 records from GetItemLinqQueryable however ToFeedIterator() fails saying System.ArgumentOutOfRangeException: 'ToFeedIterator is only supported on cosmos LINQ query operations Parameter name: linqQuery'

like image 312
Mandar Nagarkar Avatar asked Oct 16 '22 10:10

Mandar Nagarkar


1 Answers

I ran into this same issue. Check out the comments in this github issue 893 in the azure-cosmos-dotnet-v3 repo. I ended up following approach suggested here.

like image 181
Scott Avatar answered Nov 15 '22 21:11

Scott