Beispiel #1
0
        private static bool TestConstraint(IDispatcherValueConstraint constraint, DispatcherValueCollection values, string routeKey)
        {
            var httpContext       = new DefaultHttpContext();
            var constraintPurpose = ConstraintPurpose.IncomingRequest;

            var dispatcherValueConstraintContext = new DispatcherValueConstraintContext(httpContext, values, constraintPurpose)
            {
                Key = routeKey
            };

            return(constraint.Match(dispatcherValueConstraintContext));
        }
        private static bool TestConstraint(IDispatcherValueConstraint constraint, object value, Action <IMatcher> routeConfig = null)
        {
            var httpContext = new DefaultHttpContext();
            var values      = new DispatcherValueCollection()
            {
                { "fake", value }
            };
            var constraintPurpose = ConstraintPurpose.IncomingRequest;

            var dispatcherValueConstraintContext = new DispatcherValueConstraintContext(httpContext, values, constraintPurpose);

            return(constraint.Match(dispatcherValueConstraintContext));
        }
Beispiel #3
0
        /// <inheritdoc />
        public bool Match(DispatcherValueConstraintContext constraintContext)
        {
            if (constraintContext == null)
            {
                throw new ArgumentNullException(nameof(constraintContext));
            }

            if (constraintContext.Values.TryGetValue(constraintContext.Key, out var routeValue) &&
                routeValue != null)
            {
                return(InnerConstraint.Match(constraintContext));
            }

            return(true);
        }
        /// <inheritdoc />
        public bool Match(DispatcherValueConstraintContext constraintContext)
        {
            if (constraintContext == null)
            {
                throw new ArgumentNullException(nameof(constraintContext));
            }

            if (constraintContext.Values.TryGetValue(constraintContext.Key, out var routeValue) &&
                routeValue != null)
            {
                var parameterValueString = Convert.ToString(routeValue, CultureInfo.InvariantCulture);

                return(Constraint.IsMatch(parameterValueString));
            }

            return(false);
        }
Beispiel #5
0
        /// <inheritdoc />
        public bool Match(DispatcherValueConstraintContext constraintContext)
        {
            if (constraintContext == null)
            {
                throw new ArgumentNullException(nameof(constraintContext));
            }

            foreach (var constraint in Constraints)
            {
                if (!constraint.Match(constraintContext))
                {
                    return(false);
                }
            }

            return(true);
        }
        /// <inheritdoc />
        public bool Match(DispatcherValueConstraintContext constraintContext)
        {
            if (constraintContext == null)
            {
                throw new ArgumentNullException(nameof(constraintContext));
            }

            if (constraintContext.Values.TryGetValue(constraintContext.Key, out var value) && value != null)
            {
                if (value is int)
                {
                    return(true);
                }

                var valueString = Convert.ToString(value, CultureInfo.InvariantCulture);
                return(int.TryParse(valueString, NumberStyles.Integer, CultureInfo.InvariantCulture, out var result));
            }

            return(false);
        }
Beispiel #7
0
        private bool MatchConstraints(HttpContext httpContext, DispatcherValueCollection values, IDictionary <string, IDispatcherValueConstraint> constraints)
        {
            if (constraints != null)
            {
                foreach (var kvp in constraints)
                {
                    var constraint        = kvp.Value;
                    var constraintContext = new DispatcherValueConstraintContext(httpContext, values, ConstraintPurpose.IncomingRequest)
                    {
                        Key = kvp.Key
                    };

                    if (!constraint.Match(constraintContext))
                    {
                        values.TryGetValue(kvp.Key, out var value);

                        Logger.RouteValueDoesNotMatchConstraint(value, kvp.Key, kvp.Value);
                        return(false);
                    }
                }
            }

            return(true);
        }