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

48 lines
1.7 KiB
C#
Raw 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.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();
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();
var result = queryHandler.Execute(ctx.OrderItems, criteria);
Assert.Equal(resultShouldMatch, result.Data);
});
}
2018-10-22 21:21:14 -04:00
}
}