commercetools/commercetools-dotnet-core-sdk

Where-In queries with enum-arrays will generate bad requests

btastic opened this issue · 0 comments

Given the following test cases:

[Fact]
public void ExpressionEnumWhereInList()
{
    List<OrderState> orderStates = new[] { OrderState.Open, OrderState.Complete, OrderState.Confirmed }.ToList();
    Expression<Func<Order, bool>> expression = x => x.OrderState.In(orderStates);
    IQueryPredicateExpressionVisitor queryPredicateExpressionVisitor = this.linqFixture.GetService<IQueryPredicateExpressionVisitor>();
    string result = queryPredicateExpressionVisitor.Render(expression);
    Assert.Equal("orderState in (\"Open\", \"Complete\", \"Confirmed\")", result);
}

[Fact]
public void ExpressionEnumWhereInListValueOf()
{
    List<OrderState> orderStates = new[] { OrderState.Open.valueOf(), OrderState.Complete.valueOf(), OrderState.Confirmed.valueOf() }.ToList();
    Expression<Func<Order, bool>> expression = x => x.OrderState.In(orderStates);
    IQueryPredicateExpressionVisitor queryPredicateExpressionVisitor = this.linqFixture.GetService<IQueryPredicateExpressionVisitor>();
    string result = queryPredicateExpressionVisitor.Render(expression);
    Assert.Equal("orderState in (\"Open\", \"Complete\", \"Confirmed\")", result);
}

[Fact]
public void ExpressionEnumWhereInArray()
{
    OrderState[] orderStates = new[] { OrderState.Open, OrderState.Complete, OrderState.Confirmed };
    Expression<Func<Order, bool>> expression = x => x.OrderState.In(orderStates);
    IQueryPredicateExpressionVisitor queryPredicateExpressionVisitor = this.linqFixture.GetService<IQueryPredicateExpressionVisitor>();
    string result = queryPredicateExpressionVisitor.Render(expression);
    Assert.Equal("orderState in (\"Open\", \"Complete\", \"Confirmed\")", result);
}

[Fact]
public void ExpressionEnumWhereInArrayValueOf()
{
    OrderState[] orderStates = new[] { OrderState.Open.valueOf(), OrderState.Complete.valueOf(), OrderState.Confirmed.valueOf() };
    Expression<Func<Order, bool>> expression = x => x.OrderState.In(orderStates);
    IQueryPredicateExpressionVisitor queryPredicateExpressionVisitor = this.linqFixture.GetService<IQueryPredicateExpressionVisitor>();
    string result = queryPredicateExpressionVisitor.Render(expression);
    Assert.Equal("orderState in (\"Open\", \"Complete\", \"Confirmed\")", result);
}

The tests will all fail with something like this:

image

I already provided a fix, I don't know if this is the right way, but the tests won't fail, and our internal application tests also like this fix.