interface type fixes & unit test improvements

This commit is contained in:
Hasan Manzak
2023-02-23 01:11:34 +03:00
parent b73f748dba
commit 7ec97810f7
17 changed files with 884 additions and 586 deletions

View File

@@ -16,62 +16,20 @@ namespace SieveUnitTests.Services
{
}
public SieveOptions ExposedOptions => new SieveOptions()
{
IgnoreNullsOnNotEqual = Options.Value.IgnoreNullsOnNotEqual,
CaseSensitive = Options.Value.CaseSensitive,
DefaultPageSize = Options.Value.DefaultPageSize,
DisableNullableTypeExpressionForSorting = Options.Value.DisableNullableTypeExpressionForSorting,
MaxPageSize = Options.Value.MaxPageSize,
ThrowExceptions = Options.Value.ThrowExceptions,
};
protected override SievePropertyMapper MapProperties(SievePropertyMapper mapper)
{
mapper.Property<Post>(p => p.ThisHasNoAttributeButIsAccessible)
.CanSort()
.CanFilter()
.HasName("shortname");
mapper.Property<Post>(p => p.TopComment.Text)
.CanFilter();
mapper.Property<Post>(p => p.TopComment.Id)
.CanSort();
mapper.Property<Post>(p => p.OnlySortableViaFluentApi)
.CanSort();
mapper.Property<Post>(p => p.TopComment.Text)
.CanFilter()
.HasName("topc");
mapper.Property<Post>(p => p.FeaturedComment.Text)
.CanFilter()
.HasName("featc");
mapper
.Property<Post>(p => p.DateCreated)
.CanSort()
.HasName("CreateDate");
// interfaces
mapper.Property<IPost>(p => p.ThisHasNoAttributeButIsAccessible)
.CanSort()
.CanFilter()
.HasName("shortname");
mapper.Property<IPost>(p => p.TopComment.Text)
.CanFilter();
mapper.Property<IPost>(p => p.TopComment.Id)
.CanSort();
mapper.Property<IPost>(p => p.OnlySortableViaFluentApi)
.CanSort();
mapper.Property<IPost>(p => p.TopComment.Text)
.CanFilter()
.HasName("topc");
mapper.Property<IPost>(p => p.FeaturedComment.Text)
.CanFilter()
.HasName("featc");
mapper
.Property<IPost>(p => p.DateCreated)
.CanSort()
.HasName("CreateDate");
SieveConfigurationForPost.ConfigureStatic(mapper);
SieveConfigurationForIPost.ConfigureStatic(mapper);
return mapper;
}

View File

@@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Linq.Expressions;
using Sieve.Services;
using SieveUnitTests.Abstractions.Entity;
using SieveUnitTests.Entities;
@@ -8,9 +9,14 @@ namespace SieveUnitTests.Services
{
public class SieveCustomFilterMethods : ISieveCustomFilterMethods
{
internal static readonly Expression<Func<Post, bool>> IsNewFilterForPost = post => post.LikeCount < 100;
internal static readonly Expression<Func<IPost, bool>> IsNewFilterForIPost = post => post.LikeCount < 100;
internal static readonly Expression<Func<Comment, bool>> IsNewFilterForComment = comment => comment.DateCreated > DateTimeOffset.UtcNow.AddDays(-2);
internal static readonly Expression<Func<IComment, bool>> IsNewFilterForIComment = comment => comment.DateCreated > DateTimeOffset.UtcNow.AddDays(-2);
public IQueryable<Post> IsNew(IQueryable<Post> source, string op, string[] values)
{
var result = source.Where(p => p.LikeCount < 100);
var result = source.Where(IsNewFilterForPost);
return result;
}
@@ -24,7 +30,7 @@ namespace SieveUnitTests.Services
public IQueryable<Comment> IsNew(IQueryable<Comment> source, string op, string[] values)
{
var result = source.Where(c => c.DateCreated > DateTimeOffset.UtcNow.AddDays(-2));
var result = source.Where(IsNewFilterForComment);
return result;
}
@@ -42,7 +48,7 @@ namespace SieveUnitTests.Services
public IQueryable<IPost> IsNew(IQueryable<IPost> source, string op, string[] values)
{
var result = source.Where(p => p.LikeCount < 100);
var result = source.Where(IsNewFilterForIPost);
return result;
}
@@ -56,7 +62,7 @@ namespace SieveUnitTests.Services
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(IsNewFilterForIComment);
return result;
}