Build() public method

The Build is called at the point when all of the middleware should be chained together. This is typically done by the hosting component which created the app builder, and does not need to be called by the startup method if the IAppBuilder is passed in.
public Build ( Type returnType ) : object
returnType System.Type /// The Type argument indicates which calling convention should be returned, and /// is typically typeof() for the OWIN /// calling convention. ///
return object
コード例 #1
0
 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();
 }
コード例 #2
0
 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));
 }
コード例 #3
0
ファイル: StaticTests.cs プロジェクト: dragan/gate
 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;
 }
コード例 #4
0
ファイル: ContentTypeTests.cs プロジェクト: dragan/gate
 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;
 }
コード例 #5
0
        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"]);
        }
コード例 #6
0
 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;
 }
コード例 #7
0
        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"]);
        }
コード例 #8
0
        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
        }
コード例 #9
0
        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"]);
        }
コード例 #10
0
ファイル: TraceTests.cs プロジェクト: owin/museum-piece-gate
 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);
 }
コード例 #11
0
ファイル: AppSingleton.cs プロジェクト: dragan/gate
        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));
        }
コード例 #12
0
        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));
        }
コード例 #13
0
        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());
        }
コード例 #14
0
        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);
        }
コード例 #15
0
ファイル: StaticTests.cs プロジェクト: owin/museum-piece-gate
        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;
        }
コード例 #16
0
        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);
        }
コード例 #17
0
ファイル: Program.cs プロジェクト: nonintanon/SignalR
        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();
        }
コード例 #18
0
ファイル: Program.cs プロジェクト: virajs/firefly
        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();
            }
        }
コード例 #19
0
ファイル: Program.cs プロジェクト: loudej/owin-samples
        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();
            }
        }
コード例 #20
0
        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"]);
        }
コード例 #21
0
ファイル: ShowExceptionsTests.cs プロジェクト: dragan/gate
 AppDelegate Build(Action<IAppBuilder> b)
 {
     var builder = new AppBuilder();
     b(builder);
     return (AppDelegate)builder.Build(typeof(AppDelegate));
 }
コード例 #22
0
        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"]);
        }
コード例 #23
0
 AppFunc Build(Action<IAppBuilder> b)
 {
     var builder = new AppBuilder();
     b(builder);
     return (AppFunc)builder.Build(typeof(AppFunc));
 }
コード例 #24
0
        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);
        }
コード例 #25
0
ファイル: TestHttpClient.cs プロジェクト: dragan/gate
 /// <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)));
 }
コード例 #26
0
        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"]);
        }
コード例 #27
0
        // 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());
        }
コード例 #28
0
 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;
 }
コード例 #29
0
        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);
        }
コード例 #30
0
 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;
 }