mirror of
https://github.com/Biarity/Sieve.git
synced 2024-11-22 13:32:33 +01:00
Added static filters
This commit is contained in:
parent
b73f748dba
commit
709e3d6fae
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -436,8 +436,8 @@ namespace Sieve.Services
|
|||||||
var customMethod = parent?.GetType()
|
var customMethod = parent?.GetType()
|
||||||
.GetMethodExt(name,
|
.GetMethodExt(name,
|
||||||
Options.Value.CaseSensitive
|
Options.Value.CaseSensitive
|
||||||
? BindingFlags.Default
|
? BindingFlags.Default | BindingFlags.Static
|
||||||
: BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance,
|
: BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static,
|
||||||
typeof(IQueryable<TEntity>));
|
typeof(IQueryable<TEntity>));
|
||||||
|
|
||||||
|
|
||||||
|
@ -848,5 +848,29 @@ namespace SieveUnitTests
|
|||||||
Assert.Equal(1, resultCount);
|
Assert.Equal(1, resultCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(@"HasInTitleStatic@=Tale", 1)]
|
||||||
|
[InlineData(@"HasInTitleStatic@=Tail", 0)]
|
||||||
|
public void CanFilterWithStaticFilters(string filter, int expectedMatches)
|
||||||
|
{
|
||||||
|
var posts = new List<Post>
|
||||||
|
{
|
||||||
|
new()
|
||||||
|
{
|
||||||
|
Id = 1,
|
||||||
|
Title = "A Tale of Two Cities",
|
||||||
|
}
|
||||||
|
}.AsQueryable();
|
||||||
|
|
||||||
|
var model = new SieveModel
|
||||||
|
{
|
||||||
|
Filters = filter
|
||||||
|
};
|
||||||
|
|
||||||
|
var result = _processor.Apply(model, posts);
|
||||||
|
var resultCount = result.Count();
|
||||||
|
Assert.Equal(expectedMatches, resultCount);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,13 @@ namespace SieveUnitTests.Services
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IQueryable<IPost> HasInTitleStatic(IQueryable<Post> source, string op, string[] values)
|
||||||
|
{
|
||||||
|
var result = source.Where(p => p.Title.Contains(values[0]));
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public IQueryable<IComment> IsNew(IQueryable<IComment> source, string op, string[] values)
|
public IQueryable<IComment> IsNew(IQueryable<IComment> source, string op, string[] values)
|
||||||
{
|
{
|
||||||
var result = source.Where(c => c.DateCreated > DateTimeOffset.UtcNow.AddDays(-2));
|
var result = source.Where(c => c.DateCreated > DateTimeOffset.UtcNow.AddDays(-2));
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net5.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<RootNamespace></RootNamespace>
|
<RootNamespace></RootNamespace>
|
||||||
<NoWarn>CS0649;CS0169</NoWarn>
|
<NoWarn>CS0649;CS0169</NoWarn>
|
||||||
<NukeRootDirectory>..</NukeRootDirectory>
|
<NukeRootDirectory>..</NukeRootDirectory>
|
||||||
|
Loading…
Reference in New Issue
Block a user