mirror of
https://github.com/Biarity/Sieve.git
synced 2025-07-27 04:33:23 +02:00
CustomMethods in testing
This commit is contained in:
20
SieveTests/Services/SieveCustomFilterMethodsOfPosts.cs
Normal file
20
SieveTests/Services/SieveCustomFilterMethodsOfPosts.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Sieve.Services;
|
||||
using SieveTests.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SieveTests.Services
|
||||
{
|
||||
public class SieveCustomFilterMethodsOfPosts : ISieveCustomFilterMethods<Post>
|
||||
{
|
||||
public IQueryable<Post> IsNew(IQueryable<Post> source)
|
||||
{
|
||||
var result = source.Where(p => p.LikeCount < 100 &&
|
||||
p.CommentCount < 5);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
23
SieveTests/Services/SieveCustomSortMethodsOfPosts - Copy.cs
Normal file
23
SieveTests/Services/SieveCustomSortMethodsOfPosts - Copy.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Sieve.Services;
|
||||
using SieveTests.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SieveTests.Services
|
||||
{
|
||||
public class SieveCustomSortMethodsOfPosts : ISieveCustomSortMethods<Post>
|
||||
{
|
||||
public IQueryable<Post> Popularity(IQueryable<Post> source, bool useThenBy, bool desc)
|
||||
{
|
||||
var result = useThenBy ?
|
||||
((IOrderedQueryable<Post>)source).ThenBy(p => p.LikeCount) :
|
||||
source.OrderBy(p => p.LikeCount)
|
||||
.ThenBy(p => p.CommentCount)
|
||||
.ThenBy(p => p.DateCreated);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
@@ -12,6 +12,7 @@ using Microsoft.Extensions.Options;
|
||||
using Sieve.Models;
|
||||
using Sieve.Services;
|
||||
using SieveTests.Entities;
|
||||
using SieveTests.Services;
|
||||
|
||||
namespace SieveTests
|
||||
{
|
||||
@@ -36,6 +37,8 @@ namespace SieveTests
|
||||
|
||||
|
||||
//services.AddScoped<ISieveProcessor, SieveProcessor>();
|
||||
services.AddScoped<ISieveCustomSortMethods<Post>, SieveCustomSortMethodsOfPosts>();
|
||||
services.AddScoped<ISieveCustomFilterMethods<Post>, SieveCustomFilterMethodsOfPosts>();
|
||||
services.AddScoped<ISieveProcessor<Post>, SieveProcessor<Post>>();
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user