dotnet-dynamic-query/PoweredSoft.DynamicQuery.Test/CriteriaTests.cs

49 lines
1.8 KiB
C#
Raw Permalink Normal View History

2018-10-22 21:21:14 -04:00
using System;
2018-10-22 22:05:23 -04:00
using System.Collections.Generic;
2018-10-22 21:21:14 -04:00
using System.Linq;
using Microsoft.EntityFrameworkCore;
using PoweredSoft.DynamicQuery.Core;
2018-10-22 21:21:14 -04:00
using PoweredSoft.DynamicQuery.Test.Mock;
using Xunit;
namespace PoweredSoft.DynamicQuery.Test
{
public class CriteriaTests
{
[Fact]
public void TestEmptyCriteria()
{
2018-10-22 22:05:23 -04:00
MockContextFactory.SeedAndTestContextFor("CriteriaTests_TestEmptyCriteria", TestSeeders.SimpleSeedScenario, ctx =>
2018-10-22 21:21:14 -04:00
{
var resultShouldMatch = ctx.Items.ToList();
var queryable = ctx.Items.AsQueryable();
2018-10-22 22:05:23 -04:00
2018-10-22 21:21:14 -04:00
// query handler that is empty should be the same as running to list.
var criteria = new QueryCriteria();
var queryHandler = new QueryHandler(Enumerable.Empty<IQueryInterceptorProvider>());
2018-10-22 21:21:14 -04:00
var result = queryHandler.Execute(queryable, criteria);
2018-10-22 22:05:23 -04:00
Assert.Equal(resultShouldMatch, result.Data);
});
2018-10-22 21:21:14 -04:00
}
2018-10-22 23:42:57 -04:00
[Fact]
2018-10-22 23:43:49 -04:00
public void TestPaging()
2018-10-22 23:42:57 -04:00
{
MockContextFactory.SeedAndTestContextFor("CriteriaTests_TestPagging", TestSeeders.SimpleSeedScenario, ctx =>
{
var resultShouldMatch = ctx.OrderItems.OrderBy(t => t.Id).Skip(5).Take(5).ToList();
// query handler that is empty should be the same as running to list.
var criteria = new QueryCriteria();
criteria.Sorts.Add(new Sort("Id"));
criteria.Page = 2;
criteria.PageSize = 5;
var queryHandler = new QueryHandler(Enumerable.Empty<IQueryInterceptorProvider>());
2018-10-22 23:42:57 -04:00
var result = queryHandler.Execute(ctx.OrderItems, criteria);
Assert.Equal(resultShouldMatch, result.Data);
});
}
2018-10-22 21:21:14 -04:00
}
}