mirror of
https://github.com/Biarity/Sieve.git
synced 2025-10-16 18:36:55 +02:00
Added static filters
This commit is contained in:
@@ -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>
|
||||
|
||||
|
Reference in New Issue
Block a user