示例#1
0
        public void Assert_Nullable_Float_Collection_Inequality_Expression_With_Array_Value_Is_Generated_Correctly()
        {
            // Arrange
            var randomHydra = Utilities.GetRandomItem(HydraArmy);
            var expression  = ExpressionBuilder.CreateBinaryFromQuery <Hydra>(BuildQueryText(nameof(Hydra.NullableFloatCollection), randomHydra.NullableFloatCollection.ToArray(), ExpressionOperator.NotEqual));

            // Act
            var result = HydraArmy.Where(expression.Compile()).ToList();

            // Assert
            Assert.NotEmpty(result);
            Assert.Contains(result, t => !t.NullableFloatCollection.SequenceEqual(randomHydra.NullableFloatCollection));
            Assert.DoesNotContain(result, t => t.NullableFloatCollection.SequenceEqual(randomHydra.NullableFloatCollection));
        }
示例#2
0
        public void Assert_Nullable_Float_Collection_Contains_Single_Value_Dynamic_Query_Expression_Is_Generated_Correctly()
        {
            // Arrange
            var randomFloat = Utilities.GetRandomItem(HydraArmy.Select(t => t.NullableFloatCollection)).FirstOrDefault();
            var expression  = ExpressionBuilder.CreateBinaryFromQuery <Hydra>(BuildQueryText(nameof(Hydra.NullableFloatCollection), randomFloat, ExpressionOperator.Contains));

            // Act
            var result = HydraArmy.Where(expression.Compile()).ToList();

            // Assert
            Assert.NotEmpty(result);
            Assert.Contains(result, t => t.NullableFloatCollection.Contains(randomFloat));
            Assert.DoesNotContain(result, t => !t.NullableFloatCollection.Contains(randomFloat));
        }
示例#3
0
        public void Assert_String_Ends_With_Dynamic_Query_Expression_Is_Generated_Correctly()
        {
            // Arrange
            var randomHydra = Utilities.GetRandomItem(HydraArmy);
            var expression  = ExpressionBuilder.CreateBinaryFromQuery <Hydra>(BuildQueryText(nameof(Hydra.FullName), randomHydra.LastName, ExpressionOperator.EndsWith));

            // Act
            var result = HydraArmy.Where(expression.Compile()).ToList();

            // Assert
            Assert.NotEmpty(result);
            Assert.Contains(result, t => t.FullName.EndsWith(randomHydra.LastName));
            Assert.DoesNotContain(result, t => t.FullName.EndsWith(randomHydra.LastName) == false);
        }
示例#4
0
        public void Assert_Nullable_Integer_Less_Than_Or_Equal_Expression_Is_Generated_Correctly()
        {
            // Arrange
            var randomHydra = Utilities.GetRandomItem(HydraArmy.Where(t => t.NullableInteger.HasValue));
            var expression  = ExpressionBuilder.CreateBinary <Hydra>(nameof(Hydra.NullableInteger), randomHydra.NullableInteger, ExpressionOperator.LessThanOrEqual);

            // Act
            var result = HydraArmy.Where(expression.Compile()).ToList();

            // Assert
            Assert.NotEmpty(result);
            Assert.Contains(result, t => t.NullableInteger <= randomHydra.NullableInteger);
            Assert.DoesNotContain(result, t => t.NullableInteger > randomHydra.NullableInteger);
        }
        public void Assert_DateTime_Greater_Than_Or_Equal_Expression_Is_Generated_Correctly()
        {
            // Arrange
            var randomHydra = Utilities.GetRandomItem(HydraArmy);
            var expression  = ExpressionBuilder.CreateBinary <Hydra>(nameof(Hydra.DateTime), randomHydra.DateTime, ExpressionOperator.GreaterThanOrEqual);

            // Act
            var result = HydraArmy.Where(expression.Compile()).ToList();

            // Assert
            Assert.NotEmpty(result);
            Assert.Contains(result, t => t.DateTime >= randomHydra.DateTime);
            Assert.DoesNotContain(result, t => t.DateTime < randomHydra.DateTime);
        }
        public void Assert_DateTime_Collection_Inequality_Expression_Is_Generated_Correctly()
        {
            // Arrange
            var randomHydra = Utilities.GetRandomItem(HydraArmy);
            var expression  = ExpressionBuilder.CreateBinary <Hydra>(nameof(Hydra.DateTimeCollection), randomHydra.DateTimeCollection, ExpressionOperator.NotEqual);

            // Act
            var result = HydraArmy.Where(expression.Compile()).ToList();

            // Assert
            Assert.NotEmpty(result);
            Assert.Contains(result, t => t.DateTimeCollection.SequenceEqual(randomHydra.DateTimeCollection) == false);
            Assert.DoesNotContain(result, t => t.DateTimeCollection.SequenceEqual(randomHydra.DateTimeCollection));
        }
        public void Assert_Boolean_Array_Contains_Single_Value_Dynamic_Query_Expression_Is_Generated_Correctly()
        {
            // Arrange
            var randomBoolean = Utilities.GetRandomItem(HydraArmy.Select(t => t.BooleanArray)).FirstOrDefault();
            var expression    = ExpressionBuilder.CreateBinaryFromQuery <Hydra>(BuildQueryText(nameof(Hydra.BooleanArray), randomBoolean, ExpressionOperator.Contains));

            // Act
            var result = HydraArmy.Where(expression.Compile()).ToList();

            // Assert
            Assert.NotEmpty(result);
            Assert.Contains(result, t => t.BooleanArray.Contains(randomBoolean));
            Assert.DoesNotContain(result, t => t.BooleanArray.Contains(randomBoolean) == false);
        }
