我正在使用单元测试来测试DocumentDBRepository课程。我按照这篇文章作为 SQL 查询用例的示例。但它显示错误
消息:System.InvalidCastException:无法将类型“System.Linq.EnumerableQuery”的对象转换为类型“Microsoft.Azure.Documents.Linq.IDocumentQuery”
这是我的DocumentDBRepository课程代码
private IDocumentQuery<T> GetQueryBySQL(string queryStr)
{
var uri = UriFactory.CreateDocumentCollectionUri(_databaseId, _collectionId);
var feedOptions = new FeedOptions { MaxItemCount = -1, EnableCrossPartitionQuery = true };
IQueryable<T> filter = _client.CreateDocumentQuery<T>(uri, queryStr, feedOptions);
IDocumentQuery<T> query = filter.AsDocumentQuery();
return query;
}
public async Task<IEnumerable<T>> RunQueryAsync(string queryString)
{
IDocumentQuery<T> query = GetQueryBySQL(queryString);
List<T> results = new List<T>();
while (query.HasMoreResults)
{
results.AddRange(await query.ExecuteNextAsync<T>());
}
return results;
}
Run Code Online (Sandbox Code Playgroud)
这是我的测试类的代码
public async virtual Task Test_GetEntitiesAsyncBySQL()
{
var id …Run Code Online (Sandbox Code Playgroud)