using System; using System.Collections.Generic; using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; using PoweredSoft.DynamicLinq.Dal.Pocos; using PoweredSoft.DynamicLinq.Helpers; namespace PoweredSoft.DynamicLinq.Test { [TestClass] public class HelpersTests { [TestMethod] public void TestCreateFilterExpression() { var authors = new List() { new Author { Id = 1, FirstName = "David", LastName = "Lebee", Posts = new List { new Post { Id = 1, AuthorId = 1, Title = "Match", Content = "ABC", Comments = new List() { new Comment() { Id = 1, DisplayName = "John Doe", CommentText = "!@#$!@#!@#", Email = "John.doe@me.com" } } }, new Post { Id = 2, AuthorId = 1, Title = "Match", Content = "ABC", Comments = new List() } } }, new Author { Id = 2, FirstName = "Chuck", LastName = "Norris", Posts = new List { new Post { Id = 3, AuthorId = 2, Title = "Match", Content = "ASD", Comments = new List() }, new Post { Id = 4, AuthorId = 2, Title = "DontMatch", Content = "ASD", Comments = new List() } } } }; // the query. var query = authors.AsQueryable(); var allExpression = QueryableHelpers.CreateConditionExpression("Posts.Title", ConditionOperators.Equal, "Match", QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling.All); var anyExpression = QueryableHelpers.CreateConditionExpression("Posts.Title", ConditionOperators.Equal, "Match", QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling.Any); var anyExpression2 = QueryableHelpers.CreateConditionExpression("Posts.Comments.Email", ConditionOperators.Equal, "John.doe@me.com", QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling.Any); Assert.AreEqual(1, query.Count(allExpression)); Assert.AreEqual(2, query.Count(anyExpression)); Assert.AreEqual(1, query.Count(anyExpression2)); } } }