Пример #1
0
        public void Format_WhenUpperInclusive_ExpectCorrectSql()
        {
            // Arrange
            var rangeFormatter = new RangeFormatter();

            var node = new RangeOperator
            {
                Name           = "ColumnName",
                Lower          = 25,
                Upper          = 100,
                LowerInclusive = false,
                UpperInclusive = true,
            };

            // Act
            var stopwatch       = Stopwatch.StartNew();
            var sqlDataResponse = rangeFormatter.Format(node, 0);

            stopwatch.Stop();

            // Assert
            this.WriteTimeElapsed(stopwatch);

            Assert.That(sqlDataResponse.Sql, Is.EqualTo("ColumnName > @ColumnName0 AND ColumnName <= @ColumnName1"));
            Assert.That(sqlDataResponse.Params.First(r => r.VarName == "ColumnName0").Value, Is.EqualTo(25));
            Assert.That(sqlDataResponse.Params.First(r => r.VarName == "ColumnName1").Value, Is.EqualTo(100));
        }
Пример #2
0
 /// <summary>
 /// Determines whether the supplied compare operator is true, by comparing the supplied value against the supplied comparison.
 /// </summary>
 /// <param name="op">The operation to use for comparing value to comparison.</param>
 /// <param name="value">The value.</param>
 /// <param name="comparison">The comparison to use for comparing value against.</param>
 /// <returns>True if the compare operator evaluates true</returns>
 public static bool IsOperatorTrue(RangeOperator op, float value, float comparison)
 {
     return(op == RangeOperator.None ||
            (op == RangeOperator.Equals && value == comparison) ||
            (op == RangeOperator.GreaterThan && value > comparison) ||
            (op == RangeOperator.GreaterThanOrEquals && value >= comparison) ||
            (op == RangeOperator.LessThan && value < comparison) ||
            (op == RangeOperator.LessThanOrEquals && value <= comparison));
 }
        public void ValidateCorrectly(bool expectedValid, object start, object end, RangeOperator op)
        {
            var sut = new FilterRange
            {
                Start         = start,
                End           = end,
                RangeOperator = op
            };

            Assert.Equal(expectedValid, sut.IsValid);
            Assert.Equal(!expectedValid, sut.IsInvalid);
        }
        /// <summary>
        /// Create an operation specific predicate
        /// </summary>
        /// <param name="name">Parameterized property name</param>
        /// <param name="startValue">Parameterized start value</param>
        /// <param name="endValue">Parameterized end value</param>
        /// <param name="operator">Operator</param>
        /// <returns></returns>
        public static string Create(string name, string startValue, string endValue, RangeOperator @operator)
        {
            string predicate;

            switch (@operator)
            {
            case RangeOperator.Between:
                predicate = $"{name} >= {startValue} And {name} <= {endValue}";
                break;

            case RangeOperator.NotBetween:
                predicate = $"{name} < {startValue} Or {name} > {endValue}";
                break;

            default:
                throw new ArgumentException($"'{@operator}' is not a valid operation.");
            }
            return(predicate);
        }
Пример #5
0
        public void CreateExpressionTest1()
        {
            // Arrange
            Expression parameterExpression = Expression.Parameter(typeof(Employee), "sample");
            Expression expressionProperty  = Expression.Property(parameterExpression, nameof(Employee.Age));
            Expression expressionConstant  = Expression.Constant(10);

            var leftSide  = Expression.GreaterThanOrEqual(expressionProperty, expressionConstant);
            var rightSide = Expression.LessThanOrEqual(expressionProperty, expressionConstant);

            Expression expectedExpression = Expression.And(leftSide, rightSide);

            var _operator = new RangeOperator();

            // Act
            Expression resultExpression = _operator.CreateExpression(expressionProperty, expressionConstant);

            // Assert
            Assert.AreEqual(expectedExpression.ToString(), resultExpression.ToString(), "Expression not correct");
        }
