Esempio n. 1
0
        public void Create_ForType()
        {
            IGridFilter actual = filters.Create(typeof(String), "CONTAINS", new String[0]);

            Assert.IsType <StringContainsFilter>(actual);
            Assert.Equal("contains", actual.Method);
        }
Esempio n. 2
0
        public void Create_ForEnumType()
        {
            IGridFilter actual = filters.Create(typeof(TestEnum), "EQUALS", new String[0]);

            Assert.Equal("equals", actual.Method);
            Assert.IsType <EnumFilter>(actual);
        }
Esempio n. 3
0
        public void GetFilter_ForEnumType()
        {
            IGridFilter actual = filters.GetFilter(typeof(TestEnum), "EQUALS");

            Assert.Equal("equals", actual.Method);
            Assert.IsType <EnumFilter>(actual);
        }
Esempio n. 4
0
        public void GetFilter_ForNullableType()
        {
            IGridFilter actual = filters.GetFilter(typeof(Int32?), "EQUALS");

            Assert.IsType <NumberFilter <Int32> >(actual);
            Assert.Equal("equals", actual.Method);
        }
Esempio n. 5
0
        public IGridFilter <T> GetFilter <T>(IGridColumn <T> column, String type, String value)
        {
            Type valueType = Nullable.GetUnderlyingType(column.Expression.ReturnType) ?? column.Expression.ReturnType;

            if (!Table.ContainsKey(valueType))
            {
                return(null);
            }

            IDictionary <String, Type> typedFilters = Table[valueType];

            if (!typedFilters.ContainsKey(type))
            {
                return(null);
            }

            Type            filterType = typedFilters[type].MakeGenericType(typeof(T));
            IGridFilter <T> filter     = (IGridFilter <T>)Activator.CreateInstance(filterType);

            filter.FilteredExpression = column.Expression;
            filter.Value = value;
            filter.Type  = type;

            return(filter);
        }
Esempio n. 6
0
        public void GetFilter_ForType()
        {
            IGridFilter actual = filters.GetFilter(typeof(String), "CONTAINS");

            Assert.IsType <StringContainsFilter>(actual);
            Assert.Equal("contains", actual.Method);
        }
Esempio n. 7
0
        public virtual IGridFilter GetFilter(Type type, String method)
        {
            type = Nullable.GetUnderlyingType(type) ?? type;

            if (!Filters.ContainsKey(type))
            {
                if (type.GetTypeInfo().IsEnum&& Filters.ContainsKey(typeof(Enum)))
                {
                    type = typeof(Enum);
                }
                else
                {
                    return(null);
                }
            }

            if (!Filters[type].TryGetValue(method, out Type filterType))
            {
                return(null);
            }

            IGridFilter filter = (IGridFilter)Activator.CreateInstance(filterType);

            filter.Method = method.ToLower();

            return(filter);
        }
Esempio n. 8
0
        public void Create_ForNullableType()
        {
            IGridFilter actual = filters.Create(typeof(Int32?), "EQUALS", new String[0]);

            Assert.IsType <NumberFilter <Int32> >(actual);
            Assert.Equal("equals", actual.Method);
        }
        /// <summary>
        /// Creates a <see cref="IGridFilter"/> for the specified arguments.
        /// It calls <see cref="CreateGridFilterInternal"/> which must be overridden
        /// by any implementing class and raises the <see cref="GridFilterCreated"/>
        /// afterwards.
        /// </summary>
        /// <param name="column">The <see cref="DataColumn"/> for which the filter control should be created.</param>
        /// <returns>A <see cref="IGridFilter"/>.</returns>
        public IGridFilter CreateGridFilter(DataGridViewColumn column)
        {
            IGridFilter         gridFilter          = CreateGridFilterInternal(column);
            GridFilterEventArgs gridFilterEventArgs = new GridFilterEventArgs(column, gridFilter);

            OnGridFilterCreated(gridFilterEventArgs);
            return(gridFilterEventArgs.GridFilter);
        }
Esempio n. 10
0
        public void GetFilter_ForSpecificEnumType()
        {
            filters.Register(typeof(TestEnum), "equals", typeof(StringEqualsFilter));

            IGridFilter actual = filters.GetFilter(typeof(TestEnum), "EQUALS");

            Assert.IsType <StringEqualsFilter>(actual);
            Assert.Equal("equals", actual.Method);
        }
