public void MatchUriToTemplate()
        {
            var uri = new Uri("http://example.com/foo/bar");

            var sTemplate = "http://example.com/{p1}/{p2}";

            var x = UriTemplate.CreateMatchingRegex(sTemplate);

            var match = Regex.IsMatch(uri.AbsoluteUri, x);

            Assert.True(match);
        }
        public void GetParameters()
        {
            var uri = new Uri("http://example.com/foo/bar");

            var sTemplate = "http://example.com/{p1}/{p2}";

            var x     = UriTemplate.CreateMatchingRegex(sTemplate);
            var regex = new Regex(x);

            var match = regex.Match(uri.AbsoluteUri);

            Assert.Equal("foo", match.Groups["p1"].Value);
            Assert.Equal("bar", match.Groups["p2"].Value);
        }
示例#3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OpenApiPathTemplate"/> class.
 /// </summary>
 /// <param name="uriTemplate">The uri template.</param>
 /// <param name="item">The path item.</param>
 public OpenApiPathTemplate(string uriTemplate, OpenApiPathItem item)
 {
     this.UriTemplate = new UriTemplate(uriTemplate);
     this.PathItem    = item;
     this.Match       = new Regex(UriTemplate.CreateMatchingRegex(uriTemplate), RegexOptions.Compiled);
 }