Document & test multiple values for 2.2.0. Closes #46

This commit is contained in:
Biarity 2018-11-30 09:08:39 +10:00
parent 2d5fc0d232
commit c818267526
5 changed files with 37 additions and 7 deletions

View File

@ -90,7 +90,7 @@ And `SieveCustomFilterMethods`:
```C#
public class SieveCustomFilterMethods : ISieveCustomFilterMethods
{
public IQueryable<Post> IsNew(IQueryable<Post> source, string op, string value) // The method is given the {Operator} & {Value}
public IQueryable<Post> IsNew(IQueryable<Post> source, string op, string[] values) // The method is given the {Operator} & {Value}
{
var result = source.Where(p => p.LikeCount < 100 &&
p.CommentCount < 5);
@ -181,6 +181,15 @@ It is recommended that you write exception-handling middleware to globally handl
### Example project
You can find an example project incorporating most Sieve concepts in [SieveTests](https://github.com/Biarity/Sieve/tree/master/SieveTests).
## Upgrading to v2.2.0
2.2.0 introduced OR logic for filter values. This means your custom filters will need to accept multiple values rather than just the one.
* In all your custom filter methods, change the last argument to be a `string[] values` instead of `string value`
* The first value can then be found to be `values[0]` rather than `value`
* Multiple values will be present if the client uses OR logic
## Upgrading from v1.* to v2.*
* Changes to the `SieveProcessor` API:

View File

@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>2.1.5</Version>
<Version>2.2</Version>
<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>
<Copyright>Copyright 2018</Copyright>
@ -10,7 +10,7 @@
<PackageProjectUrl>https://github.com/Biarity/Sieve</PackageProjectUrl>
<PackageIconUrl>https://emojipedia-us.s3.amazonaws.com/thumbs/240/twitter/120/alembic_2697.png</PackageIconUrl>
<RepositoryUrl></RepositoryUrl>
<PackageReleaseNotes>Fix custom sort methods not working after 2.1</PackageReleaseNotes>
<PackageReleaseNotes>Added OR logic for value fields, allowed escaping special characters</PackageReleaseNotes>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Authors>Biarity</Authors>

View File

@ -6,7 +6,7 @@ namespace SieveTests.Services
{
public class SieveCustomFilterMethods : ISieveCustomFilterMethods
{
public IQueryable<Post> IsNew(IQueryable<Post> source, string op, string value)
public IQueryable<Post> IsNew(IQueryable<Post> source, string op, string[] values)
=> source.Where(p => p.LikeCount < 100 && p.CommentCount < 5);
}
}

View File

@ -172,6 +172,20 @@ namespace SieveUnitTests
Assert.IsTrue(result.Count() == 3);
}
[TestMethod]
public void CustomFiltersWithOperatorsWork()
{
var model = new SieveModel()
{
Filters = "HasInTitle==A",
};
var result = _processor.Apply(model, _posts);
Assert.IsTrue(result.Any(p => p.Id == 0));
Assert.IsTrue(result.Count() == 1);
}
[TestMethod]
public void CustomFiltersMixedWithUsualWork1()
{

View File

@ -7,21 +7,28 @@ namespace SieveUnitTests.Services
{
public class SieveCustomFilterMethods : ISieveCustomFilterMethods
{
public IQueryable<Post> IsNew(IQueryable<Post> source, string op, string value)
public IQueryable<Post> IsNew(IQueryable<Post> source, string op, string[] values)
{
var result = source.Where(p => p.LikeCount < 100);
return result;
}
public IQueryable<Comment> IsNew(IQueryable<Comment> source, string op, string value)
public IQueryable<Post> HasInTitle(IQueryable<Post> source, string op, string[] values)
{
var result = source.Where(p => p.Title.Contains(values[0]));
return result;
}
public IQueryable<Comment> IsNew(IQueryable<Comment> source, string op, string[] values)
{
var result = source.Where(c => c.DateCreated > DateTimeOffset.UtcNow.AddDays(-2));
return result;
}
public IQueryable<Comment> TestComment(IQueryable<Comment> source, string op, string value)
public IQueryable<Comment> TestComment(IQueryable<Comment> source, string op, string[] values)
{
return source;
}