Esempio n. 11
0
        public void Filter_OnGridQueryWithoutFilterSetsFilterToNull(String query)
        {
            grid.Query = HttpUtility.ParseQueryString(query);
            IGridFilter <GridModel> filter = Substitute.For <IGridFilter <GridModel> >();

            MvcGrid.Filters.GetFilter(Arg.Any <IGridColumn <GridModel> >(), Arg.Any <String>(), Arg.Any <String>()).Returns(filter);

            Assert.IsNull(column.Filter);
        }
Esempio n. 12
0
        public void GetFilter_SetsFirstFilter(String query, String type, String value)
        {
            column.Grid.Query = HttpUtility.ParseQueryString(query);

            IGridFilter actual = filters.GetFilter(column).First;

            Assert.Equal(typeof(StringEqualsFilter), actual.GetType());
            Assert.Equal(value, actual.Value);
            Assert.Equal(type, actual.Type);
        }
Esempio n. 13
0
        private IGridFilter GetFilter(String method, String value)
        {
            IGridFilter filter = GetFilters().GetFilter(typeof(TValue), method);

            if (filter != null)
            {
                filter.Value = value;
            }

            return(filter);
        }
Esempio n. 14
0
        public void GetFilter_OnNotFoundValueTypeReturnsNull()
        {
            IGridColumn <GridModel> column = Substitute.For <IGridColumn <GridModel> >();
            Expression <Func <GridModel, Object> > expression = (model) => 0;

            column.Expression.Returns(expression);

            IGridFilter <GridModel> filter = filters.GetFilter <GridModel>(column, "Equals", "1");

            Assert.IsNull(filter);
        }
Esempio n. 15
0
        public void First_Get_FromQuery(String name, String query, String value)
        {
            filter.Column.Grid.Name  = name;
            filter.Column.Grid.Query = HttpUtility.ParseQueryString(query);

            IGridFilter actual = filter.First !;

            Assert.Equal(value, actual.Values.Single());
            Assert.IsType <StringEqualsFilter>(actual);
            Assert.Equal("equals", actual.Method);
        }
Esempio n. 16
0
        public void GetFilter_SetsSecondFilter(String name, String query, String value)
        {
            column.Grid.Name  = name;
            column.Grid.Query = HttpUtility.ParseQueryString(query);

            IGridFilter actual = filters.GetFilter(column).Second;

            Assert.Equal(typeof(StringEqualsFilter), actual.GetType());
            Assert.Equal("Equals", actual.Type);
            Assert.Equal(value, actual.Value);
        }
Esempio n. 17
0
        public void Second_Get_FromQuery(String name, String query, String value)
        {
            filter.Column.Grid.Name  = name;
            filter.Column.Grid.Query = HttpUtility.ParseQueryString(query);

            IGridFilter actual = filter.Second;

            Assert.Equal(typeof(StringEqualsFilter), actual.GetType());
            Assert.Equal("equals", actual.Method);
            Assert.Equal(value, actual.Value);
        }
Esempio n. 18
0
        public void GetFilter_OnNotFoundFilterTypeReturnsNull()
        {
            IGridColumn <GridModel> column = Substitute.For <IGridColumn <GridModel> >();
            Expression <Func <GridModel, String> > expression = (model) => "Test";

            column.Expression.Returns(expression);

            IGridFilter <GridModel> filter = filters.GetFilter <GridModel>(column, "GreaterThan", "Test");

            Assert.IsNull(filter);
        }
        public void First_Get_MultiFilter(String name, String query, String value)
        {
            filter.Column.Grid.Name  = name;
            filter.Type              = GridFilterType.Multi;
            filter.Column.Grid.Query = HttpUtility.ParseQueryString(query);

            IGridFilter actual = filter.First !;

            Assert.Equal("equals", actual.Method);
            Assert.IsType <StringFilter>(actual);
            Assert.Equal(value, actual.Values);
        }
        public void Second_Get_FromQuery(String name, String query, String value)
        {
            filter.Column.Grid.Name  = name;
            filter.Type              = GridFilterType.Double;
            filter.Column.Grid.Query = HttpUtility.ParseQueryString(query);

            IGridFilter actual = filter.Second !;

            Assert.Equal("equals", actual.Method);
            Assert.IsType <StringFilter>(actual);
            Assert.Equal(value, actual.Values);
        }
