public class TestEntity : Entity
|
{
|
} public static class MongoBugs
|
{
|
[Fact]
|
public static void TestMongoIQueryableBug()
|
{
|
var mongoDb = new MongoClient(new MongoClientSettings
|
{
|
ServerSelectionTimeout = TimeSpan.FromMilliseconds(0)
|
}).GetDatabase("admin");
|
var expression = CreateGuidFilterExpression(nameof(TestEntity.Id), Guid.Empty);
|
try
|
{
|
mongoDb.GetCollection<TestEntity>(nameof(TestEntity)).AsQueryable().Where(expression).First();
|
}
|
catch (Exception ex)
|
{
|
ex.Should().BeAssignableTo<ArgumentNullException>();
|
}
|
}
|
|
private static Expression<Func<TestEntity, bool>> CreateGuidFilterExpression(string propertyName,
|
Guid value)
|
{
|
// expression input parameter
|
var entityParameter = Expression.Parameter(typeof(TestEntity));
|
return
|
// parameter.[propertyName] == .Constant(value) expression
|
Expression.Lambda<Func<TestEntity, bool>>(
|
Expression.Equal(Expression.Property(entityParameter, propertyName),
|
Expression.Constant(value)),
|
entityParameter);
|
}
|
}
|