case insensitive support.
This commit is contained in:
parent
1ceb75e945
commit
353a7401ce
@ -5,5 +5,6 @@
|
||||
string Path { get; set; }
|
||||
object Value { get; set; }
|
||||
bool? Not { get; set; }
|
||||
bool? CaseInsensitive { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ namespace PoweredSoft.DynamicQuery.Test
|
||||
public string Path { get; set; } = "FirstName";
|
||||
public object Value { get; set; } = "Chuck";
|
||||
public bool? Not { get; set; }
|
||||
public bool? CaseInsensitive { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -38,6 +39,8 @@ namespace PoweredSoft.DynamicQuery.Test
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Fact]
|
||||
public void SimpleFilter()
|
||||
{
|
||||
@ -64,6 +67,33 @@ namespace PoweredSoft.DynamicQuery.Test
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SimpleFilterCaseInsensitive()
|
||||
{
|
||||
MockContextFactory.SeedAndTestContextFor("FilterTests_SimpleFilterCaseInsensitive", TestSeeders.SimpleSeedScenario, ctx =>
|
||||
{
|
||||
var resultShouldMatch = ctx.Items.Where(t => t.Name.ToLower().EndsWith("Cables".ToLower())).ToList();
|
||||
|
||||
var criteria = new QueryCriteria()
|
||||
{
|
||||
Filters = new List<IFilter>
|
||||
{
|
||||
new SimpleFilter
|
||||
{
|
||||
Path = "Name",
|
||||
Type = FilterType.EndsWith,
|
||||
Value = "Cables",
|
||||
CaseInsensitive = true
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var queryHandler = new QueryHandler(Enumerable.Empty<IQueryInterceptorProvider>());
|
||||
var result = queryHandler.Execute(ctx.Items, criteria);
|
||||
Assert.Equal(resultShouldMatch, result.Data);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Fact]
|
||||
|
@ -18,6 +18,7 @@ namespace PoweredSoft.DynamicQuery
|
||||
public FilterType Type { get; set; }
|
||||
public string Path { get; set; }
|
||||
public object Value { get; set; }
|
||||
public bool? CaseInsensitive { get; set; }
|
||||
}
|
||||
|
||||
public class CompositeFilter : ICompositeFilter
|
||||
|
@ -21,7 +21,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.0.0" />
|
||||
<PackageReference Include="PoweredSoft.Data" Version="2.0.0" />
|
||||
<PackageReference Include="PoweredSoft.DynamicLinq" Version="1.1.11" />
|
||||
<PackageReference Include="PoweredSoft.DynamicLinq" Version="1.1.12" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -366,6 +366,13 @@ namespace PoweredSoft.DynamicQuery
|
||||
protected virtual void ApplySimpleFilter<TSource>(WhereBuilder whereBuilder, ISimpleFilter filter)
|
||||
{
|
||||
var resolvedConditionOperator = ResolveConditionOperatorFrom(filter.Type);
|
||||
|
||||
if (filter.CaseInsensitive == true)
|
||||
{
|
||||
filter.Path += ".ToLower()";
|
||||
filter.Value = $"{filter.Value}"?.ToLower();
|
||||
}
|
||||
|
||||
whereBuilder.Compare(filter.Path, resolvedConditionOperator, filter.Value, and: filter.And == true, negate: filter.Not == true);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user