public void NonPartialsDontMatchLongerUrls() { var rt = new RouteTemplate("/branch", false); var rd = new RouteDict(); var md = rt.match("/branch/excess"); Assert.IsNull(md); }
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); }
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); }
public void SlashMatchesSlash() { var rt = new RouteTemplate("/", false); var md = rt.match("/"); Assert.IsNotNull(md); Assert.AreEqual("", md.pathRemaining); Assert.AreEqual("/", md.pathMatched); }
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"]); }
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"]); }
public void EmptyOnlyMatchesEmpty() { var rt = new RouteTemplate("", false); var md = rt.match("/branch"); Assert.IsNull(md); }
public Options(string httpMethod, RouteTemplate[] templates, AppFunc app) { this.httpMethod = httpMethod; this.templates = templates; this.app = app; }
public Options(string httpMethod, RouteTemplate template, AppFunc app) : this(httpMethod, new[] { template}, app) { }
/// <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); }
// 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); }
// 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; }
// 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; }