public void DynamicExpressionParser_ParseLambda_Complex_3() { var config = new ParsingConfig { CustomTypeProvider = new TestCustomTypeProvider() }; // Arrange var testList = User.GenerateSampleModels(51); var qry = testList.AsQueryable(); var externals = new Dictionary <string, object> { { "Users", qry } }; // Act string stringExpression = "Users.GroupBy(x => new { x.Profile.Age }).OrderBy(gg => gg.Key.Age).Select(j => new System.Linq.Dynamic.Core.Tests.DynamicExpressionParserTests+ComplexParseLambda3Result{j.Key.Age, j.Sum(k => k.Income) As TotalIncome})"; LambdaExpression expression = DynamicExpressionParser.ParseLambda(config, null, stringExpression, externals); Delegate del = expression.Compile(); IEnumerable <dynamic> result = del.DynamicInvoke() as IEnumerable <dynamic>; var expected = qry.GroupBy(x => new { x.Profile.Age }).OrderBy(gg => gg.Key.Age) .Select(j => new ComplexParseLambda3Result { Age = j.Key.Age, TotalIncome = j.Sum(k => k.Income) }) .Cast <dynamic>().ToArray(); // Assert Check.That(result).IsNotNull(); Check.That(result).HasSize(expected.Length); Check.That(result.ToArray()[0]).Equals(expected[0]); }
public void DynamicExpressionParser_ParseLambda_Complex_2() { // Arrange var testList = User.GenerateSampleModels(51); var qry = testList.AsQueryable(); // Act string query = "GroupBy(x => new { x.Profile.Age }, it).OrderBy(gg => gg.Key.Age).Select(j => new (j.Key.Age, j.Sum(k => k.Income) As TotalIncome))"; LambdaExpression expression = DynamicExpressionParser.ParseLambda(qry.GetType(), null, query); Delegate del = expression.Compile(); IEnumerable <dynamic> result = del.DynamicInvoke(qry) as IEnumerable <dynamic>; var expected = qry.GroupBy(x => new { x.Profile.Age }, x => x).OrderBy(gg => gg.Key.Age) .Select(j => new { j.Key.Age, TotalIncome = j.Sum(k => k.Income) }) .Select(c => new ComplexParseLambda1Result { Age = c.Age, TotalIncome = c.TotalIncome }).Cast <dynamic>() .ToArray(); // Assert Check.That(result).IsNotNull(); Check.That(result).HasSize(expected.Length); Check.That(result.ToArray()[0]).Equals(expected[0]); }
public void DynamicExpressionParser_ParseLambda_ToList() { // Arrange var testList = User.GenerateSampleModels(51); var qry = testList.AsQueryable(); // Act string query = "OrderBy(gg => gg.Income).ToList()"; LambdaExpression expression = DynamicExpressionParser.ParseLambda(qry.GetType(), null, query); Delegate del = expression.Compile(); IEnumerable <dynamic> result = del.DynamicInvoke(qry) as IEnumerable <dynamic>; var expected = qry.OrderBy(gg => gg.Income).ToList(); // Assert Check.That(result).IsNotNull(); Check.That(result).HasSize(expected.Count); Check.That(result.ToArray()[0]).Equals(expected[0]); }
public void DynamicExpressionParser_ParseLambda_Select_2() { // Arrange var testList = User.GenerateSampleModels(5); var qry = testList.AsQueryable(); var externals = new Dictionary <string, object> { { "Users", qry } }; // Act string query = "Users.Select(j => j)"; LambdaExpression expression = DynamicExpressionParser.ParseLambda(null, query, externals); Delegate del = expression.Compile(); object result = del.DynamicInvoke(); // Assert Assert.NotNull(result); }
public void DynamicExpressionParser_ParseLambda_WithStructWithEquality() { // Assign var testList = User.GenerateSampleModels(51); var qry = testList.AsQueryable(); // Act ulong expectedX = (ulong)long.MaxValue + 3; string query = $"Where(x => x.SnowflakeId == {expectedX})"; LambdaExpression expression = DynamicExpressionParser.ParseLambda(qry.GetType(), null, query); Delegate del = expression.Compile(); IEnumerable <dynamic> result = del.DynamicInvoke(qry) as IEnumerable <dynamic>; var expected = qry.Where(gg => gg.SnowflakeId == new SnowflakeId(expectedX)).ToList(); // Assert Check.That(result).IsNotNull(); Check.That(result).HasSize(expected.Count); Check.That(result.ToArray()[0]).Equals(expected[0]); }