public void Parse_WhenOneExpressionIsNullExpression_DoesNotThrowException() { var lambda = new OrderByAscExpression(Reflect<MyClass>.LambdaFrom(m => m.String1)); Assert.DoesNotThrow( () => new OrderByParser().Parse(new OrderByExpression[] { lambda, null })); }
public void Parse_WhenOnePropertyLambdaIsPassed_ExactlyOneSortingNodeIsReturned() { var lambda = new OrderByAscExpression(Reflect<MyClass>.LambdaFrom(m => m.String1)); var parsedLambda = new OrderByParser().Parse(new[] { lambda }); Assert.AreEqual(1, parsedLambda.Nodes.Length); Assert.IsInstanceOf(typeof(SortingNode), parsedLambda.Nodes[0]); }
public void Parse_WhenNestedMemberIsMethod_ThrowsException() { var lambda = new OrderByAscExpression(Reflect<MyClass>.LambdaFrom(m => m.Child.DoSomething())); var ex = Assert.Throws<SisoDbException>( () => new OrderByParser().Parse(new[] { lambda })); Assert.AreEqual(ExceptionMessages.OrderByParser_UnsupportedMethodForSortingDirection, ex.Message); }
public void Parse_WhenNonMemberExpression_ThrowsException() { var parser = new OrderByParser(); var nonMemberExpression = new OrderByAscExpression(Reflect<MyClass>.BoolExpressionFrom(m => m.Int1 == 32)); var ex = Assert.Throws<NCoreException>(() => parser.Parse(new[] { nonMemberExpression })); Assert.AreEqual("No MemberExpression found in expression: '(m.Int1 == 32)'.", ex.Message); }
public void Parse_WhenNonMemberExpression_ThrowsException() { var parser = CreateParser(); var nonMemberExpression = new OrderByAscExpression(Reflect<MyClass>.BoolExpressionFrom(m => m.Int1 == 32)); var ex = Assert.Throws<SisoDbException>(() => parser.Parse(new[] { nonMemberExpression })); Assert.AreEqual(ExceptionMessages.OrderByExpressionDoesNotTargetMember.Inject("m => (m.Int1 == 32)"), ex.Message); }
public void Parse_WhenTwoPropertyLambdasArePassed_ExactlyTwoSortingNodeIsReturned() { var lambda1 = new OrderByAscExpression(Reflect<MyClass>.LambdaFrom(m => m.String1)); var lambda2 = new OrderByDescExpression(Reflect<MyClass>.LambdaFrom(m => m.Int1)); var parsedLambda = new OrderByParser().Parse(new OrderByExpression[] { lambda1, lambda2 }); Assert.AreEqual(2, parsedLambda.Nodes.Length); Assert.IsInstanceOf(typeof(SortingNode), parsedLambda.Nodes[0]); Assert.IsInstanceOf(typeof(SortingNode), parsedLambda.Nodes[1]); }
public void Parse_WhenNestedLambda_MemberPathReflectsHierarchy() { var lambda = new OrderByAscExpression(Reflect<MyClass>.LambdaFrom(m => m.Child.String1)); var parsedLambda = new OrderByParser().Parse(new[] { lambda }); var node = (SortingNode)parsedLambda.Nodes[0]; Assert.AreEqual("Child.String1", node.MemberPath); }
public void Parse_WhenFirstLevelLambda_MemberPathIsPropertyName() { var lambda = new OrderByAscExpression(Reflect<MyClass>.LambdaFrom(m => m.String1)); var parsedLambda = new OrderByParser().Parse(new[] { lambda }); var node = (SortingNode)parsedLambda.Nodes[0]; Assert.AreEqual("String1", node.MemberPath); }
public void Parse_WhenAscAndDescExpressionOnSameMember_SortingDirectionBecomesBothAscAndDescInCorrectOrder() { var lambda1 = new OrderByAscExpression(Reflect<MyClass>.LambdaFrom(m => m.String1)); var lambda2 = new OrderByDescExpression(Reflect<MyClass>.LambdaFrom(m => m.String1)); var parsedLambda = new OrderByParser() .Parse(new OrderByExpression [] { lambda1, lambda2 }); Assert.AreEqual(2, parsedLambda.Nodes.Length); var node1 = (SortingNode)parsedLambda.Nodes[0]; Assert.AreEqual(SortDirections.Asc, node1.Direction); var node2 = (SortingNode)parsedLambda.Nodes[1]; Assert.AreEqual(SortDirections.Desc, node2.Direction); }
public void Parse_WhenAscExpressionOnNested_SortingDirectionBecomesAsc() { var lambda = new OrderByAscExpression(Reflect<MyClass>.LambdaFrom(m => m.Child.String1)); var parsedLambda = new OrderByParser().Parse(new[] { lambda }); var node = (SortingNode)parsedLambda.Nodes[0]; Assert.AreEqual(SortDirections.Asc, node.Direction); }