protected override Expression VisitMethodCall(MethodCallExpression node)
        {
            if (node.Method.Name == "Select" &&
                expansion.MemberType.GetUnderlyingElementType() == node.GetUnderlyingElementType() &&
                this.expression.ToString().StartsWith(node.ToString()))   //makes sure we're not updating some nested "Select"
            {
                FilterLambdaOperator filterOperator = mapper.Map <FilterLambdaOperator>
                                                      (
                    expansion.FilterOption.Filter,
                    opts => opts.Items[ExpressionOperators.PARAMETERS_KEY] = new Dictionary <string, ParameterExpression>()
                                                      );

                return(node.GetWhereCall(filterOperator.Build()));
            }

            return(base.VisitMethodCall(node));
        }
        public void CanCreateSerachByFirstNameAndLastNameExpression()
        {
            //arrange
            ItemFilterGroupDescriptor itemFilterGroupDescriptor = new ItemFilterGroupDescriptor
            {
                Filters = new List <ItemFilterDescriptorBase>
                {
                    new ItemFilterGroupDescriptor
                    {
                        Filters = new List <ItemFilterDescriptorBase>
                        {
                            new MemberSourceFilterDescriptor
                            {
                                Field        = "CitizenshipStatus",
                                MemberSource = "CitizenshipStatus",
                                Operator     = "eq",
                                Type         = "System.String"
                            },
                            new MemberSourceFilterDescriptor
                            {
                                Field        = "ResidentState",
                                MemberSource = "ResidentState",
                                Operator     = "eq",
                                Type         = "System.String"
                            }
                        },
                        Logic = "and"
                    }
                }
            };

            //act
            FilterLambdaOperatorParameters filterLambdaOperatorDescriptor = serviceProvider.GetRequiredService <IGetItemFilterBuilder>().CreateFilter
                                                                            (
                itemFilterGroupDescriptor,
                typeof(ResidencyModel),
                residency
                                                                            );

            FilterLambdaOperator filterLambdaOperator        = (FilterLambdaOperator)serviceProvider.GetRequiredService <IMapper>().MapToOperator(filterLambdaOperatorDescriptor);
            Expression <Func <ResidencyModel, bool> > filter = (Expression <Func <ResidencyModel, bool> >)filterLambdaOperator.Build();

            //assert
            AssertFilterStringIsCorrect
            (
                filter,
                "f => ((f.CitizenshipStatus == \"US\") AndAlso (f.ResidentState == \"OH\"))"
            );
        }
        public void CanCreateFilterFromSearchFilterGroupDescriptor()
        {
            //act
            FilterLambdaOperatorDescriptor filterLambdaOperatorDescriptor = serviceProvider.GetRequiredService <ISearchSelectorBuilder>().CreateFilter
                                                                            (
                searchFilterGroupDescriptor,
                typeof(PersonalModel),
                "xxx"
                                                                            );
            FilterLambdaOperator filterLambdaOperator       = (FilterLambdaOperator)serviceProvider.GetRequiredService <IMapper>().MapToOperator(filterLambdaOperatorDescriptor);
            Expression <Func <PersonalModel, bool> > filter = (Expression <Func <PersonalModel, bool> >)filterLambdaOperator.Build();

            //assert
            AssertFilterStringIsCorrect
            (
                filter,
                "f => (f.MiddleName.Contains(\"xxx\") OrElse (f.FirstName.Contains(\"xxx\") OrElse f.LastName.Contains(\"xxx\")))"
            );
        }
        public void CanCreateSerachByIdExpression()
        {
            //arrange
            ItemFilterGroupDescriptor itemFilterGroupDescriptor = new ItemFilterGroupDescriptor
            {
                Filters = new List <ItemFilterDescriptorBase>
                {
                    new MemberSourceFilterDescriptor
                    {
                        Field        = "UserId",
                        MemberSource = "UserId",
                        Operator     = "eq",
                        Type         = "System.Int32"
                    }
                }
            };

            //act
            FilterLambdaOperatorParameters filterLambdaOperatorDescriptor = serviceProvider.GetRequiredService <IGetItemFilterBuilder>().CreateFilter
                                                                            (
                itemFilterGroupDescriptor,
                typeof(ResidencyModel),
                residency
                                                                            );

            FilterLambdaOperator filterLambdaOperator        = (FilterLambdaOperator)serviceProvider.GetRequiredService <IMapper>().MapToOperator(filterLambdaOperatorDescriptor);
            Expression <Func <ResidencyModel, bool> > filter = (Expression <Func <ResidencyModel, bool> >)filterLambdaOperator.Build();

            //assert
            AssertFilterStringIsCorrect
            (
                filter,
                "f => (f.UserId == 3)"
            );
        }
        public void CanCreateSerachByFirstNameAndLastNameExpression()
        {
            //arrange
            ItemFilterGroupDescriptor itemFilterGroupDescriptor = new ItemFilterGroupDescriptor
            {
                Filters = new List <ItemFilterDescriptorBase>
                {
                    new ItemFilterGroupDescriptor
                    {
                        Filters = new List <ItemFilterDescriptorBase>
                        {
                            new MemberSourceFilterDescriptor
                            {
                                Field        = "FirstName",
                                MemberSource = "FirstName",
                                Operator     = "eq",
                                Type         = "System.String"
                            },
                            new MemberSourceFilterDescriptor
                            {
                                Field        = "LastName",
                                MemberSource = "LastName",
                                Operator     = "eq",
                                Type         = "System.String"
                            }
                        },
                        Logic = "and"
                    }
                }
            };

            //act
            FilterLambdaOperatorParameters filterLambdaOperatorDescriptor = serviceProvider.GetRequiredService <IGetItemFilterBuilder>().CreateFilter
                                                                            (
                itemFilterGroupDescriptor,
                typeof(InstructorModel),
                inststructor
                                                                            );

            FilterLambdaOperator filterLambdaOperator         = (FilterLambdaOperator)serviceProvider.GetRequiredService <IMapper>().MapToOperator(filterLambdaOperatorDescriptor);
            Expression <Func <InstructorModel, bool> > filter = (Expression <Func <InstructorModel, bool> >)filterLambdaOperator.Build();

            //assert
            AssertFilterStringIsCorrect
            (
                filter,
                "f => ((f.FirstName == \"John\") AndAlso (f.LastName == \"Smith\"))"
            );
        }