Beispiel #1
0
 public void BuildsWithSetup() {
     var pipeline = new Pipeline();
     pipeline.Use((env, next) => {
                      OwinContext.Get(env)
                                 .TraceOutput.Write("Do Before.");
                      return next(env);
                  },
                  env => new OwinHostContext(env).TraceOutput.Write("Setup Before."))
             .Use((env, next) => {
                      next(env)
                          .Wait();
                      OwinContext.Get(env)
                                 .TraceOutput.Write("Do After.");
                      return TaskHelper.Completed();
                  },
                  env => new OwinHostContext(env).TraceOutput.Write("Setup After."))
             .Use(env => {
                      OwinContext.Get(env)
                                 .TraceOutput.Write("Do App.");
                      return TaskHelper.Completed();
                  },
                  env => new OwinHostContext(env).TraceOutput.Write("Setup App."));
     var host = new TestHostAndServer(pipeline);
     host.Process(TestRequest.Get("/"));
     host.TraceOutputValue.ShouldEqual("Setup Before.Setup After.Setup App.Do Before.Do App.Do After.");
 }
Beispiel #2
0
 public static IDisposable App(Pipeline pipeline,
                               IPAddress address = null,
                               int? port = null,
                               IEnumerable<IOwinHostService> hostServices = null) {
     var host = BuildHost(address, port, hostServices);
     host.SetApp(pipeline);
     return host.Run();
 }
 public void HostPipeline() {
     var pipeline = new Pipeline();
     pipeline.Use(env => {
                      OwinContext.Get(env)
                                 .TraceOutput.Write("App");
                      return TaskHelper.Completed();
                  },
                  hostEnv => new OwinHostContext(hostEnv).TraceOutput.Write("Setup-"));
     var host = new TestHostAndServer(pipeline);
     host.ProcessGet("/");
     host.TraceOutputValue.ShouldEqual("Setup-App");
 }
 public void SetApp(Pipeline pipeline) {
     switch (_state) {
         case OwinHostState.ConfigureHost:
             throw new Exception("The Server must be specified before setting the AppFunc.");
         case OwinHostState.ConfigureApp:
             pipeline.Setup(_hostContext.Environment);
             var app = pipeline.Build();
             SetApp(app);
             return;
         case OwinHostState.Runnable:
             throw new Exception("The AppFunc may only be set once.");
         default:
             throw new ArgumentOutOfRangeException("Unknown Host State: " + _state);
     }
 }
Beispiel #5
0
 private static Pipeline BuildPipeline()
 {
     var pipeline = new Pipeline();
     pipeline.Use(DumpExceptionsMiddleware.PrintExceptions)
         .Use(DumpEnvironmentMiddleware.DumpOwinEnvironment)
         .Use(IdentityManagement.Middleware)
         .Use((env, next) =>
         {
             OwinContext context = OwinContext.Get(env);
             return context.Request.Path.StartsWith("/throw")
                 ? TaskHelper.Exception(new Exception("This is intentional!"))
                 : next(env);
         })
         .Use(SayHello.App);
     return pipeline;
 }
Beispiel #6
0
 public void BuildsInCorrectOrder() {
     var pipeline = new Pipeline();
     pipeline.Use((env, next) => {
                      OwinContext.Get(env)
                                 .TraceOutput.Write("Before.");
                      return next(env);
                  })
             .Use((env, next) => {
                      next(env)
                          .Wait();
                      OwinContext.Get(env)
                                 .TraceOutput.Write("After.");
                      return TaskHelper.Completed();
                  })
             .Use(env => {
                      OwinContext.Get(env)
                                 .TraceOutput.Write("App.");
                      return TaskHelper.Completed();
                  });
     var host = new TestHostAndServer(pipeline);
     host.Process(TestRequest.Get("/"));
     host.TraceOutputValue.ShouldEqual("Before.App.After.");
 }
 public TestHostAndServer(Pipeline pipeline, IEnumerable<IOwinHostService> hostServices = null) {
     _host = BuildHost(hostServices);
     _host.SetApp(pipeline);
 }