Esempio n. 21
0
        public virtual IGridFilter?Create(Type type, String method, StringValues values)
        {
            if (Get(Nullable.GetUnderlyingType(type) ?? type, method) is Type filterType)
            {
                IGridFilter filter = (IGridFilter)Activator.CreateInstance(filterType);
                filter.Method = method.ToLower();
                filter.Values = values;

                return(filter);
            }

            return(null);
        }
Esempio n. 22
0
        public void Filter_DoesNotChangeFilterAfterItsSet()
        {
            String query = "Grid-Name-Equals=Test";

            grid.Query = HttpUtility.ParseQueryString(query);
            IGridFilter <GridModel> filter = Substitute.For <IGridFilter <GridModel> >();

            MvcGrid.Filters.GetFilter(Arg.Any <IGridColumn <GridModel> >(), Arg.Any <String>(), Arg.Any <String>()).Returns(filter);

            column.Filter = null;

            Assert.IsNull(column.Filter);
        }
        /// <summary>
        /// Creates a new instance.
        /// </summary>
        /// <param name="columns">List of <see cref="DataGridViewColumn"/>s which are associated with <see cref="IGridFilter"/>s.</param>
        /// <param name="columnsToGridFiltersHash">Mapping between <see cref="DataGridViewColumn"/>s and <see cref="IGridFilter"/>s.</param>
        internal GridFilterCollection(IList columns, Hashtable columnsToGridFiltersHash)
        {
            _columnsToGridFiltersHash = (Hashtable)columnsToGridFiltersHash.Clone();

            foreach (DataGridViewColumn column in columns)
            {
                IGridFilter gridFilter = (IGridFilter)_columnsToGridFiltersHash[column];
                if (gridFilter != null)
                {
                    base.InnerList.Add(gridFilter);
                }
            }
        }
Esempio n. 24
0
        public void Filter_SetsFilterThenItsNotSet(String query, String type, String value)
        {
            grid.Query = HttpUtility.ParseQueryString(query);
            IGridFilter <GridModel> filter = Substitute.For <IGridFilter <GridModel> >();

            MvcGrid.Filters.GetFilter(Arg.Any <IGridColumn <GridModel> >(), type, value).Returns(filter);

            Object actual   = column.Filter;
            Object expected = filter;

            MvcGrid.Filters.Received().GetFilter(column, type, value);
            Assert.AreSame(expected, actual);
        }
        /// <summary>
        /// Creates a new instance of <see cref="IGridFilter"/>.
        /// The concrete implementation depends on the given datatype.
        /// The parameters tablename and columnanem are ignored in this implementation.
        /// </summary>
        /// <param name="column">The <see cref="DataColumn"/> for which the filter control should be created.</param>
        /// <returns>A <see cref="IGridFilter"/>.</returns>
        protected override IGridFilter CreateGridFilterInternal(DataGridViewColumn column)
        {
            IGridFilter result = null;

            Type dataType = column.ValueType;

            if (column.ValueType == null)
            {
                return(new EmptyGridFilter());
            }

            if (dataType.IsEnum && _handleEnumerationTypes)
            {
                result = new EnumerationGridFilter(dataType);
            }
            else if (_createDistinctGridFilters)
            {
                bool     containsDbNull;
                string[] values = DistinctValuesGridFilter.GetDistinctValues(column, _maximumDistinctValues, out containsDbNull);
                if (values != null)
                {
                    result = new DistinctValuesGridFilter(values, containsDbNull);
                }
            }

            if (result == null)
            {
                if (_hash.ContainsKey(dataType))
                {
                    Type gridFilterType = _hash[dataType] as Type;
                    result = gridFilterType.Assembly.CreateInstance(gridFilterType.FullName) as IGridFilter;
                }
                else if (_defaultGridFilterType != null)
                {
                    result = _defaultGridFilterType.Assembly.CreateInstance(_defaultGridFilterType.FullName) as IGridFilter;
                }
            }

            if (result is DateGridFilter)
            {
                (result as DateGridFilter).ShowInBetweenOperator = _defaultShowDateInBetweenOperator;
            }
            if (result is NumericGridFilter)
            {
                (result as NumericGridFilter).ShowInBetweenOperator = _defaultShowNumericInBetweenOperator;
            }

            return(result);
        }
 /// <summary>
 /// Sets all filters to the specified values.
 /// The values must be in order of the column styles in the current view.
 /// This function should normally be used with data previously coming
 /// from the <see cref="GetFilters"/> function.
 /// </summary>
 /// <param name="filters">filters to set</param>
 internal void SetFilters(string[] filters)
 {
     for (int i = 0; i < _grid.Columns.Count && i < filters.Length; i++)
     {
         IGridFilter gridFilter = (IGridFilter)_columnToGridFilterHash[_grid.Columns[i]];
         if (filters[i].Length > 0)
         {
             gridFilter.SetFilter(filters[i]);
         }
         else
         {
             gridFilter.Clear();
         }
     }
 }
        public void First_Get_Caches()
        {
            filter.Column.Grid.Query = HttpUtility.ParseQueryString("name-contains=a");

            IGridFilter?expected = filter.First;

            filter.Column.Grid.Query = HttpUtility.ParseQueryString("name-equals=b");

            IGridFilter actual = filter.First !;

            Assert.Equal("contains", actual.Method);
            Assert.IsType <StringFilter>(actual);
            Assert.Equal("a", actual.Values);
            Assert.Same(expected, actual);
        }
