7

Only seen two questions on here for this, one wasn't answered and one was an unusable answer (maybe I just didn't get it). I want to mock this:

var eventsFeed = this.documentClient.CreateDocumentQuery(this.collectionUri, 
sqlExpression, feedOptions).AsDocumentQuery();
var events = await eventsFeed.ExecuteNextAsync(cancellationToken); 

I only seem to be able to get this error:

Unable to cast object of type 'System.Linq.EnumerableQuery to type 'Microsoft.Azure.Documents.Linq.IDocumentQuery

There is a possible answer here:

Unable to cast object of type 'System.Linq.EnumerableQuery to type 'Microsoft.Azure.Documents.Linq.IDocumentQuery

but I can't find the type JTokenEx used in the example and there is no explanation of how to write the mock code?

Ideally I'd like to return some mock results so that I can test the ExecuteNextAsync.

For reference here's the other question I found relating to it but again it wasn't answered:

How to (should I) mock DocumentClient for DocumentDb unit testing?

Any help would be greatly appreciated. Thanks

Jim Brown
  • 71
  • 3
  • The `JToken` I know comes from `NewtonSoft.Json`, it's likely that the OP just used that as an example class – Camilo Terevinto Jan 23 '18 at 15:44
  • Thanks, I did try it using just JToken but then I didn't know how to construct the class properly and there was no example of that bit. – Jim Brown Jan 23 '18 at 16:18
  • The eventsFeed results in a IDocumentQuery, I tried replacing JToken with dynamic but that gives an error "Cannot implement a dynamic interface". – Jim Brown Jan 23 '18 at 16:24
  • I answered the previous question. Check to see if that answer applied to your problem as well. https://stackoverflow.com/a/48432085/5233410 – Nkosi Feb 08 '18 at 21:35

0 Answers0