Custom filters/sorts case-insensitivity

This commit is contained in:
Biarity 2018-02-11 13:35:33 +10:00
parent bafee2314e
commit 3068c476e1
5 changed files with 21 additions and 7 deletions

View File

@ -284,7 +284,8 @@ namespace Sieve.Services
private IQueryable<TEntity> ApplyCustomMethod<TEntity>(IQueryable<TEntity> result, string name, object parent, object[] parameters, object[] optionalParameters = null)
{
var customMethod = parent?.GetType()
.GetMethod(name);
.GetMethod(name,
_options.Value.CaseSensitive ? BindingFlags.Default : BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
if (customMethod != null)
{

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>Sieve</id>
<version>1.3.8</version>
<version>1.3.9</version>
<title>Sieve</title>
<authors>Biarity</authors>
<owners>Biarity</owners>
@ -13,7 +13,7 @@
<description>
Sieve is a simple, clean, and extensible framework for .NET Core that adds sorting, filtering, and pagination functionality out of the box. Most common use case would be for serving ASP.NET Core GET queries. Documentation available on GitHub: https://github.com/Biarity/Sieve/
</description>
<releaseNotes>Filter before sort</releaseNotes>
<releaseNotes>Fluent API v1 and case-insensitive operators</releaseNotes>
<copyright>Copyright 2018</copyright>
<tags>aspnetcore filter sort page paginate sieve search</tags>
<dependencies>

View File

@ -87,6 +87,20 @@ namespace SieveUnitTests
Assert.AreEqual(result.First().Id, 1);
Assert.IsTrue(result.Count() == 1);
}
[TestMethod]
public void CustomFiltersWork()
{
var model = new SieveModel()
{
Filters = "Isnew",
};
var result = _processor.ApplyFiltering(model, _posts);
Assert.IsFalse(result.Any(p => p.Id == 0));
Assert.IsTrue(result.Count() == 2);
}
}
}

View File

@ -11,8 +11,7 @@ namespace SieveUnitTests.Services
{
public IQueryable<Post> IsNew(IQueryable<Post> source, string op, string value)
{
var result = source.Where(p => p.LikeCount < 100 &&
p.CommentCount < 5);
var result = source.Where(p => p.LikeCount < 100);
return result;
}

View File

@ -1,6 +1,6 @@
### 1. Pack:
```
dotnet pack Sieve.csproj -c Release -o . /p:PackageVersion=1.3.8
dotnet pack Sieve.csproj -c Release -o . /p:PackageVersion=1.3.9
```
Don't forget to change version since nuget packages are immutable (add one to the nuget current).
@ -13,7 +13,7 @@ Also don't forget updaing `releaseNotes` in nuspec.
### 3. Publish:
```
nuget push Sieve.1.3.8.nupkg API_KEY -Source https://api.nuget.org/v3/index.json
nuget push Sieve.1.3.9.nupkg API_KEY -Source https://api.nuget.org/v3/index.json
```
Replace API_KEY with one you get from nuget's website.
Also don't forget to replace corresponding version.