Esempio n. 28
0
        public void First_Get_Caches()
        {
            filter.Column.Grid.Query = HttpUtility.ParseQueryString("name-contains=a");

            IGridFilter expected = filter.First;

            filter.Column.Grid.Query = HttpUtility.ParseQueryString("name-equals=b");

            IGridFilter actual = filter.First;

            Assert.Equal(typeof(StringContainsFilter), actual.GetType());
            Assert.Equal("contains", actual.Method);
            Assert.Equal("a", actual.Value);
            Assert.Same(expected, actual);
        }
Esempio n. 29
0
        public void Second_Get_Caches()
        {
            filter.Column.Grid.Query = HttpUtility.ParseQueryString("name-contains=a&name-equals=b");

            IGridFilter expected = filter.Second;

            filter.Column.Grid.Query = HttpUtility.ParseQueryString("name-starts-with=d&name-ends-with=e");

            IGridFilter actual = filter.Second;

            Assert.Equal(typeof(StringEqualsFilter), actual.GetType());
            Assert.Equal("equals", actual.Method);
            Assert.Equal("b", actual.Value);
            Assert.Same(expected, actual);
        }
Esempio n. 30
0
        public void Second_Get_Caches()
        {
            filter.Type = GridFilterType.Double;
            filter.Column.Grid.Query = HttpUtility.ParseQueryString("name-contains=a&name-equals=b");

            IGridFilter?expected = filter.Second;

            filter.Column.Grid.Query = HttpUtility.ParseQueryString("name-starts-with=d&name-ends-with=e");

            IGridFilter actual = filter.Second !;

            Assert.IsType <StringEqualsFilter>(actual);
            Assert.Equal("b", actual.Values.Single());
            Assert.Equal("equals", actual.Method);
            Assert.Same(expected, actual);
        }
Esempio n. 31
0
 /// <summary>
 /// Creates a new instance
 /// </summary>
 /// <param name="column">Column the <see cref="IGridFilter"/> is created for.</param>
 /// <param name="columnStyle">Column style the <see cref="IGridFilter"/> is created for.</param>
 /// <param name="gridFilter">Default <see cref="IGridFilter"/> instance.</param>
 public GridFilterEventArgs(DataColumn column, DataGridColumnStyle columnStyle, IGridFilter gridFilter)
 {
     _column = column;
     _columnStyle = columnStyle;
     _gridFilter = gridFilter;
 }
 /// <summary>
 /// Determines whether a given <see cref="IGridFilter"/> is contained in this instance.
 /// </summary>
 /// <param name="gridFilter"><see cref="IGridFilter"/> to be checked.</param>
 /// <returns>True if <see cref="IGridFilter"/> is contained in this instance otherwise False.</returns>
 public bool Contains(IGridFilter gridFilter)
 {
     return base.InnerList.Contains(gridFilter);
 }