public void IsMatchWithCaseSensitiveReturnsTrueForMissingQuery()
        {
            // Arrange.
            const string Path = "/WebApp/Administration/Test.aspx?Param1=42&Param2=No";
            const string Pattern = "/WebApp/Administration/Test.aspx";

            var matcher = new StartsWithPathMatcher();

            // Act.
            var result = matcher.IsMatch(Path, Pattern, false);

            // Assert.
            Assert.True(result);
        }
        public void IsMatchWithCaseInsensitiveReturnsFalseForNearMatch()
        {
            // Arrange.
            const string Path = "/WebApp/Administration/Test.aspx?Param1=42&Param2=No";
            const string Pattern = "/webapp/administration/test.aspx?param1=43";

            var matcher = new StartsWithPathMatcher();

            // Act.
            var result = matcher.IsMatch(Path, Pattern, true);

            // Assert.
            Assert.False(result);
        }
示例#3
0
        /// <summary>
        /// Creates an appropriate path matcher for the specified match type.
        /// </summary>
        /// <param name="matchType">The PathMatchType used to determine the appropriate path matcher.</param>
        /// <returns></returns>
        public static IPathMatcher Create(PathMatchType matchType)
        {
            // Check for cached matchers first.
            IDictionary <PathMatchType, IPathMatcher> cachedMatchers = CachedMatchers;

            if (cachedMatchers != null && cachedMatchers.ContainsKey(matchType))
            {
                IPathMatcher cachedPathMatcher = cachedMatchers[matchType];
                Logger.LogFormat("Cached {0} retrieved.", cachedPathMatcher.GetType().Name);
                return(cachedPathMatcher);
            }

            // Create the appropriate path matcher.
            IPathMatcher pathMatcher;

            switch (matchType)
            {
            case PathMatchType.Regex:
                pathMatcher = new RegexPathMatcher();
                break;

            case PathMatchType.StartsWith:
                pathMatcher = new StartsWithPathMatcher();
                break;

            case PathMatchType.Exact:
                pathMatcher = new ExactPathMatcher();
                break;

            default:
                throw new ArgumentOutOfRangeException("matchType");
            }

            // Cache the path matcher, if possible.
            if (cachedMatchers != null)
            {
                cachedMatchers.Add(matchType, pathMatcher);
            }

            Logger.LogFormat("Creating {0}.", pathMatcher.GetType().Name);
            return(pathMatcher);
        }
        /// <summary>
        /// Creates an appropriate path matcher for the specified match type.
        /// </summary>
        /// <param name="matchType">The PathMatchType used to determine the appropriate path matcher.</param>
        /// <returns></returns>
        public static IPathMatcher Create(PathMatchType matchType)
        {
            // Check for cached matchers first.
            IDictionary<PathMatchType, IPathMatcher> cachedMatchers = CachedMatchers;
            if (cachedMatchers != null && cachedMatchers.ContainsKey(matchType)) {
                IPathMatcher cachedPathMatcher = cachedMatchers[matchType];
                Logger.LogFormat("Cached {0} retrieved.", cachedPathMatcher.GetType().Name);
                return cachedPathMatcher;
            }

            // Create the appropriate path matcher.
            IPathMatcher pathMatcher;
            switch (matchType) {
                case PathMatchType.Regex:
                    pathMatcher = new RegexPathMatcher();
                    break;

                case PathMatchType.StartsWith:
                    pathMatcher = new StartsWithPathMatcher();
                    break;

                case PathMatchType.Exact:
                    pathMatcher = new ExactPathMatcher();
                    break;

                default:
                    throw new ArgumentOutOfRangeException("matchType");
            }

            // Cache the path matcher, if possible.
            if (cachedMatchers != null) {
                cachedMatchers.Add(matchType, pathMatcher);
            }

            Logger.LogFormat("Creating {0}.", pathMatcher.GetType().Name);
            return pathMatcher;
        }