Added static filters

This commit is contained in:
Michael Buchoff 2024-05-27 16:11:10 -04:00
parent b73f748dba
commit 709e3d6fae
6 changed files with 37 additions and 6 deletions

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>

View File

@ -436,8 +436,8 @@ namespace Sieve.Services
var customMethod = parent?.GetType()
.GetMethodExt(name,
Options.Value.CaseSensitive
? BindingFlags.Default
: BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance,
? BindingFlags.Default | BindingFlags.Static
: BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static,
typeof(IQueryable<TEntity>));

View File

@ -847,6 +847,30 @@ namespace SieveUnitTests
Assert.NotNull(entry);
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);
}
}
}

View File

@ -54,6 +54,13 @@ namespace SieveUnitTests.Services
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)
{
var result = source.Where(c => c.DateCreated > DateTimeOffset.UtcNow.AddDays(-2));

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

View File

@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace></RootNamespace>
<NoWarn>CS0649;CS0169</NoWarn>
<NukeRootDirectory>..</NukeRootDirectory>