Ejemplo n.º 1
0
        public void GenerateFilterIlTest()
        {
            // Arrange
            ExpressFormsFilterText      target     = new ExpressFormsFilterText();
            DynamicMethod               method     = new DynamicMethod("Wow", typeof(bool), new Type[] { typeof(TestClass2) });
            ILGenerator                 generator  = method.GetILGenerator();
            PropertyInfo                property   = typeof(TestClass2).GetProperty("Text");
            Dictionary <string, string> thisFilter = new Dictionary <string, string>()
            {
                { "filterMode", Convert.ToString(TestContext.DataRow["FilterMode"]) }, { "filterText", Convert.ToString(TestContext.DataRow["FilterText"]) }
            };
            TestClass2 argument = new TestClass2()
            {
                Text = Convert.ToString(TestContext.DataRow["ValueToMatch"])
            };

            // Act
            target.GenerateFilterIl(generator, thisFilter, property);
            // The method would eventually return true if it didn't encounter a reason to return false.
            generator.EmitReturnTrue();
            object objResult = method.Invoke(null, new[] { argument });
            bool   result    = (bool)objResult;

            // Assert
            bool expected = Convert.ToBoolean(TestContext.DataRow["Result"]);

            Assert.AreEqual(expected, result);
        }
        } // end GetIndexFilters

        private ExpressFormsFilter GetIndexFilter(PropertyInfo property)
        {
            ExpressFormsFilter filter;

            string inputName = property.Name;

            //filter = GetCustomEditorFilter(filterName, value, isVisible);

            // TODO: Implement function to allow for custom editor filters.

            // Note that this refers only to primitive types such as Nullable<int>
            // Other types, such as string, will not match this nullable test.
            bool   isNullable         = property.PropertyType.Name == "Nullable`1";
            string myPropertyTypeName = isNullable ?
                                        property.PropertyType.GetGenericArguments().First().Name :
                                        property.PropertyType.Name;

            filter = null;
            if (filter == null) // we didn't get an input from GetCustomEditorInput
            {
                switch (myPropertyTypeName)
                {
                case "Boolean":
                    filter = new ExpressFormsFilterBool()
                    {
                        FilterName = property.Name,
                        IsNullable = isNullable
                    };
                    break;

                case "Byte":
                case "Int16":
                case "Int32":
                case "Int64":
                case "Single":
                case "Double":
                case "Decimal":
                    filter = new ExpressFormsFilterNumber()
                    {
                        FilterName = property.Name,
                        IsNullable = isNullable
                    };

                    break;

                case "DateTime":
                    filter = new ExpressFormsFilterDate()
                    {
                        FilterName = property.Name,
                        //IsNullable = isNullable
                    };
                    break;

                case "String":
                    filter = new ExpressFormsFilterText()
                    {
                        FilterName = property.Name
                    };
                    break;

                default:
                    filter = new ExpressFormsPassThruFilter()
                    {
                        FilterName = property.Name,
                    };
                    break;
                }
            }

            // If this property has an associated "CustomPropertyName", use that for the display name.  Otherwise, use the inputName.
            filter.FilterDisplayName = CustomPropertyNames.Keys.Contains(filter.FilterName) ? CustomPropertyNames[filter.FilterName] : filter.FilterName;

            filter.UseAutocomplete = DefaultIndexFilterAutocompleteMode == ExpressFormsIndexViewModel.DefaultIndexFilterAutocompleteModeEnum.On;

            return(filter);
        }