public void IsMatchReturnsTrueForNonQueryContainmentMatch()
        {
            // Arrange.
            const string Path1 = "/WebApp/Administration/Test.aspx";
            const string Path2 = "/webapp/admin/manage.aspx";
            const string Path3 = "/WebApp/Admin.aspx";
            const string Path4 = "/WebApp/Reports/TestAdminReport.aspx";
            const string Path5 = "/WebApp/Reports/TestReport.aspx?Admin=true";
            const string Path6 = "/WebApp/Reports/TestReport.aspx?Param1=42&Admin=true";
            const string Pattern = @"(?<!\?|&)Admin";

            var matcher = new RegexPathMatcher();

            // Act.
            var result1 = matcher.IsMatch(Path1, Pattern, true);
            var result2 = matcher.IsMatch(Path2, Pattern, true);
            var result3 = matcher.IsMatch(Path3, Pattern, true);
            var result4 = matcher.IsMatch(Path4, Pattern, true);
            var result5 = matcher.IsMatch(Path5, Pattern, true);
            var result6 = matcher.IsMatch(Path6, Pattern, true);

            // Assert.
            Assert.True(result1);
            Assert.True(result2);
            Assert.True(result3);
            Assert.True(result4);
            Assert.False(result5);
            Assert.False(result6);
        }
        public void IsMatchWithCaseInsensitiveReturnsFalseForNearMatch()
        {
            // Arrange.
            const string Path = "/WebApp/Administration/Test.aspx?Param1=42&Param2=No";
            const string Pattern = @"/webapp/administration/test\.aspx(\?.+&|\?)param2=yes";

            var matcher = new RegexPathMatcher();

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

            // Assert.
            Assert.False(result);
        }
        public void IsMatchReturnsFalseForMissingQuery()
        {
            // Arrange.
            const string Path = "/WebApp/Administration/Test.aspx";
            const string Pattern = @"/WebApp/Administration/Test\.aspx(\?.+&|\?)Param2=No";

            var matcher = new RegexPathMatcher();

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

            // Assert.
            Assert.False(result);
        }
Exemplo n.º 4
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;
        }
        public void IsMatchWithCaseInsensitiveReturnsTrueForEquivalentPartialQueryMatch()
        {
            // Arrange.
            const string Path1 = "/WebApp/Administration/Test.aspx?Param1=42&Param2=No";
            const string Path2 = "/WebApp/Administration/Test.aspx?Param2=No&Param1=42";
            const string Path3 = "/WebApp/Administration/Test.aspx?Param2=No";
            const string Pattern = @"/webapp/administration/test\.aspx(\?.+&|\?)param2=no";

            var matcher = new RegexPathMatcher();

            // Act.
            var result1 = matcher.IsMatch(Path1, Pattern, true);
            var result2 = matcher.IsMatch(Path2, Pattern, true);
            var result3 = matcher.IsMatch(Path3, Pattern, true);

            // Assert.
            Assert.True(result1);
            Assert.True(result2);
            Assert.True(result3);
        }