mirror of
https://github.com/Biarity/Sieve.git
synced 2024-11-22 05:22:57 +01:00
Added static filters
This commit is contained in:
parent
b73f748dba
commit
709e3d6fae
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -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>));
|
||||
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<RootNamespace></RootNamespace>
|
||||
<NoWarn>CS0649;CS0169</NoWarn>
|
||||
<NukeRootDirectory>..</NukeRootDirectory>
|
||||
|
Loading…
Reference in New Issue
Block a user