Beispiel #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TermsCriteria"/> class.
 /// </summary>
 /// <param name="executionMode">Type of execution mode this terms criteria will take.</param>
 /// <param name="field">Field to be checked for this term.</param>
 /// <param name="member">Property or field being checked for this term.</param>
 /// <param name="values">Constant values being searched for.</param>
 private TermsCriteria(TermsExecutionMode? executionMode, string field, MemberInfo member, IEnumerable<object> values)
     : base(field)
 {
     this.executionMode = executionMode;
     this.member = member;
     this.values = new ReadOnlyCollection<object>(values.ToArray());
 }
Beispiel #2
0
 private TermsCriteria(TermsExecutionMode? executionMode, string field, MemberInfo member, HashSet<object> values)
 {
     this.executionMode = executionMode;
     this.field = field;
     this.member = member;
     this.values = values;
 }
        public void CombineWithAllTermFieldsSame_OrIncompatibleExecutionMode_ReturnsOrCriteria(TermsExecutionMode executionMode)
        {
            var salutationMs = TermsCriteria.Build(executionMode, "salutation", memberInfo, "Miss", "Ms");
            var criteria = OrCriteria.Combine(salutationMr, salutationMrs, salutationMs);

            var orCriteria = Assert.IsType<OrCriteria>(criteria);
            Assert.Contains(salutationMr, orCriteria.Criteria);
            Assert.Contains(salutationMrs, orCriteria.Criteria);
            Assert.Contains(salutationMs, orCriteria.Criteria);
            Assert.Equal(3, orCriteria.Criteria.Count);
        }
        public void CombineWithAllTermFieldsSame_OrCompatibleExecutionMode_CombinesIntoSingleTerm(TermsExecutionMode? executionMode)
        {
            var salutationMs = TermsCriteria.Build(executionMode, "salutation", memberInfo, "Miss", "Ms");
            var criteria = OrCriteria.Combine(salutationMr, salutationMrs, salutationMs);

            var termsCriteria = Assert.IsType<TermsCriteria>(criteria);
            Assert.Equal(salutationMr.Field, termsCriteria.Field);
            Assert.Same(memberInfo, termsCriteria.Member);

            var allValues = salutationMr.Values.Concat(salutationMrs.Values).Concat(salutationMs.Values).Distinct().ToArray();
            foreach (var value in allValues)
                Assert.Contains(value, termsCriteria.Values);

            Assert.Equal(allValues.Length, termsCriteria.Values.Count);
        }
        private Expression VisitContains(string methodName, Expression left, Expression right, TermsExecutionMode executionMode)
        {
            var cm = ConstantMemberPair.Create(left, right);

            if (cm != null)
            {
                var values = ((IEnumerable)cm.ConstantExpression.Value).Cast <object>().ToArray();
                return(new CriteriaExpression(TermsCriteria.Build(executionMode, mapping.GetFieldName(prefix, cm.MemberExpression.Member), cm.MemberExpression.Member, values)));
            }

            throw new NotSupportedException(methodName + " must be between a Member and a Constant");
        }
Beispiel #6
0
        public void CombineWithAllTermFieldsSame_OrIncompatibleExecutionMode_ReturnsOrCriteria(TermsExecutionMode executionMode)
        {
            var salutationMs = TermsCriteria.Build(executionMode, "salutation", memberInfo, "Miss", "Ms");
            var criteria     = OrCriteria.Combine(salutationMr, salutationMrs, salutationMs);

            var orCriteria = Assert.IsType <OrCriteria>(criteria);

            Assert.Contains(salutationMr, orCriteria.Criteria);
            Assert.Contains(salutationMrs, orCriteria.Criteria);
            Assert.Contains(salutationMs, orCriteria.Criteria);
            Assert.Equal(3, orCriteria.Criteria.Count);
        }
Beispiel #7
0
        /// <summary>
        /// Builds a <see cref="TermCriteria"/> or <see cref="TermsCriteria"/>, depending on how many values are
        /// present in the <paramref name="values"/> collection.
        /// </summary>
        /// <param name="executionMode">The terms execution mode (optional). Only used when a <see cref="TermsCriteria"/> is returned.</param>
        /// <param name="field">The field that's being searched.</param>
        /// <param name="member">The member information for the field.</param>
        /// <param name="values">The values to be matched.</param>
        /// <returns>Either a <see cref="TermCriteria"/> object or a <see cref="TermsCriteria"/> object.</returns>
        internal static ITermsCriteria Build(TermsExecutionMode? executionMode, string field, MemberInfo member, IEnumerable<object> values)
        {
            Argument.EnsureNotNull("values", values);

            var hashValues = new HashSet<object>(values);
            if (hashValues.Count == 1)
                return new TermCriteria(field, member, hashValues.First());

            return new TermsCriteria(executionMode, field, member, hashValues);
        }
Beispiel #8
0
 /// <summary>
 /// Builds a <see cref="TermCriteria"/> or <see cref="TermsCriteria"/>, depending on how many values are
 /// present in the <paramref name="values"/> collection.
 /// </summary>
 /// <param name="executionMode">The terms execution mode (optional). Only used when a <see cref="TermsCriteria"/> is returned.</param>
 /// <param name="field">The field that's being searched.</param>
 /// <param name="member">The member information for the field.</param>
 /// <param name="values">The values to be matched.</param>
 /// <returns>Either a <see cref="TermCriteria"/> object or a <see cref="TermsCriteria"/> object.</returns>
 internal static ITermsCriteria Build(TermsExecutionMode? executionMode, string field, MemberInfo member, params object[] values)
 {
     return Build(executionMode, field, member, values.AsEnumerable());
 }
        Expression VisitContains(string methodName, Expression left, Expression right, TermsExecutionMode executionMode)
        {
            var cm = ConstantMemberPair.Create(left, right);

            if (cm != null && Mapping.TryGetFieldName(SourceType, cm.Expression, out string fieldName))
            {
                var values = ((IEnumerable)cm.ConstantExpression.Value).Cast <object>().ToArray();

                return(new CriteriaExpression(TermsCriteria.Build(executionMode, fieldName, cm.GetMemberFromExpression(), values)));
            }

            throw new NotSupportedException(methodName + " must be between a Member and a Constant");
        }