コード例 #1
0
		public void Parse_WhenOneExpressionIsNullExpression_DoesNotThrowException()
		{
			var lambda = new OrderByAscExpression(Reflect<MyClass>.LambdaFrom(m => m.String1));

			Assert.DoesNotThrow(
				() => new OrderByParser().Parse(new OrderByExpression[] { lambda, null }));
		}
コード例 #2
0
		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]);
		}
コード例 #3
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);
		}
コード例 #4
0
		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);
		}
コード例 #5
0
		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);
		}
コード例 #6
0
		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]);
		}
コード例 #7
0
		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);
		}
コード例 #8
0
		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);
		}
コード例 #9
0
		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);
		}
コード例 #10
0
		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);
		}