Пример #6
0
        public BannedIpQuery WithExpireDateUtcBetween(DateTime?from = null,
                                                      ArgumentEvaluationMode fromMode = ArgumentEvaluationMode.IgnoreNeutral,
                                                      DateTime?to = null,
                                                      ArgumentEvaluationMode toMode = ArgumentEvaluationMode.IgnoreNeutral,
                                                      RangeOperator @operator       = RangeOperator.Inside)
        {
            switch (@operator)
            {
            case RangeOperator.Inside:
                switch (fromMode)
                {
                case ArgumentEvaluationMode.IgnoreNeutral:
                    if (!Neutrals.Is(from))
                    {
                        Entities = Entities.Where(bi => bi.ExpireDateUtc >= from);
                    }
                    break;

                case ArgumentEvaluationMode.Explicit:
                    Entities = Entities.Where(bi => bi.ExpireDateUtc == from);
                    break;

                default:
                    throw new NotSupportedEnumException(fromMode);
                }

                switch (toMode)
                {
                case ArgumentEvaluationMode.IgnoreNeutral:
                    if (!Neutrals.Is(to))
                    {
                        Entities = Entities.Where(bi => bi.ExpireDateUtc <= to);
                    }
                    break;

                case ArgumentEvaluationMode.Explicit:
                    Entities = Entities.Where(bi => bi.ExpireDateUtc == to);
                    break;

                default:
                    throw new NotSupportedEnumException(toMode);
                }
                break;

            case RangeOperator.Outside:
                switch (fromMode)
                {
                case ArgumentEvaluationMode.IgnoreNeutral:
                    if (!Neutrals.Is(from))
                    {
                        Entities = Entities.Where(bi => bi.ExpireDateUtc <= from);
                    }
                    break;

                case ArgumentEvaluationMode.Explicit:
                    Entities = Entities.Where(bi => bi.ExpireDateUtc == from);
                    break;

                default:
                    throw new NotSupportedEnumException(fromMode);
                }

                switch (toMode)
                {
                case ArgumentEvaluationMode.IgnoreNeutral:
                    if (!Neutrals.Is(to))
                    {
                        Entities = Entities.Where(bi => bi.ExpireDateUtc >= to);
                    }
                    break;

                case ArgumentEvaluationMode.Explicit:
                    Entities = Entities.Where(bi => bi.ExpireDateUtc == to);
                    break;

                default:
                    throw new NotSupportedEnumException(toMode);
                }
                break;

            default:
                throw new NotSupportedEnumException(@operator);
            }

            return(this);
        }
        public QueuedEmailQuery WithSendingTriesBetween(int?from = null,
                                                        ArgumentEvaluationMode fromMode = ArgumentEvaluationMode.IgnoreNeutral,
                                                        int?to = null,
                                                        ArgumentEvaluationMode toMode = ArgumentEvaluationMode.IgnoreNeutral,
                                                        RangeOperator @operator       = RangeOperator.Inside)
        {
            switch (@operator)
            {
            case RangeOperator.Inside:
                switch (fromMode)
                {
                case ArgumentEvaluationMode.IgnoreNeutral:
                    if (!Neutrals.Is(from))
                    {
                        Entities = Entities.Where(qe => qe.SendingTries >= from);
                    }
                    break;

                case ArgumentEvaluationMode.Explicit:
                    Entities = Entities.Where(qe => qe.SendingTries == from);
                    break;

                default:
                    throw new NotSupportedEnumException(fromMode);
                }

                switch (toMode)
                {
                case ArgumentEvaluationMode.IgnoreNeutral:
                    if (!Neutrals.Is(to))
                    {
                        Entities = Entities.Where(qe => qe.SendingTries <= to);
                    }
                    break;

                case ArgumentEvaluationMode.Explicit:
                    Entities = Entities.Where(qe => qe.SendingTries == to);
                    break;

                default:
                    throw new NotSupportedEnumException(toMode);
                }
                break;

            case RangeOperator.Outside:
                switch (fromMode)
                {
                case ArgumentEvaluationMode.IgnoreNeutral:
                    if (!Neutrals.Is(from))
                    {
                        Entities = Entities.Where(qe => qe.SendingTries <= from);
                    }
                    break;

                case ArgumentEvaluationMode.Explicit:
                    Entities = Entities.Where(qe => qe.SendingTries == from);
                    break;

                default:
                    throw new NotSupportedEnumException(fromMode);
                }

                switch (toMode)
                {
                case ArgumentEvaluationMode.IgnoreNeutral:
                    if (!Neutrals.Is(to))
                    {
                        Entities = Entities.Where(qe => qe.SendingTries >= to);
                    }
                    break;

                case ArgumentEvaluationMode.Explicit:
                    Entities = Entities.Where(qe => qe.SendingTries == to);
                    break;

                default:
                    throw new NotSupportedEnumException(toMode);
                }
                break;

            default:
                throw new NotSupportedEnumException(@operator);
            }

            return(this);
        }
