From 8b78bc983a16a76345a5c2a3286abfcbe4afa203 Mon Sep 17 00:00:00 2001 From: David Lebee Date: Mon, 22 Oct 2018 21:10:41 -0500 Subject: [PATCH] filters are tested. --- PoweredSoft.DynamicQuery.Test/FilterTests.cs | 55 +++++++++++++++----- README.md | 6 +-- 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/PoweredSoft.DynamicQuery.Test/FilterTests.cs b/PoweredSoft.DynamicQuery.Test/FilterTests.cs index 717a924..3700da3 100644 --- a/PoweredSoft.DynamicQuery.Test/FilterTests.cs +++ b/PoweredSoft.DynamicQuery.Test/FilterTests.cs @@ -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 { 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 @@ -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 { new MockIsChuckFilter() } + Filters = new List + { + new CompositeFilter() + { + Type = FilterType.Composite, + Filters = new List + { + new SimpleFilter() { Path = "FirstName", Type = FilterType.Equal, Value = "John" }, + new SimpleFilter() { Path = "LastName", Type = FilterType.Equal, Value = "Norris"} + } + } + } }; var queryHandler = new QueryHandler(); diff --git a/README.md b/README.md index 4c1ce82..b92afa8 100644 --- a/README.md +++ b/README.md @@ -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