dotnet-dynamic-linq/PoweredSoft.DynamicLinq.Test/InTests.cs
David Lebée 10f15b802c selects need to be rethinked.
i'll try to use some kind of path resolve helper which callbacks for each part and allows handling this could be a better idea also will be able to refactor where code to use it as well :)
2018-03-23 19:29:55 -05:00

75 lines
2.8 KiB
C#

using System;
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
{
[TestClass]
public class InTests
{
[TestMethod]
public void In()
{
IQueryable<MockPersonObject> a, b;
var ageGroup = new List<int>() { 28, 27, 50 };
a = TestData.Persons.AsQueryable().Query(t => t.In("Age", ageGroup));
b = TestData.Persons.AsQueryable().Where(t => ageGroup.Contains(t.Age));
QueryableAssert.AreEqual(a, b);
}
[TestMethod]
public void NotIn()
{
IQueryable<MockPersonObject> a, b;
var ageGroup = new List<int>() { 50, 58 };
a = TestData.Persons.AsQueryable().Query(t => t.NotIn("Age", ageGroup));
b = TestData.Persons.AsQueryable().Where(t => !ageGroup.Contains(t.Age));
QueryableAssert.AreEqual(a, b);
}
[TestMethod]
public void InString()
{
IQueryable<MockPersonObject> a, b;
var group = new List<string>() { "David", "Michaela" };
a = TestData.Persons.AsQueryable().Query(t => t.In("FirstName", group));
b = TestData.Persons.AsQueryable().Where(t => group.Contains(t.FirstName));
QueryableAssert.AreEqual(a, b);
}
[TestMethod]
public void DiffTypeListConversion()
{
IQueryable<MockPersonObject> a, b;
var ageGroup = new List<string>() { "28", "27", "50" };
var ageGroupInt = ageGroup.Select(t => Convert.ToInt32(t)).ToList();
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<string>() { "Match" };
var a = TestData.Authors.AsQueryable().Query(t => t.NullChecking(true).In("Posts.Title", titles));
var b = TestData.Authors.AsQueryable().Where(t => t.Posts != null && t.Posts.Any(t2 => titles.Contains(t2.Title)));
QueryableAssert.AreEqual(a, b);
}
[TestMethod]
public void MixingInComplexPaths()
{
var authorsFirstNames = new List<string>() { "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);
}
}
}