Пример #1
0
 public void NonPartialsDontMatchLongerUrls()
 {
     var rt = new RouteTemplate("/branch", false);
     var rd = new RouteDict();
     var md = rt.match("/branch/excess");
     Assert.IsNull(md);
 }
Пример #2
0
 public void TrailingSlashesArePreserved()
 {
     var rt = new RouteTemplate("/branch", true);
     var md = rt.match("/branch/");
     Assert.IsNotNull(md);
     Assert.AreEqual("/", md.pathRemaining);
     Assert.AreEqual("/branch", md.pathMatched);
 }
Пример #3
0
 public void PartialMatches()
 {
     var rt = new RouteTemplate("/branch", true);
     var md = rt.match("/branch/value");
     Assert.IsNotNull(md);
     Assert.AreEqual("/value", md.pathRemaining);
     Assert.AreEqual("/branch", md.pathMatched);
 }
Пример #4
0
 public void SlashMatchesSlash()
 {
     var rt = new RouteTemplate("/", false);
     var md = rt.match("/");
     Assert.IsNotNull(md);
     Assert.AreEqual("", md.pathRemaining);
     Assert.AreEqual("/", md.pathMatched);
 }
Пример #5
0
 public void VarsAreExtractedWithTrailingSlash(string template)
 {
     var rt = new RouteTemplate(template, true);
     var md = rt.match("/branch/abcdefg/");
     Assert.IsNotNull(md);
     Assert.AreEqual("/", md.pathRemaining);
     Assert.AreEqual("/branch/abcdefg", md.pathMatched);
     Assert.IsNotNull(md.extracted);
     Assert.AreEqual("abcdefg", md.extracted["value"]);
 }
Пример #6
0
 public void RequiredVarsAreExtracted(string template)
 {
     var rt = new RouteTemplate(template, false);
     var md = rt.match("/branch/abcdefg");
     Assert.IsNotNull(md);
     Assert.AreEqual("", md.pathRemaining);
     Assert.AreEqual("/branch/abcdefg", md.pathMatched);
     Assert.IsNotNull(md.extracted);
     Assert.AreEqual("abcdefg", md.extracted["value"]);
 }
Пример #7
0
 public void EmptyOnlyMatchesEmpty()
 {
     var rt = new RouteTemplate("", false);
     var md = rt.match("/branch");
     Assert.IsNull(md);
 }
Пример #8
0
 public Options(string httpMethod, RouteTemplate[] templates, AppFunc app)
 {
     this.httpMethod = httpMethod;
     this.templates = templates;
     this.app = app;
 }
Пример #9
0
 public Options(string httpMethod, RouteTemplate template, AppFunc app)
     : this(httpMethod, new[] { template}, app)
 {
 }
Пример #10
0
 /// <summary>
 /// Creates a branch in the pipeline. 
 /// </summary>
 /// <remarks>If the inbound request matches "template"
 /// then the middlewares defined by <paramref name="branchBuilder"/> will be called. 
 /// If the template is not matched then the middleware attatched to the return value will
 /// be called. 
 /// 
 /// Any parameters
 /// extracted by the template will be added to RouteParams for use within the branch.
 /// The BasePath and Path variables in the owin Environment will be adjusted and then restored
 /// when the branch is complete
 /// 
 /// If the template is not matched this does nothing and the middleware after this branch will be called
 /// </summary>
 /// <param name="template">A string defining the RouteTemplate to match.</param>
 /// <param name="branchBuilder">An Action which adds middleware to this branch</param>
 /// <param name="iab">The appbuilder being extended (this)</param>
 public static IAppBuilder Branch(this IAppBuilder iab, string template, Action<IAppBuilder> branchBuilder)
 {
     var rt = new RouteTemplate(template, true);
     return Branch(iab, rt, branchBuilder);
 }
Пример #11
0
 // Creates a route which calls methodName on instance callee converting any
 // matching entries in env["routeParams"] to arguments of callee.methodName
 private static IAppBuilder Route(this IAppBuilder app, string httpMethod, object callee, string methodName, RouteTemplate[] templates)
 {
     if (callee == null) {
         var msg = string.Format("Null target for route {0} {1}", httpMethod, templates[0]);
         throw new ArgumentNullException("callee", msg);
     }
     var wrapper = new Wrapper(callee, methodName);
     return Route(app, httpMethod, wrapper.Invoke, templates);
 }
Пример #12
0
 // creates a route which calls an AppFunc
 private static IAppBuilder Route(this IAppBuilder app, string httpMethod, AppFunc runAction, RouteTemplate[] templates)
 {
     var options = new RouteMiddleware.Options(httpMethod, templates, runAction);
     IAppBuilder result = app.Use<RouteMiddleware>(options);
     return result;
 }
Пример #13
0
 // creates a branch in the routing
 private static IAppBuilder Branch(this IAppBuilder app, RouteTemplate template, Action<IAppBuilder> branchAction)
 {
     var options = new RouteMiddleware.Options(null, template, null);
     IAppBuilder result = app.Use<RouteMiddleware>(options);
     IAppBuilder branch = app.New();
     branchAction(branch);
     options.branch = (OwinMiddleware)branch.Build(typeof(OwinMiddleware));
     return result;
 }