public Build ( |
||
returnType |
/// The Type argument indicates which calling convention should be returned, and
/// is typically typeof( |
|
return | object |
private void Call(Action<IAppBuilder> pipe, Request request) { var builder = new AppBuilder(); pipe(builder); var app = (AppFunc)builder.Build(typeof(AppFunc)); app(request.Environment).Wait(); }
public static void AddOwinRoute(this RouteCollection routes, string path, Action<IAppBuilder> configuration) { var builder = new AppBuilder(); configuration(builder); var app = (AppDelegate)builder.Build(typeof(AppDelegate)); routes.Add(new OwinRoute(path, app)); }
private ResultParameters Call(Action<IAppBuilder> pipe, string path) { var builder = new AppBuilder(); pipe(builder); var app = builder.Build<AppDelegate>(); return app(new Request() { Path = path }.Call).Result; }
private ResultParameters Call(Action<IAppBuilder> pipe) { var builder = new AppBuilder(); pipe(builder); var app = (AppDelegate)builder.Build(typeof(AppDelegate)); return app(new Request().Call).Result; }
public void NoMatch_PassesThrough(string baseUrl, string baseDir, string requestUrl) { IAppBuilder builder = new AppBuilder(); builder.UseStaticFiles(baseUrl, baseDir); var app = (AppFunc)builder.Build(typeof(AppFunc)); IDictionary<string, object> env = CreateEmptyRequest(requestUrl); app(env).Wait(); Assert.Equal(404, env["owin.ResponseStatusCode"]); }
private IDictionary<string, string[]> Call(Action<IAppBuilder> pipe) { var builder = new AppBuilder(); pipe(builder); var app = (AppFunc)builder.Build(typeof(AppFunc)); var env = Request.Create().Environment; var resp = new Response(env); resp.OutputStream = new MemoryStream(); app(env).Wait(); return resp.Headers; }
public void PathMatchFunc_BranchTaken(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, environment["owin.RequestPathBase"]); Assert.Equal(requestPath.Substring(matchPath.Length), environment["owin.RequestPath"]); }
public void FoundDirectoryWithDefaultFile_PathModified(string baseUrl, string baseDir, string requestUrl) { IAppBuilder builder = new AppBuilder(); builder.UseDefaultFiles(baseUrl, baseDir); var app = (AppFunc)builder.Build(typeof(AppFunc)); IDictionary<string, object> env = CreateEmptyRequest(requestUrl); app(env).Wait(); Assert.Equal(404, env["owin.ResponseStatusCode"]); // Passed through Assert.Equal(requestUrl + "default.html", env["owin.RequestPath"]); // Should be modified }
public void PostDirectory_PassesThrough(string baseUrl, string baseDir, string requestUrl) { IAppBuilder builder = new AppBuilder(); builder.UseDirectoryBrowser(baseUrl, baseDir); var app = (AppFunc)builder.Build(typeof(AppFunc)); IDictionary<string, object> env = CreateEmptyRequest(requestUrl); env["owin.RequestMethod"] = "POST"; app(env).Wait(); Assert.Equal(404, env["owin.ResponseStatusCode"]); }
private string Call(Action<IAppBuilder> pipe, Request request) { var builder = new AppBuilder(); pipe(builder); var app = (AppFunc)builder.Build(typeof(AppFunc)); var env = request.Environment; var resp = new Response(env); MemoryStream buffer = new MemoryStream(); resp.OutputStream = buffer; app(env).Wait(); return Encoding.UTF8.GetString(buffer.GetBuffer(), 0, (int)buffer.Length); }
public static AppDelegate DefaultFactory() { var loader = new DefaultLoader(); var builder = new AppBuilder(); var startupName = ConfigurationManager.AppSettings["owin:Startup"]; var startupMethod = loader.Load(startupName); if (startupMethod != null) { startupMethod.Invoke(builder); } return (AppDelegate)builder.Build(typeof(AppDelegate)); }
public OwinHttpClient(Action<IAppBuilder> build) { var app = new AppBuilder(); _shutdownTokenSource = new CancellationTokenSource(); // Some default properties (this is the instance name so make it unique per instance) app.Properties["server.Capabilities"] = new Dictionary<string, object>(); app.Properties["host.AppName"] = "OwinHttpClient(" + GetHashCode() + ")"; app.Properties["host.OnAppDisposing"] = _shutdownTokenSource.Token; build(app); _appFunc = (AppFunc)app.Build(typeof(AppFunc)); }
public void FoundFile_Served(string baseUrl, string baseDir, string requestUrl) { IAppBuilder builder = new AppBuilder(); builder.UseStaticFiles(baseUrl, baseDir); var app = (AppFunc)builder.Build(typeof(AppFunc)); IDictionary<string, object> env = CreateEmptyRequest(requestUrl); app(env).Wait(); var responseHeaders = (IDictionary<string, string[]>)env["owin.ResponseHeaders"]; Assert.Equal("text/xml", responseHeaders["Content-Type"][0]); Assert.True(responseHeaders["Content-Length"][0].Length > 0); Assert.Equal(responseHeaders["Content-Length"][0], ((Stream)env["owin.ResponseBody"]).Length.ToString()); }
public async Task ScriptFileCanBeExecutedByName() { var factory = new RoslynAppLoaderFactory(); Func<string, Action<IAppBuilder>> loader = factory.Create(_ => null); Action<IAppBuilder> startup = loader.Invoke("Simple.csx"); var builder = new AppBuilder(); startup.Invoke(builder); var app = (AppFunc)builder.Build(typeof(AppFunc)); OwinRequest req = OwinRequest.Create(); await app.Invoke(req.Dictionary); var res = new OwinResponse(req); res.StatusCode.ShouldBe(24601); }
private int Call(Action<IAppBuilder> pipe, string path) { var builder = new AppBuilder(); pipe(builder); var app = builder.Build<AppFunc>(); Request request = Request.Create(); request.Path = path; request.Method = "GET"; Response response = new Response(request.Environment); response.OutputStream = new MemoryStream(); app(request.Environment).Wait(); return response.StatusCode; }
public void NearMatch_RedirectAddSlash(string baseUrl, string baseDir, string requestUrl) { IAppBuilder builder = new AppBuilder(); builder.UseDirectoryBrowser(baseUrl, baseDir); var app = (AppFunc)builder.Build(typeof(AppFunc)); IDictionary<string, object> env = CreateEmptyRequest(requestUrl); app(env).Wait(); Assert.Equal(301, env["owin.ResponseStatusCode"]); var responseHeaders = (IDictionary<string, string[]>)env["owin.ResponseHeaders"]; Assert.Equal(requestUrl + "/", responseHeaders["Location"][0]); Assert.Equal(0, ((Stream)env["owin.ResponseBody"]).Length); }
static void Main(string[] args) { var app = new AppBuilder(); app.Properties["host.Addresses"] = HostAddresses; ServerFactory.Initialize(app); Startup.Configuration(app); var server = ServerFactory.Create(app.Build(), app.Properties); System.Console.WriteLine("Running on http://localhost:8080/"); System.Console.WriteLine("Press enter to exit"); System.Console.ReadLine(); server.Dispose(); }
static void Main(string[] args) { var server = new ServerFactory(new ConsoleTrace()); var builder = new AppBuilder(); builder .UseFunc(ShowFormValues) .UseFunc(UrlRewrite("/", "/index.html")) .UseStatic() .Run(new Program()); var app = builder.Build<AppFunc>(); using (server.Create(app, 8080)) { Console.WriteLine("Running server on http://localhost:8080/"); Console.WriteLine("Press enter to exit"); Console.ReadLine(); } }
static void Main(string[] args) { var startup = new Startup(); // this program's Startup.cs class var app = new AppBuilder(); // the app builder, from Owin.Builder package // the server adapter, from Microsoft.HttpListener.Owin package, gets first chance ServerFactory.Initialize(app.Properties); // this method adds all middleware and frameworks startup.Configuration(app); // ext method to set server address in app.Properties app.SetHostAddress("http", "+", 8080); // build pipeline, and give to server adapter from Microsoft.HttpListener.Owin package using (ServerFactory.Create(app.Build(), app.Properties)) { Console.WriteLine("Running on http://+:8080/"); Console.WriteLine("Press enter to exit"); Console.ReadLine(); } }
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"]); }
AppDelegate Build(Action<IAppBuilder> b) { var builder = new AppBuilder(); b(builder); return (AppDelegate)builder.Build(typeof(AppDelegate)); }
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"]); }
AppFunc Build(Action<IAppBuilder> b) { var builder = new AppBuilder(); b(builder); return (AppFunc)builder.Build(typeof(AppFunc)); }
public void Method_that_returns_app_action_may_also_be_called() { var loader = new DefaultLoader(); var configuration = loader.Load("Owin.Loader.Tests.DefaultConfigurationLoaderTests.Alpha"); var builder = new AppBuilder(); configuration(builder); var app = builder.Build<AppFunc>(); _alphaCalls = 0; app(new Dictionary<string, object>()); Assert.Equal(1, _alphaCalls); }
/// <summary> /// Create an HttpClient that can be used to test an app. /// </summary> /// <param name="configuration">Delegate called to build the app being tested</param> /// <returns></returns> public static TestHttpClient ForConfiguration(Action<IAppBuilder> configuration) { var builder = new AppBuilder(); configuration(builder); return ForAppDelegate((AppDelegate)builder.Build(typeof(AppDelegate))); }
public void NoKnownAcceptContentType_406NotAcceptable(string[] acceptHeader) { IAppBuilder builder = new AppBuilder(); builder.UseDirectoryBrowser(string.Empty, string.Empty); var app = (AppFunc)builder.Build(typeof(AppFunc)); IDictionary<string, object> env = CreateEmptyRequest("/"); SetAcceptHeader(env, acceptHeader); app(env).Wait(); Assert.Equal(406, env["owin.ResponseStatusCode"]); }
// TODO: text/*, q rankings, etc. public void KnownAcceptContentType_Served(string[] acceptHeader, string expectedContentType) { IAppBuilder builder = new AppBuilder(); builder.UseDirectoryBrowser(string.Empty, string.Empty); var app = (AppFunc)builder.Build(typeof(AppFunc)); IDictionary<string, object> env = CreateEmptyRequest("/"); SetAcceptHeader(env, acceptHeader); app(env).Wait(); Assert.False(env.ContainsKey("owin.ResponseStatusCode")); var responseHeaders = (IDictionary<string, string[]>)env["owin.ResponseHeaders"]; Assert.Equal(expectedContentType, responseHeaders["Content-Type"][0]); Assert.True(responseHeaders["Content-Length"][0].Length > 0); Assert.Equal(responseHeaders["Content-Length"][0], ((Stream)env["owin.ResponseBody"]).Length.ToString()); }
private IDictionary<string, string[]> CallPipe(Action<IAppBuilder> pipe) { var builder = new AppBuilder(); pipe(builder); var app = (AppFunc)builder.Build(typeof(AppFunc)); Request request = Request.Create(); request.Method = "GET"; Response response = new Response(request.Environment); response.OutputStream = new MemoryStream(); app(request.Environment).Wait(); return response.Headers; }
public void HeadDirectory_HeadersButNotBodyServed(string baseUrl, string baseDir, string requestUrl) { IAppBuilder builder = new AppBuilder(); builder.UseDirectoryBrowser(baseUrl, baseDir); var app = (AppFunc)builder.Build(typeof(AppFunc)); IDictionary<string, object> env = CreateEmptyRequest(requestUrl); env["owin.RequestMethod"] = "HEAD"; app(env).Wait(); Assert.False(env.ContainsKey("owin.ResponseStatusCode")); var responseHeaders = (IDictionary<string, string[]>)env["owin.ResponseHeaders"]; Assert.Equal("text/html", responseHeaders["Content-Type"][0]); Assert.True(responseHeaders["Content-Length"][0].Length > 0); Assert.Equal(0, ((Stream)env["owin.ResponseBody"]).Length); }
private Response Call(Action<IAppBuilder> pipe) { var builder = new AppBuilder(); pipe(builder); var app = (AppFunc)builder.Build(typeof(AppFunc)); Request request = Request.Create(); request.Method = "GET"; Response response = new Response(request.Environment); MemoryStream buffer = new MemoryStream(); response.OutputStream = buffer; app(request.Environment).Wait(); response.OutputStream = buffer; // Replace the buffer so it can be read. return response; }