示例#8
0
        public void Assert_Nullable_Char_Contains_On_Value_Dynamic_Query_Expression_Is_Generated_Correctly()
        {
            // Arrange
            var randomChars = Utilities.GetRandomItems(HydraArmy.Select(t => t.NullableChar));
            var expression  = ExpressionBuilder.CreateBinaryFromQuery <Hydra>(BuildQueryText(nameof(Hydra.NullableChar), randomChars, ExpressionOperator.ContainsOnValue));

            // Act
            var result = HydraArmy.Where(expression.Compile()).ToList();

            // Assert
            Assert.NotEmpty(result);
            Assert.Contains(result, t => randomChars.Contains(t.NullableChar));
            Assert.DoesNotContain(result, t => randomChars.Contains(t.NullableChar) == false);
        }
        public void Assert_TimeSpan_Array_Equality_Expression_Is_Generated_Correctly()
        {
            // Arrange
            var randomHydra = Utilities.GetRandomItem(HydraArmy);
            var expression  = ExpressionBuilder.CreateBinary <Hydra>(nameof(Hydra.TimeSpanArray), randomHydra.TimeSpanArray, ExpressionOperator.Equal);

            // Act
            var result = HydraArmy.Where(expression.Compile()).ToList();

            // Assert
            Assert.NotEmpty(result);
            Assert.Contains(result, t => t.TimeSpanArray.SequenceEqual(randomHydra.TimeSpanArray));
            Assert.DoesNotContain(result, t => !t.TimeSpanArray.SequenceEqual(randomHydra.TimeSpanArray));
        }
        public void Assert_TimeSpan_Less_Than_Expression_Is_Generated_Correctly()
        {
            // Arrange
            var randomHydra = Utilities.GetRandomItem(HydraArmy);
            var expression  = ExpressionBuilder.CreateBinary <Hydra>(nameof(Hydra.TimeSpan), randomHydra.TimeSpan, ExpressionOperator.LessThan);

            // Act
            var result = HydraArmy.Where(expression.Compile()).ToList();

            // Assert
            Assert.NotEmpty(result);
            Assert.Contains(result, t => t.TimeSpan < randomHydra.TimeSpan);
            Assert.DoesNotContain(result, t => t.TimeSpan >= randomHydra.TimeSpan);
        }
        public void Assert_TimeSpan_Contains_On_Value_Expression_Is_Generated_Correctly()
        {
            // Arrange
            var randomTimeSpans = Utilities.GetRandomItems(HydraArmy.Select(t => t.TimeSpan));
            var expression      = ExpressionBuilder.CreateBinary <Hydra>(nameof(Hydra.TimeSpan), randomTimeSpans, ExpressionOperator.ContainsOnValue);

            // Act
            var result = HydraArmy.Where(expression.Compile()).ToList();

            // Assert
            Assert.NotEmpty(result);
            Assert.Contains(result, t => randomTimeSpans.Contains(t.TimeSpan));
            Assert.DoesNotContain(result, t => !randomTimeSpans.Contains(t.TimeSpan));
        }
