public void NullArguments_ArgumentNullException() { var builder = new AppBuilder(); Assert.Throws<ArgumentNullException>(() => builder.MapPath(null, FuncNotImplemented)); Assert.Throws<ArgumentNullException>(() => builder.MapPath("/foo", (AppFunc)null)); Assert.Throws<ArgumentNullException>(() => builder.MapPath(null, ActionNotImplemented)); Assert.Throws<ArgumentNullException>(() => builder.MapPath("/foo", (Action<IAppBuilder>)null)); Assert.Throws<ArgumentNullException>(() => new MapPathMiddleware(null, FuncNotImplemented, "/foo")); Assert.Throws<ArgumentNullException>(() => new MapPathMiddleware(FuncNotImplemented, null, "/foo")); Assert.Throws<ArgumentNullException>(() => new MapPathMiddleware(FuncNotImplemented, FuncNotImplemented, null)); }
public void PathMatchAction_BranchTaken(string matchPath, string basePath, string requestPath) { IDictionary<string, object> environment = CreateEmptyRequest(basePath, requestPath); IAppBuilder builder = new AppBuilder(); builder.MapPath(matchPath, subBuilder => subBuilder.Run(Success)); var app = builder.Build<AppFunc>(); app(environment); Assert.Equal(200, environment["owin.ResponseStatusCode"]); Assert.Equal(basePath + matchPath, environment["owin.RequestPathBase"]); Assert.Equal(requestPath.Substring(matchPath.Length), environment["owin.RequestPath"]); }
public void PathMismatchAction_PassedThrough(string matchPath, string basePath, string requestPath) { IDictionary<string, object> environment = CreateEmptyRequest(basePath, requestPath); IAppBuilder builder = new AppBuilder(); builder.MapPath(matchPath, subBuilder => subBuilder.Run(FuncNotImplemented)); builder.Run(Success); var app = builder.Build<AppFunc>(); app(environment); Assert.Equal(200, environment["owin.ResponseStatusCode"]); Assert.Equal(basePath, environment["owin.RequestPathBase"]); Assert.Equal(requestPath, environment["owin.RequestPath"]); }
public void ChainedRoutes_Success() { IAppBuilder builder = new AppBuilder(); builder.MapPath("/route1", subBuilder => { subBuilder.MapPath("/subroute1", Success); subBuilder.Run(FuncNotImplemented); }); builder.MapPath("/route2/subroute2", Success); var app = builder.Build<AppFunc>(); IDictionary<string, object> environment = CreateEmptyRequest(string.Empty, "/route1"); Assert.Throws<NotImplementedException>(() => app(environment)); environment = CreateEmptyRequest(string.Empty, "/route1/subroute1"); app(environment); Assert.Equal(200, environment["owin.ResponseStatusCode"]); Assert.Equal("/route1/subroute1", environment["owin.RequestPathBase"]); Assert.Equal(string.Empty, environment["owin.RequestPath"]); environment = CreateEmptyRequest(string.Empty, "/route2"); app(environment); Assert.Equal(404, environment["owin.ResponseStatusCode"]); Assert.Equal(string.Empty, environment["owin.RequestPathBase"]); Assert.Equal("/route2", environment["owin.RequestPath"]); environment = CreateEmptyRequest(string.Empty, "/route2/subroute2"); app(environment); Assert.Equal(200, environment["owin.ResponseStatusCode"]); Assert.Equal("/route2/subroute2", environment["owin.RequestPathBase"]); Assert.Equal(string.Empty, environment["owin.RequestPath"]); environment = CreateEmptyRequest(string.Empty, "/route2/subroute2/subsub2"); app(environment); Assert.Equal(200, environment["owin.ResponseStatusCode"]); Assert.Equal("/route2/subroute2", environment["owin.RequestPathBase"]); Assert.Equal("/subsub2", environment["owin.RequestPath"]); }
public void MatchPathHasTrailingSlash_Trimmed(string matchPath, string basePath, string requestPath) { IDictionary<string, object> environment = CreateEmptyRequest(basePath, requestPath); IAppBuilder builder = new AppBuilder(); builder.MapPath(matchPath, Success); var app = builder.Build<AppFunc>(); app(environment); Assert.Equal(200, environment["owin.ResponseStatusCode"]); Assert.Equal(basePath + matchPath.Substring(0, matchPath.Length - 1), environment["owin.RequestPathBase"]); Assert.Equal(requestPath.Substring(matchPath.Length - 1), environment["owin.RequestPath"]); }