Пример #8
0
        public ScheduleTaskQuery WithMaximumRunningSecondsBetween(int?from = null,
                                                                  ArgumentEvaluationMode fromMode = ArgumentEvaluationMode.IgnoreNeutral,
                                                                  int?to = null,
                                                                  ArgumentEvaluationMode toMode = ArgumentEvaluationMode.IgnoreNeutral,
                                                                  RangeOperator @operator       = RangeOperator.Inside)
        {
            switch (@operator)
            {
            case RangeOperator.Inside:
                switch (fromMode)
                {
                case ArgumentEvaluationMode.IgnoreNeutral:
                    if (!Neutrals.Is(from))
                    {
                        Entities = Entities.Where(st => st.MaximumRunningSeconds >= from);
                    }
                    break;

                case ArgumentEvaluationMode.Explicit:
                    Entities = Entities.Where(st => st.MaximumRunningSeconds == from);
                    break;

                default:
                    throw new NotSupportedEnumException(fromMode);
                }

                switch (toMode)
                {
                case ArgumentEvaluationMode.IgnoreNeutral:
                    if (!Neutrals.Is(to))
                    {
                        Entities = Entities.Where(st => st.MaximumRunningSeconds <= to);
                    }
                    break;

                case ArgumentEvaluationMode.Explicit:
                    Entities = Entities.Where(st => st.MaximumRunningSeconds == to);
                    break;

                default:
                    throw new NotSupportedEnumException(toMode);
                }
                break;

            case RangeOperator.Outside:
                switch (fromMode)
                {
                case ArgumentEvaluationMode.IgnoreNeutral:
                    if (!Neutrals.Is(from))
                    {
                        Entities = Entities.Where(st => st.MaximumRunningSeconds <= from);
                    }
                    break;

                case ArgumentEvaluationMode.Explicit:
                    Entities = Entities.Where(st => st.MaximumRunningSeconds == from);
                    break;

                default:
                    throw new NotSupportedEnumException(fromMode);
                }

                switch (toMode)
                {
                case ArgumentEvaluationMode.IgnoreNeutral:
                    if (!Neutrals.Is(to))
                    {
                        Entities = Entities.Where(st => st.MaximumRunningSeconds >= to);
                    }
                    break;

                case ArgumentEvaluationMode.Explicit:
                    Entities = Entities.Where(st => st.MaximumRunningSeconds == to);
                    break;

                default:
                    throw new NotSupportedEnumException(toMode);
                }
                break;

            default:
                throw new NotSupportedEnumException(@operator);
            }

            return(this);
        }
Пример #9
0
        public LogQuery WithInvokerIdBetween(long?from = null,
                                             ArgumentEvaluationMode fromMode = ArgumentEvaluationMode.IgnoreNeutral,
                                             long?to = null,
                                             ArgumentEvaluationMode toMode = ArgumentEvaluationMode.IgnoreNeutral,
                                             RangeOperator @operator       = RangeOperator.Inside)
        {
            switch (@operator)
            {
            case RangeOperator.Inside:
                switch (fromMode)
                {
                case ArgumentEvaluationMode.IgnoreNeutral:
                    if (!Neutrals.Is(from))
                    {
                        Entities = Entities.Where(l => l.Invoker.Id >= from);
                    }
                    break;

                case ArgumentEvaluationMode.Explicit:
                    Entities = Entities.Where(l => l.Invoker.Id == from);
                    break;

                default:
                    throw new NotSupportedEnumException(fromMode);
                }

                switch (toMode)
                {
                case ArgumentEvaluationMode.IgnoreNeutral:
                    if (!Neutrals.Is(to))
                    {
                        Entities = Entities.Where(l => l.Invoker.Id <= to);
                    }
                    break;

                case ArgumentEvaluationMode.Explicit:
                    Entities = Entities.Where(l => l.Invoker.Id == to);
                    break;

                default:
                    throw new NotSupportedEnumException(toMode);
                }
                break;

            case RangeOperator.Outside:
                switch (fromMode)
                {
                case ArgumentEvaluationMode.IgnoreNeutral:
                    if (!Neutrals.Is(from))
                    {
                        Entities = Entities.Where(l => l.Invoker.Id <= from);
                    }
                    break;

                case ArgumentEvaluationMode.Explicit:
                    Entities = Entities.Where(l => l.Invoker.Id == from);
                    break;

                default:
                    throw new NotSupportedEnumException(fromMode);
                }

                switch (toMode)
                {
                case ArgumentEvaluationMode.IgnoreNeutral:
                    if (!Neutrals.Is(to))
                    {
                        Entities = Entities.Where(l => l.Invoker.Id >= to);
                    }
                    break;

                case ArgumentEvaluationMode.Explicit:
                    Entities = Entities.Where(l => l.Invoker.Id == to);
                    break;

                default:
                    throw new NotSupportedEnumException(toMode);
                }
                break;

            default:
                throw new NotSupportedEnumException(@operator);
            }

            return(this);
        }
Пример #10
0
        public static Filter SetRange(this Filter filter, object start = null, object end = null, RangeOperator rangeOperator = (RangeOperator)0)
        {
            filter ??= new Filter();

            var range = new FilterRange
            {
                Start         = start,
                End           = end,
                RangeOperator = rangeOperator,
            };

            filter.Range = range;

            return(filter);
        }
