A standard implementation of IAppBuilder
상속: IAppBuilder
예제 #1
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));
 }
예제 #2
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;
 }
예제 #3
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();
 }
예제 #4
0
 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 LoadWithAssemblyAndFullTypeName_Success(string data, string expected)
 {
     ServerFactoryLoader loader = new ServerFactoryLoader(new ServerFactoryActivator(ServicesFactory.Create()));
     IServerFactoryAdapter serverFactory = loader.Load(data);
     Assert.NotNull(serverFactory);
     IAppBuilder builder = new AppBuilder();
     serverFactory.Create(builder);
     Assert.Equal(expected, builder.Properties["create.server"]);
 }
예제 #6
0
 public void LoadWithAssemblyName_DiscoverDefaultFactoryName()
 {
     ServerFactoryLoader loader = new ServerFactoryLoader(new ServerFactoryActivator(ServicesFactory.Create()));
     IServerFactoryAdapter serverFactory = loader.Load("Microsoft.Owin.Hosting.Tests");
     Assert.NotNull(serverFactory);
     IAppBuilder builder = new AppBuilder();
     serverFactory.Create(builder);
     Assert.Equal("Microsoft.Owin.Hosting.Tests.ServerFactory", builder.Properties["create.server"]);
 }
예제 #7
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;
 }
예제 #8
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"]);
        }
예제 #9
0
 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));
 }
예제 #10
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"]);
        }
예제 #11
0
        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"]);
        }
예제 #12
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
        }
예제 #13
0
 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);
 }
예제 #14
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));
        }
예제 #15
0
        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);
        }
예제 #17
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());
        }
예제 #18
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));
        }
예제 #19
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);
        }
예제 #20
0
        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();
        }
예제 #21
0
        public void Configure(Action<IAppBuilder> startup)
        {
            if (startup == null)
            {
                throw new ArgumentNullException("startup");
            }

            var builder = new AppBuilder();

            builder.Properties[OwinConstants.ServerCapabilities] = new Dictionary<string, object>();
            builder.Properties[OwinConstants.HostOnAppDisposing] = _shutDownToken;
            builder.Properties[OwinConstants.HostAppNameKey] = InstanceName ?? Process.GetCurrentProcess().GetUniqueInstanceName(_shutDownToken);

            startup(builder);

            _appFunc = Build(builder);
        }
예제 #22
0
        public void NullArguments_ArgumentNullException()
        {
            var builder = new AppBuilder();
            Assert.Throws<ArgumentNullException>(() => builder.MapPredicate(null, FuncNotImplemented));
            Assert.Throws<ArgumentNullException>(() => builder.MapPredicate(NotImplementedPredicate, (AppFunc)null));
            Assert.Throws<ArgumentNullException>(() => builder.MapPredicate(null, ActionNotImplemented));
            Assert.Throws<ArgumentNullException>(() => builder.MapPredicate(NotImplementedPredicate, (Action<IAppBuilder>)null));
            Assert.Throws<ArgumentNullException>(() => new MapPredicateMiddleware(null, FuncNotImplemented, NotImplementedPredicate));
            Assert.Throws<ArgumentNullException>(() => new MapPredicateMiddleware(FuncNotImplemented, null, NotImplementedPredicate));
            Assert.Throws<ArgumentNullException>(() => new MapPredicateMiddleware(FuncNotImplemented, FuncNotImplemented, (Predicate)null));

            Assert.Throws<ArgumentNullException>(() => builder.MapPredicateAsync(null, FuncNotImplemented));
            Assert.Throws<ArgumentNullException>(() => builder.MapPredicateAsync(NotImplementedPredicateAsync, (AppFunc)null));
            Assert.Throws<ArgumentNullException>(() => builder.MapPredicateAsync(null, ActionNotImplemented));
            Assert.Throws<ArgumentNullException>(() => builder.MapPredicateAsync(NotImplementedPredicateAsync, (Action<IAppBuilder>)null));
            Assert.Throws<ArgumentNullException>(() => new MapPredicateMiddleware(null, FuncNotImplemented, NotImplementedPredicateAsync));
            Assert.Throws<ArgumentNullException>(() => new MapPredicateMiddleware(FuncNotImplemented, null, NotImplementedPredicateAsync));
            Assert.Throws<ArgumentNullException>(() => new MapPredicateMiddleware(FuncNotImplemented, FuncNotImplemented, (PredicateAsync)null));
        }
예제 #23
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();
            }
        }
예제 #24
0
        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();
            }
        }
예제 #25
0
 AppDelegate Build(Action<IAppBuilder> b)
 {
     var builder = new AppBuilder();
     b(builder);
     return (AppDelegate)builder.Build(typeof(AppDelegate));
 }
예제 #26
0
 AppFunc Build(Action<IAppBuilder> b)
 {
     var builder = new AppBuilder();
     b(builder);
     return (AppFunc)builder.Build(typeof(AppFunc));
 }
예제 #27
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;
 }
        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);
        }
예제 #29
0
파일: AppBuilder.cs 프로젝트: loudej/owin
 public object Build(Type signature, Action<object> configuration)
 {
     var nestedBuilder = new AppBuilder(_conversions, _properties);
     configuration.Invoke(nestedBuilder);
     return nestedBuilder.BuildInternal(signature);
 }
예제 #30
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;
 }