Ejemplo n.º 1
0
 /// <summary>
 /// Sets the default order.
 /// </summary>
 /// <param name="options">The options.</param>
 /// <param name="column">The column.</param>
 /// <param name="direction">The direction.</param>
 public static void SetDefaultOrder(this DataOptions options, string column, OrderDirection direction = OrderDirection.Asc)
 {
     if (!options.Order.By.Any())
     {
         options.Order.Add(column, direction);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Determines whether the specified data options has a column in the where section.
        /// </summary>
        /// <param name="options">The data options.</param>
        /// <param name="column">The column.</param>
        /// <returns>
        ///   <c>true</c> if a column is in the where section; otherwise, <c>false</c>.
        /// </returns>
        public static bool HasColumnInWhereSection(this DataOptions options, string column)
        {
            var filter = options.Filter;

            if (filter != null)
            {
                return(HasColumnInWhereSection(filter, column));
            }

            return(false);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Determines whether the specified data options has a column in sort-by section.
        /// </summary>
        /// <param name="options">The data options.</param>
        /// <param name="column">The column.</param>
        /// <returns>
        ///   <c>true</c> if a column is in the sort-by section; otherwise, <c>false</c>.
        /// </returns>
        public static bool HasColumnInSortBySection(this DataOptions options, string column)
        {
            var order = options.Order;

            if (order != null && order.By != null && order.By.Count > 0)
            {
                return(order.By.Count(f => f.Field != null && f.Field.ToLowerInvariant() == column.ToLowerInvariant()) > 0);
            }

            return(false);
        }
Ejemplo n.º 4
0
        public void SingleOrderByDescending()
        {
            var dataOptions = new DataOptions();
            dataOptions.Order.Add("CreatedOn", OrderDirection.Desc);

            var queryCreator = new DataOptionsQueryCreator<PageProperties>(dataOptions);
            var orderQuery = queryCreator.GetOrderQuery();
            var filterQuery = queryCreator.GetFilterQuery();
            var filterParameters = queryCreator.GetFilterParameters();

            Assert.IsNotNull(filterParameters);
            Assert.IsEmpty(filterParameters);
            Assert.AreEqual(filterQuery, string.Empty);

            Assert.AreEqual(orderQuery, "CreatedOn desc");
        }
Ejemplo n.º 5
0
        public void SingleFilterByEqualOptional()
        {
            var dataOptions = new DataOptions();
            dataOptions.Filter.Add("CreatedOn", TestValueDate);

            var queryCreator = new DataOptionsQueryCreator<PageProperties>(dataOptions);
            var orderQuery = queryCreator.GetOrderQuery();
            var filterQuery = queryCreator.GetFilterQuery();
            var filterParameters = queryCreator.GetFilterParameters();

            Assert.AreEqual(orderQuery, string.Empty);

            Assert.AreEqual(filterQuery, "CreatedOn == @0");
            Assert.IsNotNull(filterParameters);
            Assert.AreEqual(filterParameters.Length, 1);
            Assert.AreEqual(filterParameters[0], Convert.ToDateTime(TestValueDate));
        }
Ejemplo n.º 6
0
        public void ComplexFilterWithAndConnector()
        {
            var dataOptions = new DataOptions();
            dataOptions.Filter.Add("Title", "Test1", FilterOperation.NotContains);
            dataOptions.Filter.Add("Title", "Test2", FilterOperation.NotContains);

            var queryCreator = new DataOptionsQueryCreator<PageProperties>(dataOptions);
            var orderQuery = queryCreator.GetOrderQuery();
            var filterQuery = queryCreator.GetFilterQuery();
            var filterParameters = queryCreator.GetFilterParameters();

            Assert.AreEqual(orderQuery, string.Empty);

            Assert.AreEqual(filterQuery, "(!Title.Contains(@0) or Title == null) and (!Title.Contains(@1) or Title == null)");
            Assert.IsNotNull(filterParameters);
            Assert.AreEqual(filterParameters.Length, 2);
            Assert.AreEqual(filterParameters[0], "Test1");
            Assert.AreEqual(filterParameters[1], "Test2");
        }
Ejemplo n.º 7
0
        public void ComplexFilterWithInnerFilters()
        {
            var dataOptions = new DataOptions();
            dataOptions.Filter.Connector = FilterConnector.And;
            dataOptions.Filter.Add("Title", "Test1", FilterOperation.NotContains);
            dataOptions.Filter.Add("Title", "Test2", FilterOperation.NotContains);

            var innerFilter1 = new DataFilter(FilterConnector.Or);
            innerFilter1.Add("CreatedOn", TestValueDate, FilterOperation.Greater);
            innerFilter1.Add("CreatedOn", TestValueDate, FilterOperation.Less);
            innerFilter1.Add("CreatedOn", TestValueDate);

            var innerFilter2 = new DataFilter(FilterConnector.Or);
            innerFilter2.Add("ModifiedOn", TestValueDate, FilterOperation.Greater);
            innerFilter2.Add("ModifiedOn", TestValueDate, FilterOperation.Less);
            innerFilter2.Add("ModifiedOn", TestValueDate);

            dataOptions.Filter.Inner.Add(innerFilter1);
            dataOptions.Filter.Inner.Add(innerFilter2);

            var queryCreator = new DataOptionsQueryCreator<PageProperties>(dataOptions);
            var orderQuery = queryCreator.GetOrderQuery();
            var filterQuery = queryCreator.GetFilterQuery();
            var filterParameters = queryCreator.GetFilterParameters();

            Assert.AreEqual(orderQuery, string.Empty);

            var result = "(!Title.Contains(@0) or Title == null) and (!Title.Contains(@1) or Title == null) and (CreatedOn > @2 or CreatedOn < @3 or CreatedOn == @4) and (ModifiedOn > @5 or ModifiedOn < @6 or ModifiedOn == @7)";

            Assert.AreEqual(filterQuery, result);
            Assert.IsNotNull(filterParameters);
            Assert.AreEqual(filterParameters.Length, 8);
            Assert.AreEqual(filterParameters[0], "Test1");
            Assert.AreEqual(filterParameters[1], "Test2");
            Assert.AreEqual(filterParameters[2], Convert.ToDateTime(TestValueDate));
            Assert.AreEqual(filterParameters[3], Convert.ToDateTime(TestValueDate));
            Assert.AreEqual(filterParameters[4], Convert.ToDateTime(TestValueDate));
            Assert.AreEqual(filterParameters[5], Convert.ToDateTime(TestValueDate));
            Assert.AreEqual(filterParameters[6], Convert.ToDateTime(TestValueDate));
            Assert.AreEqual(filterParameters[7], Convert.ToDateTime(TestValueDate));
        }
Ejemplo n.º 8
0
        public void NotExistingFilterProperty()
        {
            var dataOptions = new DataOptions();
            dataOptions.Filter.Add("NotExistingProperty", null);

            var queryCreator = new DataOptionsQueryCreator<PageProperties>(dataOptions);
            queryCreator.GetFilterQuery();
        }
Ejemplo n.º 9
0
        public void MoreComplexFilterWithOrConnector()
        {
            var dataOptions = new DataOptions();
            dataOptions.Filter.Connector = FilterConnector.Or;
            dataOptions.Filter.Add("Title", "Test1", FilterOperation.NotContains);
            dataOptions.Filter.Add("Title", "Test2", FilterOperation.Equal);
            dataOptions.Filter.Add("Title", "Test3", FilterOperation.NotEqual);
            dataOptions.Filter.Add("Title", "Test4", FilterOperation.StartsWith);

            var queryCreator = new DataOptionsQueryCreator<PageProperties>(dataOptions);
            var orderQuery = queryCreator.GetOrderQuery();
            var filterQuery = queryCreator.GetFilterQuery();
            var filterParameters = queryCreator.GetFilterParameters();

            Assert.AreEqual(orderQuery, string.Empty);

            Assert.AreEqual(filterQuery, "(!Title.Contains(@0) or Title == null) or Title == @1 or (Title != @2 or Title == null) or Title.StartsWith(@3)");
            Assert.IsNotNull(filterParameters);
            Assert.AreEqual(filterParameters.Length, 4);
            Assert.AreEqual(filterParameters[0], "Test1");
            Assert.AreEqual(filterParameters[1], "Test2");
            Assert.AreEqual(filterParameters[2], "Test3");
            Assert.AreEqual(filterParameters[3], "Test4");
        }
Ejemplo n.º 10
0
        public void SingleFilterByEndsWith()
        {
            var dataOptions = new DataOptions();
            dataOptions.Filter.Add("Title", TestValueString, FilterOperation.EndsWith);

            var queryCreator = new DataOptionsQueryCreator<PageProperties>(dataOptions);
            var orderQuery = queryCreator.GetOrderQuery();
            var filterQuery = queryCreator.GetFilterQuery();
            var filterParameters = queryCreator.GetFilterParameters();

            Assert.AreEqual(orderQuery, string.Empty);

            Assert.AreEqual(filterQuery, "Title.EndsWith(@0)");
            Assert.IsNotNull(filterParameters);
            Assert.AreEqual(filterParameters.Length, 1);
            Assert.AreEqual(filterParameters[0], TestValueString);
        }
Ejemplo n.º 11
0
        private DataOptions CreateTestDataOptions()
        {
            var options = new DataOptions(5, 3);
            options.Filter.Add("CreatedOn", new DateTime(2013, 06, 01), FilterOperation.Greater);
            options.Filter.Add("Title", "Africa", FilterOperation.NotEqual);

            var subFilter = new DataFilter(FilterConnector.Or);
            subFilter.Add("Title", "It", FilterOperation.StartsWith);
            subFilter.Add("Title", "Af", FilterOperation.StartsWith);
            subFilter.Add("Title", "na", FilterOperation.EndsWith);
            subFilter.Add("Title", "Spain");

            options.Filter.Inner.Add(subFilter);

            options.Order.Add("CreatedOn");
            options.Order.Add("Title", OrderDirection.Desc);

            return options;
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Determines whether the specified options has paging.
 /// </summary>
 /// <param name="options">The options.</param>
 /// <returns>
 ///   <c>true</c> if the specified options has paging; otherwise, <c>false</c>.
 /// </returns>
 public static bool HasPaging(this DataOptions options)
 {
     return(options != null && options.Take > 0);
 }