so the code under test is:
var query = _documentClient.CreateDocumentQuery<TEntity>(CollectionUri, GetFeedOptions()).AsQueryable();
foreach (var filter in filters)
{
query = query.Where(filter);
}
It throws an exception at query = query.Where(filter);
where my filter is a valid Expression.
The code works at runtime, and compiles, but my unit tests are throwing the exception:
Value cannot be null.
Parameter name: arg0
at System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method, Expression arg0, Expression arg1)
at System.Linq.Queryable.Where[TSource](IQueryable`1 source, Expression`1 predicate)
at .DataAccess.Core.CosmoDbRepositoryBase`1.GetAsync(IEnumerable`1 filters, Int32 take, Boolean getAll) in C:\...DataAccess\Core\CosmoDbRepositoryBase.cs:line 223
However, my arg0
is not null
My Mock, using
XUnit
& NSubstitute
, looks like this:
IDocumentClient _documentClient = Substitute.For<IDocumentClient>();
var document = new Document();
document.LoadFrom(new JsonTextReader(new StringReader(JsonConvert.SerializeObject(TestDataFactory.GetFakeResourceEntity()))));
var response = new ResourceResponse<Document>(document);
_documentClient.CreateDocumentAsync(Arg.Any<Uri>(), Arg.Any<object>(), Arg.Any<RequestOptions>(), Arg.Any<bool>(), Arg.Any<CancellationToken>())
.Returns(Task.FromResult(response));