public void MatchingUrls() { ViewUrl url1 = new ViewUrl(@"^product/(?<category>\w+)/(\d+)/$", View1, "url1"); ViewUrl url2 = new ViewUrl(@"^product/(?<category>(?:[\w\s]+))/(\d+)/$", View1, "url2"); ViewUrl url3 = new ViewUrl(@"^product/(?<category>\w+)/\((\d+)\)/$", View1, "url2"); Assert.True(url1.IsMatch("product/new/945/")); Assert.False(url1.IsMatch("product/categrory 1/15/")); Assert.False(url1.IsMatch("product/categrory%201/15/")); Assert.True(url2.IsMatch("product/new and old/125/")); Assert.True(url2.IsMatch("product/new%20and old/125/")); Assert.True(url2.IsMatch("product/new%20and+old/125/")); Assert.False(url2.IsMatch("product/new% 20and old/125/")); Assert.True(url3.IsMatch("product/old/(47)/")); Assert.False(url3.IsMatch("product/1/")); }
public void ReversingUrls() { ViewUrl url1 = new ViewUrl(@"^product/(?<category>\w+)/(\d+)/$", View1, "url1"); ViewUrl url2 = new ViewUrl(@"^product/(?<category>(?:[\w\s]+))/\((\d+)\)/(\w+)/$", View1, "url2"); ViewUrl url3 = new ViewUrl(@"^product/(?<category>\w+)/\d+/$", View1, "url3"); string revUrl1 = url1.Reverse("category=green", "1=7"); string revUrl2 = url2.Reverse("category=green and yellow", "1=7", "2=page"); Assert.Equal("/product/green/7/", revUrl1); Assert.Equal("/product/green%20and%20yellow/(7)/page/", revUrl2); Assert.Throws(typeof(Exception), () => { // positional argument 1 = "page" is not permitted because it must be numeric url2.Reverse("category=green", "1=page", "2=7"); }); Assert.Throws(typeof(Exception), () => { // url3 is not reversible because \d+ at the end was not enclosed in a group and can not be resolved url3.Reverse("category=green", "1=7"); }); }
public TemplateEngine GetTemplateEngine(ViewUrl viewUrl, string templatePathOverride = null) { if (viewUrl == null) return null; return GetTemplateEngine(templatePathOverride ?? viewUrl.TemplatePath); }