Skip to content

Commit

Permalink
test: add StringInOperator test #135
Browse files Browse the repository at this point in the history
  • Loading branch information
alirezanet committed Nov 12, 2023
1 parent 8c0e531 commit 983fe6d
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions test/EntityFrameworkIntegrationTests/Issue135Tests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
Expand Down Expand Up @@ -65,6 +66,29 @@ public void CustomOperator_ShouldGenerateExactSameSqlQuery()

GridifyGlobalConfiguration.CustomOperators.Remove<TestInOperator>();
}

[Fact]
public void CustomOperator_WithoutMapperConvertor_ShouldGenerateExactSameSqlQuery()
{
// arrange
GridifyGlobalConfiguration.EnableEntityFrameworkCompatibilityLayer();
GridifyGlobalConfiguration.CustomOperators.Register<StringInOperator>();

// ReSharper disable once InconsistentNaming (needed for the test)
var Value = new List<string> { "2", "4", "6" };
var expected = _dbContext.Users.Where(q => Value.Contains(q.Name)).ToQueryString();

// act
var actual = new QueryBuilder<User>()
.AddCondition("name #In2 2;4;6")
.Build(_dbContext.Users)
.ToQueryString();

// assert
Assert.Equal(expected, actual);

GridifyGlobalConfiguration.CustomOperators.Remove<StringInOperator>();
}
}

internal class TestInOperator : IGridifyOperator
Expand All @@ -80,6 +104,22 @@ public Expression<OperatorParameter> OperatorHandler()
}
}


class StringInOperator : IGridifyOperator
{
public string GetOperator()
{
return "#In";
}

public Expression<OperatorParameter> OperatorHandler()
{
return (prop, value) => value.ToString()
.Split(";", StringSplitOptions.RemoveEmptyEntries)
.Contains(prop.ToString());
}
}

internal class TestTask
{
public int State { get; set; }
Expand Down

0 comments on commit 983fe6d

Please sign in to comment.