public void CalculateWhereConditionsLinqWhereQueryEngineContainedTest()
        {
            // Arrange
            var whereQueryEngine = new WhereQueryEngine(new WhereQueryEngineOptions());
            var queryParameters  = new QueryParameters
            {
                WhereQueryProperties = new List <WhereQueryProperty>
                {
                    new WhereQueryProperty
                    {
                        Operator     = CompareOperator.ContainedIn,
                        PropertyName = nameof(Alpha.Gamma),
                        SearchTerm   = "Black|White"
                    },
                }
            };

            var whereConditions = whereQueryEngine.BuildQueryExpressions <Alpha>(queryParameters);


            // Act
            var result = whereConditions.Data.CalculateWhereConditions();

            // Assert
            result.QueryParameter.Should().HaveCount(1);
            result.QueryParameter.Keys.First().Should().Be("p0Array");
            result.QueryParameter.Values.First().Should().BeOfType(typeof(List <string>));
            (result.QueryParameter.Values.First() as List <string>)[0].Should().Be("Black");
            (result.QueryParameter.Values.First() as List <string>)[1].Should().Be("White");

            result.Sql.Should().Be($"Gamma IN @p0Array{Environment.NewLine}");
        }
        public void CalculateWhereConditionsLinqWhereQueryEngineEnumLessThanOrEqualTest()
        {
            // Arrange
            var whereQueryEngine = new WhereQueryEngine(new WhereQueryEngineOptions());
            var queryParameters  = new QueryParameters
            {
                WhereQueryProperties = new List <WhereQueryProperty>
                {
                    new WhereQueryProperty
                    {
                        Operator     = CompareOperator.LessThanOrEqual,
                        PropertyName = nameof(Alpha.Delta),
                        SearchTerm   = Color.White.ToString()
                    },
                }
            };

            var whereConditions = whereQueryEngine.BuildQueryExpressions <Alpha>(queryParameters);


            // Act
            var result = whereConditions.Data.CalculateWhereConditions();

            // Assert
            result.QueryParameter.Should().HaveCount(2);
            result.QueryParameter.Keys.First().Should().Be("p0");
            result.QueryParameter.Keys.Last().Should().Be("p1");
            result.QueryParameter.Values.First().Should().Be(Color.White);
            result.QueryParameter.Values.Last().Should().Be(0);

            result.Sql.Should().Be($"((CASE WHEN {nameof(Alpha.Delta)} = @p0 THEN 0 WHEN {nameof(Alpha.Delta)} > @p0 THEN 1 ELSE -1 END) <= @p1){Environment.NewLine}");
        }
Beispiel #3
0
        public static WhereQueryResult AddWhereConditionsToQuery <T>(this IEnumerable <Expression <Func <T, bool> > > queryConditions, string sqlQuery, WhereQuerySettings settings = null) where T : class
        {
            var whereQueryEngine = new WhereQueryEngine();

            return(whereQueryEngine.AddWhereConditionsToQuery(queryConditions, sqlQuery, settings));
        }
Beispiel #4
0
        public static WhereQueryResult CalculateWhereConditions <T>(this IEnumerable <Expression <Func <T, bool> > > queryConditions, WhereQuerySettings settings = null) where T : class
        {
            var whereQueryEngine = new WhereQueryEngine();

            return(whereQueryEngine.CalculateWhereConditions(queryConditions, settings));
        }
 public void Setup()
 {
     _classUnderTest = new WhereQueryEngine();
 }