mirror of
https://github.com/Biarity/Sieve.git
synced 2025-07-26 12:13:28 +02:00
Fix for Issue #19
This commit is contained in:
@@ -1,12 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Sieve.Attributes;
|
||||
|
||||
namespace SieveUnitTests.Entities
|
||||
namespace SieveUnitTests.Entities
|
||||
{
|
||||
public class Comment
|
||||
public class Comment
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
|
@@ -1,12 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Sieve.Attributes;
|
||||
|
||||
namespace SieveUnitTests.Entities
|
||||
{
|
||||
public class Post
|
||||
public class Post
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
|
@@ -1,20 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Sieve.Exceptions;
|
||||
using Sieve.Models;
|
||||
using Sieve.Services;
|
||||
using SieveUnitTests.Entities;
|
||||
using SieveUnitTests.Services;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using Sieve.Exceptions;
|
||||
|
||||
namespace SieveUnitTests
|
||||
{
|
||||
[TestClass]
|
||||
public class General
|
||||
{
|
||||
private SieveProcessor _processor;
|
||||
private IQueryable<Post> _posts;
|
||||
private readonly SieveProcessor _processor;
|
||||
private readonly IQueryable<Post> _posts;
|
||||
|
||||
public General()
|
||||
{
|
||||
@@ -43,7 +43,7 @@ namespace SieveUnitTests
|
||||
},
|
||||
new Post() {
|
||||
Id = 3,
|
||||
Title = "3",
|
||||
Title = "D",
|
||||
LikeCount = 3,
|
||||
IsDraft = true
|
||||
},
|
||||
@@ -86,11 +86,10 @@ namespace SieveUnitTests
|
||||
};
|
||||
|
||||
var result = _processor.Apply(model, _posts);
|
||||
|
||||
|
||||
Assert.IsTrue(result.Count() == 2);
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void CanSortBools()
|
||||
{
|
||||
@@ -112,14 +111,12 @@ namespace SieveUnitTests
|
||||
Filters = "LikeCount==50",
|
||||
};
|
||||
|
||||
Console.WriteLine(model.FiltersParsed.First().Value);
|
||||
Console.WriteLine(model.FiltersParsed.First().Operator);
|
||||
Console.WriteLine(model.FiltersParsed.First().OperatorParsed);
|
||||
Console.WriteLine(model.FiltersParsed[0].Value);
|
||||
Console.WriteLine(model.FiltersParsed[0].Operator);
|
||||
Console.WriteLine(model.FiltersParsed[0].OperatorParsed);
|
||||
|
||||
var result = _processor.Apply(model, _posts);
|
||||
|
||||
|
||||
|
||||
Assert.AreEqual(result.First().Id, 1);
|
||||
Assert.IsTrue(result.Count() == 1);
|
||||
}
|
||||
@@ -169,15 +166,12 @@ namespace SieveUnitTests
|
||||
};
|
||||
|
||||
var result = _processor.Apply(model, _posts);
|
||||
var entry = result.FirstOrDefault();
|
||||
var resultCount = result.Count();
|
||||
|
||||
Assert.AreEqual(result.First().Id, 3);
|
||||
Assert.IsTrue(result.Count() == 1);
|
||||
Assert.IsNotNull(entry);
|
||||
Assert.AreEqual(1, resultCount);
|
||||
Assert.AreEqual(3, entry.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//Sorts = "LikeCount",
|
||||
//Page = 1,
|
||||
//PageSize = 10
|
||||
//
|
||||
}
|
@@ -1,20 +1,18 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Sieve.Models;
|
||||
using Sieve.Services;
|
||||
using SieveUnitTests.Entities;
|
||||
using SieveUnitTests.Services;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using Sieve.Exceptions;
|
||||
|
||||
namespace SieveUnitTests
|
||||
{
|
||||
[TestClass]
|
||||
[TestClass]
|
||||
public class Mapper
|
||||
{
|
||||
private ApplicationSieveProcessor _processor;
|
||||
private IQueryable<Post> _posts;
|
||||
private readonly ApplicationSieveProcessor _processor;
|
||||
private readonly IQueryable<Post> _posts;
|
||||
|
||||
public Mapper()
|
||||
{
|
||||
@@ -44,7 +42,7 @@ namespace SieveUnitTests
|
||||
},
|
||||
}.AsQueryable();
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void MapperWorks()
|
||||
{
|
||||
|
@@ -2,19 +2,15 @@
|
||||
using Sieve.Models;
|
||||
using Sieve.Services;
|
||||
using SieveUnitTests.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SieveUnitTests.Services
|
||||
{
|
||||
public class ApplicationSieveProcessor : SieveProcessor
|
||||
public class ApplicationSieveProcessor : SieveProcessor
|
||||
{
|
||||
public ApplicationSieveProcessor(
|
||||
IOptions<SieveOptions> options,
|
||||
ISieveCustomSortMethods customSortMethods,
|
||||
ISieveCustomFilterMethods customFilterMethods)
|
||||
IOptions<SieveOptions> options,
|
||||
ISieveCustomSortMethods customSortMethods,
|
||||
ISieveCustomFilterMethods customFilterMethods)
|
||||
: base(options, customSortMethods, customFilterMethods)
|
||||
{
|
||||
}
|
||||
|
@@ -1,24 +1,15 @@
|
||||
using Sieve.Services;
|
||||
using System.Linq;
|
||||
using Sieve.Services;
|
||||
using SieveUnitTests.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SieveUnitTests.Services
|
||||
{
|
||||
public class SieveCustomFilterMethods : ISieveCustomFilterMethods
|
||||
{
|
||||
public IQueryable<Post> IsNew(IQueryable<Post> source, string op, string value)
|
||||
{
|
||||
var result = source.Where(p => p.LikeCount < 100);
|
||||
public IQueryable<Post> IsNew(IQueryable<Post> source)
|
||||
=> source.Where(p => p.LikeCount < 100);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public IQueryable<Comment> TestComment(IQueryable<Comment> source, string op, string value)
|
||||
{
|
||||
return source;
|
||||
}
|
||||
public IQueryable<Comment> TestComment(IQueryable<Comment> source)
|
||||
=> source;
|
||||
}
|
||||
}
|
||||
|
@@ -1,23 +1,15 @@
|
||||
using Sieve.Services;
|
||||
using System.Linq;
|
||||
using Sieve.Services;
|
||||
using SieveUnitTests.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SieveUnitTests.Services
|
||||
{
|
||||
public class SieveCustomSortMethods : ISieveCustomSortMethods
|
||||
{
|
||||
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)
|
||||
public IQueryable<Post> Popularity(IQueryable<Post> source, bool useThenBy) => useThenBy
|
||||
? ((IOrderedQueryable<Post>)source).ThenBy(p => p.LikeCount)
|
||||
: source.OrderBy(p => p.LikeCount)
|
||||
.ThenBy(p => p.CommentCount)
|
||||
.ThenBy(p => p.DateCreated);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,26 +1,15 @@
|
||||
using Microsoft.Extensions.Options;
|
||||
using Sieve.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace SieveUnitTests
|
||||
{
|
||||
public class SieveOptionsAccessor : IOptions<SieveOptions>
|
||||
{
|
||||
private SieveOptions _value;
|
||||
|
||||
public SieveOptions Value
|
||||
{
|
||||
get
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
}
|
||||
public SieveOptions Value { get; }
|
||||
|
||||
public SieveOptionsAccessor()
|
||||
{
|
||||
_value = new SieveOptions()
|
||||
Value = new SieveOptions()
|
||||
{
|
||||
ThrowExceptions = true
|
||||
};
|
||||
|
Reference in New Issue
Block a user