示例#12
0
        public void Assert_Nullable_DateTime_Greater_Than_Dynamic_Query_Expression_Is_Generated_Correctly()
        {
            // Arrange
            var randomHydra = Utilities.GetRandomItem(HydraArmy.Where(t => t.NullableDateTime.HasValue));
            var expression  = ExpressionBuilder.CreateBinaryFromQuery <Hydra>(BuildQueryText(nameof(Hydra.NullableDateTime), randomHydra.NullableDateTime, ExpressionOperator.GreaterThan));

            // Act
            var result = HydraArmy.Where(expression.Compile()).ToList();

            // Assert
            Assert.NotEmpty(result);
            Assert.Contains(result, t => t.NullableDateTime > randomHydra.NullableDateTime);
            Assert.DoesNotContain(result, t => t.NullableDateTime <= randomHydra.NullableDateTime);
        }
        public void Assert_Integer_Inequality_Expression_Is_Generated_Correctly()
        {
            // Arrange
            var randomHydra = Utilities.GetRandomItem(HydraArmy);
            var expression  = ExpressionBuilder.CreateBinary <Hydra>(nameof(Hydra.Integer), randomHydra.Integer, ExpressionOperator.NotEqual);

            // Act
            var result = HydraArmy.Where(expression.Compile()).ToList();

            // Assert
            Assert.NotEmpty(result);
            Assert.Contains(result, t => t.Integer != randomHydra.Integer);
            Assert.DoesNotContain(result, t => t.Integer == randomHydra.Integer);
        }
示例#14
0
        public void Assert_Nullable_Float_Inequality_Dynamic_Query_Expression_Is_Generated_Correctly()
        {
            // Arrange
            var randomHydra = Utilities.GetRandomItem(HydraArmy);
            var expression  = ExpressionBuilder.CreateBinaryFromQuery <Hydra>(BuildQueryText(nameof(Hydra.NullableFloat), randomHydra.NullableFloat, ExpressionOperator.NotEqual));

            // Act
            var result = HydraArmy.Where(expression.Compile()).ToList();

            // Assert
            Assert.NotEmpty(result);
            Assert.Contains(result, t => Math.Abs(t.NullableFloat.GetValueOrDefault() - randomHydra.NullableFloat.GetValueOrDefault()) > 0.01);
            Assert.DoesNotContain(result, t => Math.Abs(t.NullableFloat.GetValueOrDefault() - randomHydra.NullableFloat.GetValueOrDefault()) < 0.01);
        }
        public void Assert_Boolean_Inequality_Dynamic_Query_Expression_Is_Generated_Correctly()
        {
            // Arrange
            var randomHydra = Utilities.GetRandomItem(HydraArmy);
            var expression  = ExpressionBuilder.CreateBinaryFromQuery <Hydra>(BuildQueryText(nameof(Hydra.Boolean), randomHydra.Boolean, ExpressionOperator.NotEqual));

            // Act
            var result = HydraArmy.Where(expression.Compile()).ToList();

            // Assert
            Assert.NotEmpty(result);
            Assert.Contains(result, t => t.Boolean != randomHydra.Boolean);
            Assert.DoesNotContain(result, t => t.Boolean == randomHydra.Boolean);
        }
示例#16
0
        public void Assert_Nullable_Float_Less_Than_Or_Equal_Dynamic_Query_Expression_Is_Generated_Correctly()
        {
            // Arrange
            var randomHydra = Utilities.GetRandomItem(HydraArmy.Where(t => t.NullableFloat.HasValue));
            var expression  = ExpressionBuilder.CreateBinaryFromQuery <Hydra>(BuildQueryText(nameof(Hydra.NullableFloat), randomHydra.NullableFloat, ExpressionOperator.LessThanOrEqual));

            // Act
            var result = HydraArmy.Where(expression.Compile()).ToList();

            // Assert
            Assert.NotEmpty(result);
            Assert.Contains(result, t => t.NullableFloat <= randomHydra.NullableFloat);
            Assert.DoesNotContain(result, t => t.NullableFloat > randomHydra.NullableFloat);
        }
示例#17
0
        public void Assert_Integer_Less_Than_Dynamic_Query_Expression_Is_Generated_Correctly()
        {
            // Arrange
            var randomHydra = Utilities.GetRandomItem(HydraArmy);
            var expression  = ExpressionBuilder.CreateBinaryFromQuery <Hydra>(BuildQueryText(nameof(Hydra.Integer), randomHydra.Integer, ExpressionOperator.LessThan));

            // Act
            var result = HydraArmy.Where(expression.Compile()).ToList();

            // Assert
            Assert.NotEmpty(result);
            Assert.Contains(result, t => t.Integer < randomHydra.Integer);
            Assert.DoesNotContain(result, t => t.Integer >= randomHydra.Integer);
        }
示例#18
0
        public void Assert_Nullable_Char_Array_Equality_Dynamic_Query_Expression_Is_Generated_Correctly()
        {
            // Arrange
            var randomHydra = Utilities.GetRandomItem(HydraArmy);
            var expression  = ExpressionBuilder.CreateBinaryFromQuery <Hydra>(BuildQueryText(nameof(Hydra.NullableCharArray), randomHydra.NullableCharArray, ExpressionOperator.Equal));

            // Act
            var result = HydraArmy.Where(expression.Compile()).ToList();

            // Assert
            Assert.NotEmpty(result);
            Assert.Contains(result, t => t.NullableCharArray.SequenceEqual(randomHydra.NullableCharArray));
            Assert.DoesNotContain(result, t => t.NullableCharArray.SequenceEqual(randomHydra.NullableCharArray) == false);
        }
