public void BuildCapturePattern_Doesnt_Allow_Expressions()
        {
            // binding expressions are not allowed in a capture pattern.
            // Captures just get top-level names.
            string pattern = @"{p1.p2}";
            var    tokens  = BindingTemplateParser.GetTokens(pattern).ToList();

            ExceptionAssert.ThrowsInvalidOperation(() => BindingTemplateToken.BuildCapturePattern(tokens),
                                                   "Capture expressions can't include dot operators");
        }
        public void BuildCapturePattern_IfValidTemplate_ReturnsValidRegexp()
        {
            string pattern = @"{p1}-p2/{{2014}}/{d3}/folder/{name}.{ext}";
            var    tokens  = BindingTemplateParser.GetTokens(pattern).ToList();

            string captureRegex = BindingTemplateToken.BuildCapturePattern(tokens);

            Assert.NotEmpty(captureRegex);
            Assert.Equal("^(?<p1>.*)-p2/\\{2014}/(?<d3>.*)/folder/(?<name>.*)\\.(?<ext>.*)$", captureRegex);
            Assert.NotNull(new Regex(captureRegex, RegexOptions.Compiled));
        }
예제 #3
0
        private static string GetValue(BindingTemplateToken token)
        {
            var value = token.AsLiteral ?? token.ParameterName;

            return(value);
        }