Skip to content

Commit

Permalink
Fixes explicit bool.
Browse files Browse the repository at this point in the history
  • Loading branch information
matteobortolazzo committed May 2, 2019
1 parent 3216f17 commit 94f19c3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/CouchDB.Driver/ExpressionVisitors/WhereExpressionVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ protected override Expression VisitMethodCall(MethodCallExpression m)
return base.VisitMethodCall(m);
}

protected override Expression VisitBinary(BinaryExpression expression)
{
if (expression.Right is ConstantExpression c && c.Type == typeof(bool) &&
(expression.NodeType == ExpressionType.Equal || expression.NodeType == ExpressionType.NotEqual))
{
return expression;
}
return base.VisitBinary(expression);
}

protected override Expression VisitMember(MemberExpression expression)
{
if (IsWhereBooleanExpression(expression))
Expand Down
12 changes: 12 additions & 0 deletions tests/CouchDB.Driver.UnitTests/Find/Find_Selector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,17 @@ public void Variable_Bool_ExplicitFalse()
var json = rebels.Where(r => r.IsJedi == false).OrderBy(r => r.IsJedi).ToString();
Assert.Equal(@"{""selector"":{""isJedi"":false},""sort"":[""isJedi""]}", json);
}
[Fact]
public void Variable_Bool_ExplicitNotTrue()
{
var json = rebels.Where(r => r.IsJedi != true).OrderBy(r => r.IsJedi).ToString();
Assert.Equal(@"{""selector"":{""isJedi"":{""$ne"":true}},""sort"":[""isJedi""]}", json);
}
[Fact]
public void Variable_Bool_ExplicitNotFalse()
{
var json = rebels.Where(r => r.IsJedi != false).OrderBy(r => r.IsJedi).ToString();
Assert.Equal(@"{""selector"":{""isJedi"":{""$ne"":false}},""sort"":[""isJedi""]}", json);
}
}
}

0 comments on commit 94f19c3

Please sign in to comment.