filters are tested.

This commit is contained in:
David Lebee 2018-10-22 21:10:41 -05:00
parent 11074bc946
commit 8b78bc983a
2 changed files with 45 additions and 16 deletions

View File

@ -10,6 +10,32 @@ namespace PoweredSoft.DynamicQuery.Test
{
public class FilterTests
{
private class MockIsChuckFilter : ISimpleFilter
{
public bool? And { get; set; } = false;
public FilterType Type { get; set; } = FilterType.Equal;
public string Path { get; set; } = "FirstName";
public object Value { get; set; } = "Chuck";
}
[Fact]
public void TestInversionOfControl()
{
MockContextFactory.SeedAndTestContextFor("FilterTests_TestInversionOfControl", TestSeeders.SimpleSeedScenario, ctx =>
{
var resultShouldMatch = ctx.Customers.Where(t => t.FirstName == "Chuck").ToList();
var criteria = new QueryCriteria()
{
Filters = new List<IFilter> { new MockIsChuckFilter() }
};
var queryHandler = new QueryHandler();
var result = queryHandler.Execute(ctx.Customers, criteria);
Assert.Equal(resultShouldMatch, result.Data);
});
}
[Fact]
public void SimpleFilter()
{
@ -17,7 +43,6 @@ namespace PoweredSoft.DynamicQuery.Test
{
var resultShouldMatch = ctx.Items.Where(t => t.Name.EndsWith("Cables")).ToList();
// query handler that is empty should be the same as running to list.
var criteria = new QueryCriteria()
{
Filters = new List<IFilter>
@ -37,25 +62,29 @@ namespace PoweredSoft.DynamicQuery.Test
});
}
private class MockIsChuckFilter : ISimpleFilter
{
public bool? And { get; set; } = false;
public FilterType Type { get; set; } = FilterType.Equal;
public string Path { get; set; } = "FirstName";
public object Value { get; set; } = "Chuck";
}
[Fact]
public void TestInversionOfControl()
public void CompositeFilter()
{
MockContextFactory.SeedAndTestContextFor("FilterTests_SimpleFilter", TestSeeders.SimpleSeedScenario, ctx =>
MockContextFactory.SeedAndTestContextFor("FilterTests_CompositeFilter", TestSeeders.SimpleSeedScenario, ctx =>
{
var resultShouldMatch = ctx.Customers.Where(t => t.FirstName == "Chuck").ToList();
var resultShouldMatch = ctx.Customers.Where(t => t.FirstName == "John" || t.LastName == "Norris").ToList();
// query handler that is empty should be the same as running to list.
var criteria = new QueryCriteria()
{
Filters = new List<IFilter> { new MockIsChuckFilter() }
Filters = new List<IFilter>
{
new CompositeFilter()
{
Type = FilterType.Composite,
Filters = new List<IFilter>
{
new SimpleFilter() { Path = "FirstName", Type = FilterType.Equal, Value = "John" },
new SimpleFilter() { Path = "LastName", Type = FilterType.Equal, Value = "Norris"}
}
}
}
};
var queryHandler = new QueryHandler();

View File

@ -20,9 +20,9 @@ Criteria must implement the following interfaces
Object | Interface | Implementation | Example | Description
-----------------|--------------------------------------------------------------------------|-------------------------------------------------------------------------------|--------------------------------------------------------|--------------------------------------------
Query Criteria | [interface](../master/PoweredSoft.DynamicQuery.Core/IQueryCriteria.cs) | [default implementation](../master/PoweredSoft.DynamicQuery/QueryCriteria.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/CriteriaTests.cs) | Wraps the query parameters
Filter | [interface](../master/PoweredSoft.DynamicQuery.Core/IFilter.cs) | [default implementation](../master/PoweredSoft.DynamicQuery/Filter.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/FilterTests.cs) | Represent a filter to be executed
Simple Filter | [interface](../master/PoweredSoft.DynamicQuery.Core/ISimpleFilter.cs) | [default implementation](../master/PoweredSoft.DynamicQuery/Filter.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/TBT.md) | Represent a simple filter to be executed
Composite Filter | [interface](../master/PoweredSoft.DynamicQuery.Core/ICompositeFilter.cs) | [default implementation](../master/PoweredSoft.DynamicQuery/Filter.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/TBT.md) | Represent a composite filter to be executed
Filter | [interface](../master/PoweredSoft.DynamicQuery.Core/IFilter.cs) | [default implementation](../master/PoweredSoft.DynamicQuery/Filter.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/FilterTests.cs#22) | Represent a filter to be executed
Simple Filter | [interface](../master/PoweredSoft.DynamicQuery.Core/ISimpleFilter.cs) | [default implementation](../master/PoweredSoft.DynamicQuery/Filter.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/FilterTests.md#40) | Represent a simple filter to be executed
Composite Filter | [interface](../master/PoweredSoft.DynamicQuery.Core/ICompositeFilter.cs) | [default implementation](../master/PoweredSoft.DynamicQuery/Filter.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/FilterTests.md#68) | Represent a composite filter to be executed
Sort | [interface](../master/PoweredSoft.DynamicQuery.Core/ISort.cs) | [default implementation](../master/PoweredSoft.DynamicQuery/Sort.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/TBT.md) | Represent a sort to be executed
Group | [interface](../master/PoweredSoft.DynamicQuery.Core/IGroup.cs) | [default implementation](../master/PoweredSoft.DynamicQuery/Group.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/TBT.md) | Represent a group to be executed
Aggregate | [interface](../master/PoweredSoft.DynamicQuery.Core/IAggregate.cs) | [default implementation](../master/PoweredSoft.DynamicQuery/Aggregate.cs) | [test](../master/PoweredSoft.DynamicQuery.Test/TBT.md) | Represent an aggregate to be executed