diff --git a/PoweredSoft.DynamicLinq.Test/ComplexQueriesTests.cs b/PoweredSoft.DynamicLinq.Test/ComplexQueriesTests.cs index 20d17a9..9912dc5 100644 --- a/PoweredSoft.DynamicLinq.Test/ComplexQueriesTests.cs +++ b/PoweredSoft.DynamicLinq.Test/ComplexQueriesTests.cs @@ -101,65 +101,7 @@ namespace PoweredSoft.DynamicLinq.Test [TestMethod] public void TestAutomaticNullChecking() { - 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" - } - } - }, - new Author - { - Id = 2, - FirstName = "Chuck", - LastName = "Norris", - Posts = new List - { - new Post - { - Id = 3, - AuthorId = 2, - Title = "Match", - Content = "ASD" - }, - new Post - { - Id = 4, - AuthorId = 2, - Title = "DontMatch", - Content = "ASD" - } - } - } - }; + var authors = TestData.Authors; // the query. var query = authors.AsQueryable(); diff --git a/PoweredSoft.DynamicLinq.Test/InTests.cs b/PoweredSoft.DynamicLinq.Test/InTests.cs index 7beaece..2033cf2 100644 --- a/PoweredSoft.DynamicLinq.Test/InTests.cs +++ b/PoweredSoft.DynamicLinq.Test/InTests.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; using PoweredSoft.DynamicLinq; +using PoweredSoft.DynamicLinq.Dal.Pocos; using PoweredSoft.DynamicLinq.Test.Helpers; namespace PoweredSoft.DynamicLinq.Test @@ -10,23 +11,13 @@ namespace PoweredSoft.DynamicLinq.Test [TestClass] public class InTests { - internal List Persons = new List - { - new MockPersonObject { FirstName = "David", LastName = "Lebee", Age = 28 }, - new MockPersonObject { FirstName = "Michaela", LastName = "Vickar", Age = 27 }, - new MockPersonObject { FirstName = "John", LastName = "Doe", Age = 28 }, - new MockPersonObject { FirstName = "Chuck", LastName = "Norris", Age = 50 }, - new MockPersonObject { FirstName = "Michael", LastName = "Jackson", Age = 58 } - }; - [TestMethod] public void In() { IQueryable a, b; var ageGroup = new List() { 28, 27, 50 }; - - a = Persons.AsQueryable().Query(t => t.In("Age", ageGroup)); - b = Persons.AsQueryable().Where(t => ageGroup.Contains(t.Age)); + a = TestData.Persons.AsQueryable().Query(t => t.In("Age", ageGroup)); + b = TestData.Persons.AsQueryable().Where(t => ageGroup.Contains(t.Age)); QueryableAssert.AreEqual(a, b); } @@ -35,8 +26,8 @@ namespace PoweredSoft.DynamicLinq.Test { IQueryable a, b; var ageGroup = new List() { 50, 58 }; - a = Persons.AsQueryable().Query(t => t.NotIn("Age", ageGroup)); - b = Persons.AsQueryable().Where(t => !ageGroup.Contains(t.Age)); + a = TestData.Persons.AsQueryable().Query(t => t.NotIn("Age", ageGroup)); + b = TestData.Persons.AsQueryable().Where(t => !ageGroup.Contains(t.Age)); QueryableAssert.AreEqual(a, b); } @@ -45,8 +36,8 @@ namespace PoweredSoft.DynamicLinq.Test { IQueryable a, b; var group = new List() { "David", "Michaela" }; - a = Persons.AsQueryable().Query(t => t.In("FirstName", group)); - b = Persons.AsQueryable().Where(t => group.Contains(t.FirstName)); + a = TestData.Persons.AsQueryable().Query(t => t.In("FirstName", group)); + b = TestData.Persons.AsQueryable().Where(t => group.Contains(t.FirstName)); QueryableAssert.AreEqual(a, b); } @@ -57,8 +48,26 @@ namespace PoweredSoft.DynamicLinq.Test var ageGroup = new List() { "28", "27", "50" }; var ageGroupInt = ageGroup.Select(t => Convert.ToInt32(t)).ToList(); - a = Persons.AsQueryable().Query(t => t.In("Age", ageGroup)); - b = Persons.AsQueryable().Where(t => ageGroupInt.Contains(t.Age)); + a = TestData.Persons.AsQueryable().Query(t => t.In("Age", ageGroup)); + b = TestData.Persons.AsQueryable().Where(t => ageGroupInt.Contains(t.Age)); + QueryableAssert.AreEqual(a, b); + } + + [TestMethod] + public void MixingInWithCollectionPaths() + { + var titles = new List() { "Match" }; + var a = TestData.Authors.AsQueryable().Query(t => t.In("Posts.Title", titles)); + var b = TestData.Authors.AsQueryable().Where(t => t.Posts.Any(t2 => titles.Contains(t2.Title))); + QueryableAssert.AreEqual(a, b); + } + + [TestMethod] + public void MixingInComplexPaths() + { + var authorsFirstNames = new List() { "David", "Pablo" }; + var a = TestData.Posts.AsQueryable().Query(t => t.In("Author.FirstName", authorsFirstNames)); + var b = TestData.Posts.AsQueryable().Where(t => authorsFirstNames.Contains(t.Author.FirstName)); QueryableAssert.AreEqual(a, b); } } diff --git a/PoweredSoft.DynamicLinq.Test/PoweredSoft.DynamicLinq.Test.csproj b/PoweredSoft.DynamicLinq.Test/PoweredSoft.DynamicLinq.Test.csproj index 1c73b67..efadda6 100644 --- a/PoweredSoft.DynamicLinq.Test/PoweredSoft.DynamicLinq.Test.csproj +++ b/PoweredSoft.DynamicLinq.Test/PoweredSoft.DynamicLinq.Test.csproj @@ -70,6 +70,7 @@ + diff --git a/PoweredSoft.DynamicLinq.Test/StringComparision.cs b/PoweredSoft.DynamicLinq.Test/StringComparision.cs index e4e90ba..a6163a1 100644 --- a/PoweredSoft.DynamicLinq.Test/StringComparision.cs +++ b/PoweredSoft.DynamicLinq.Test/StringComparision.cs @@ -10,14 +10,7 @@ namespace PoweredSoft.DynamicLinq.Test [TestClass] public class StringComparisionTests { - internal List Persons = new List - { - new MockPersonObject { FirstName = "David", LastName = "Lebee", Age = 28 }, - new MockPersonObject { FirstName = "Michaela", LastName = "Vickar", Age = 27 }, - new MockPersonObject { FirstName = "John", LastName = "Doe", Age = 28 }, - new MockPersonObject { FirstName = "Chuck", LastName = "Norris", Age = 50 }, - new MockPersonObject { FirstName = "Michael", LastName = "Jackson", Age = 58 } - }; + internal List Persons => TestData.Persons; [TestMethod] public void Equal() diff --git a/PoweredSoft.DynamicLinq.Test/TestData.cs b/PoweredSoft.DynamicLinq.Test/TestData.cs new file mode 100644 index 0000000..01aedf5 --- /dev/null +++ b/PoweredSoft.DynamicLinq.Test/TestData.cs @@ -0,0 +1,127 @@ +using PoweredSoft.DynamicLinq.Dal.Pocos; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PoweredSoft.DynamicLinq.Test +{ + internal static class TestData + { + static readonly internal List Persons = new List + { + new MockPersonObject { FirstName = "David", LastName = "Lebee", Age = 28 }, + new MockPersonObject { FirstName = "Michaela", LastName = "Vickar", Age = 27 }, + new MockPersonObject { FirstName = "John", LastName = "Doe", Age = 28 }, + new MockPersonObject { FirstName = "Chuck", LastName = "Norris", Age = 50 }, + new MockPersonObject { FirstName = "Michael", LastName = "Jackson", Age = 58 } + }; + + static readonly internal List Posts = new List() + { + new Post + { + Id = 1, + Author = new Author() + { + Id = 1, + FirstName = "David", + LastName = "Lebee" + }, + AuthorId = 1, + CreateTime = DateTime.Now, + Title = "Match", + Content = "ABC", + }, + new Post + { + Id = 2, + Author = new Author() + { + Id = 1, + FirstName = "David", + LastName = "Lebee" + }, + AuthorId = 1, + CreateTime = DateTime.Now, + Title = "Match 2", + Content = "ABC 2", + }, + new Post + { + Id = 3, + Author = new Author() + { + Id = 2, + FirstName = "John", + LastName = "Doe" + }, + AuthorId = 3, + CreateTime = DateTime.Now, + Title = "Match 3", + Content = "ABC 3", + }, + }; + + static readonly internal List 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" + } + } + }, + new Author + { + Id = 2, + FirstName = "Chuck", + LastName = "Norris", + Posts = new List + { + new Post + { + Id = 3, + AuthorId = 2, + Title = "Match", + Content = "ASD" + }, + new Post + { + Id = 4, + AuthorId = 2, + Title = "DontMatch", + Content = "ASD" + } + } + } + }; + } +}