Пример #11
0
        public OrderLineQuery WithPriceBetween(int?from = null,
                                               ArgumentEvaluationMode fromMode = ArgumentEvaluationMode.IgnoreNeutral,
                                               int?to = null,
                                               ArgumentEvaluationMode toMode = ArgumentEvaluationMode.IgnoreNeutral,
                                               RangeOperator @operator       = RangeOperator.Inside)
        {
            switch (@operator)
            {
            case RangeOperator.Inside:
                switch (fromMode)
                {
                case ArgumentEvaluationMode.IgnoreNeutral:
                    if (!Neutrals.Is(from))
                    {
                        Entities = Entities.Where(ol => ol.Price >= from);
                    }
                    break;

                case ArgumentEvaluationMode.Explicit:
                    Entities = Entities.Where(ol => ol.Price == from);
                    break;

                default:
                    throw new NotSupportedEnumException(fromMode);
                }

                switch (toMode)
                {
                case ArgumentEvaluationMode.IgnoreNeutral:
                    if (!Neutrals.Is(to))
                    {
                        Entities = Entities.Where(ol => ol.Price <= to);
                    }
                    break;

                case ArgumentEvaluationMode.Explicit:
                    Entities = Entities.Where(ol => ol.Price == to);
                    break;

                default:
                    throw new NotSupportedEnumException(toMode);
                }
                break;

            case RangeOperator.Outside:
                switch (fromMode)
                {
                case ArgumentEvaluationMode.IgnoreNeutral:
                    if (!Neutrals.Is(from))
                    {
                        Entities = Entities.Where(ol => ol.Price <= from);
                    }
                    break;

                case ArgumentEvaluationMode.Explicit:
                    Entities = Entities.Where(ol => ol.Price == from);
                    break;

                default:
                    throw new NotSupportedEnumException(fromMode);
                }

                switch (toMode)
                {
                case ArgumentEvaluationMode.IgnoreNeutral:
                    if (!Neutrals.Is(to))
                    {
                        Entities = Entities.Where(ol => ol.Price >= to);
                    }
                    break;

                case ArgumentEvaluationMode.Explicit:
                    Entities = Entities.Where(ol => ol.Price == to);
                    break;

                default:
                    throw new NotSupportedEnumException(toMode);
                }
                break;

            default:
                throw new NotSupportedEnumException(@operator);
            }

            return(this);
        }
        public TQuery WithDisplayOrderBetween(short?from = null,
                                              ArgumentEvaluationMode fromMode = ArgumentEvaluationMode.IgnoreNeutral,
                                              short?to = null,
                                              ArgumentEvaluationMode toMode = ArgumentEvaluationMode.IgnoreNeutral,
                                              RangeOperator @operator       = RangeOperator.Inside)
        {
            switch (@operator)
            {
            case RangeOperator.Inside:
                switch (fromMode)
                {
                case ArgumentEvaluationMode.IgnoreNeutral:
                    if (!Neutrals.Is(from))
                    {
                        Entities = Entities.Where(uie => uie.DisplayOrder >= from);
                    }
                    break;

                case ArgumentEvaluationMode.Explicit:
                    Entities = Entities.Where(uie => uie.DisplayOrder == from);
                    break;

                default:
                    throw new NotSupportedEnumException(fromMode);
                }

                switch (toMode)
                {
                case ArgumentEvaluationMode.IgnoreNeutral:
                    if (!Neutrals.Is(to))
                    {
                        Entities = Entities.Where(uie => uie.DisplayOrder <= to);
                    }
                    break;

                case ArgumentEvaluationMode.Explicit:
                    Entities = Entities.Where(uie => uie.DisplayOrder == to);
                    break;

                default:
                    throw new NotSupportedEnumException(toMode);
                }
                break;

            case RangeOperator.Outside:
                switch (fromMode)
                {
                case ArgumentEvaluationMode.IgnoreNeutral:
                    if (!Neutrals.Is(from))
                    {
                        Entities = Entities.Where(uie => uie.DisplayOrder <= from);
                    }
                    break;

                case ArgumentEvaluationMode.Explicit:
                    Entities = Entities.Where(uie => uie.DisplayOrder == from);
                    break;

                default:
                    throw new NotSupportedEnumException(fromMode);
                }

                switch (toMode)
                {
                case ArgumentEvaluationMode.IgnoreNeutral:
                    if (!Neutrals.Is(to))
                    {
                        Entities = Entities.Where(uie => uie.DisplayOrder >= to);
                    }
                    break;

                case ArgumentEvaluationMode.Explicit:
                    Entities = Entities.Where(uie => uie.DisplayOrder == to);
                    break;

                default:
                    throw new NotSupportedEnumException(toMode);
                }
                break;

            default:
                throw new NotSupportedEnumException(@operator);
            }

            return((TQuery)this);
        }
Пример #13
0
 public override T VisitRangeOperator(RangeOperator node)
 {
     throw new NotImplementedException();
 }