示例#19
0
        public void Assert_Nullable_Integer_Array_Inequality_Expression_With_List_Value_Is_Generated_Correctly()
        {
            // Arrange
            var randomHydra = Utilities.GetRandomItem(HydraArmy);
            var expression  = ExpressionBuilder.CreateBinary <Hydra>(nameof(Hydra.NullableIntegerArray), randomHydra.NullableIntegerArray.ToList(), ExpressionOperator.NotEqual);

            // Act
            var result = HydraArmy.Where(expression.Compile()).ToList();

            // Assert
            Assert.NotEmpty(result);
            Assert.Contains(result, t => t.NullableIntegerArray.SequenceEqual(randomHydra.NullableIntegerArray) == false);
            Assert.DoesNotContain(result, t => t.NullableIntegerArray.SequenceEqual(randomHydra.NullableIntegerArray));
        }
        public void Assert_DateTime_Array_Contains_Single_Value_Expression_Is_Generated_Correctly()
        {
            // Arrange
            var randomDateTime = Utilities.GetRandomItem(HydraArmy.Select(t => t.DateTimeArray)).FirstOrDefault();
            var expression     = ExpressionBuilder.CreateBinary <Hydra>(nameof(Hydra.DateTimeArray), randomDateTime, ExpressionOperator.Contains);

            // Act
            var result = HydraArmy.Where(expression.Compile()).ToList();

            // Assert
            Assert.NotEmpty(result);
            Assert.Contains(result, t => t.DateTimeArray.Contains(randomDateTime));
            Assert.DoesNotContain(result, t => t.DateTimeArray.Contains(randomDateTime) == false);
        }
示例#21
0
        public void Assert_Nullable_Integer_Collection_Contains_Single_Value_Expression_Is_Generated_Correctly()
        {
            // Arrange
            var randomInteger = Utilities.GetRandomItem(HydraArmy.Select(t => t.NullableIntegerCollection)).FirstOrDefault();
            var expression    = ExpressionBuilder.CreateBinary <Hydra>(nameof(Hydra.NullableIntegerCollection), randomInteger, ExpressionOperator.Contains);

            // Act
            var result = HydraArmy.Where(expression.Compile()).ToList();

            // Assert
            Assert.NotEmpty(result);
            Assert.Contains(result, t => t.NullableIntegerCollection.Contains(randomInteger));
            Assert.DoesNotContain(result, t => t.NullableIntegerCollection.Contains(randomInteger) == false);
        }
示例#22
0
        public void Assert_String_Contains_Dynamic_Query_Expression_Is_Generated_Correctly()
        {
            // Arrange
            var randomString = Utilities.GetRandomItem(HydraArmy.Select(t => string.Concat(t.FirstName, " ")));
            var expression   = ExpressionBuilder.CreateBinaryFromQuery <Hydra>(BuildQueryText(nameof(Hydra.FullName), randomString, ExpressionOperator.Contains));

            // Act
            var result = HydraArmy.Where(expression.Compile()).ToList();

            // Assert
            Assert.NotEmpty(result);
            Assert.Contains(result, t => randomString.Contains(t.FirstName));
            Assert.DoesNotContain(result, t => randomString.Contains(t.FirstName) == false);
        }
        public void Assert_Or_Composition_Gives_Correct_Result()
        {
            // Arrange
            var randomHydra1 = Utilities.GetRandomItem(HydraArmy);
            var randomHydra2 = Utilities.GetRandomItem(HydraArmy);
            var queryText    = ComposeQuery(BuildQueryText(nameof(Hydra.FullName), randomHydra1.FullName, ExpressionOperator.Equal), BuildQueryText(nameof(Hydra.DateTime), randomHydra2.DateTime, ExpressionOperator.Equal), ExpressionCompose.Or);
            var expression   = ExpressionBuilder.CreateBinaryFromQuery <Hydra>(queryText);

            // Act
            var result = HydraArmy.Where(expression.Compile()).ToList();

            // Assert
            Assert.NotEmpty(result);
            Assert.Contains(result, t => t.FullName == randomHydra1.FullName || t.DateTime == randomHydra2.DateTime);
            Assert.DoesNotContain(result, t => t.FullName != randomHydra1.FullName && t.DateTime != randomHydra2.DateTime);
        }