コード例 #1
0
 public void WhenAll() {
     var control = new ControlComponent(ControlComponent.Match.All);
     control.When(env => false, (env, next) => TaskHelper.Exception(new Exception()));
     control.When(env => true,
                  (env, next) => {
                      env.SetValue("branch1", "pass");
                      return TaskHelper.Completed();
                  });
     control.When(env => false, (env, next) => TaskHelper.Exception(new Exception()));
     control.When(env => true,
                  (env, next) => {
                      env.SetValue("branch2", "pass");
                      return TaskHelper.Completed();
                  });
     var environment = OwinFactory.CreateEnvironment();
     var pipelineComponent = control as IPipelineComponent;
     pipelineComponent.Connect(Pipeline.ReturnDone);
     Task task = pipelineComponent.Execute(environment);
     task.Wait();
     task.IsCanceled.ShouldBeFalse();
     task.IsFaulted.ShouldBeFalse();
     task.IsCompleted.ShouldBeTrue();
     environment.GetValue<string>("branch1")
                .ShouldEqual("pass");
     environment.GetValue<string>("branch2")
                .ShouldEqual("pass");
 }
コード例 #2
0
        public void WhenAll()
        {
            var control = new ControlComponent(ControlComponent.Match.All);

            control.When(env => false, (env, next) => TaskHelper.Exception(new Exception()));
            control.When(env => true,
                         (env, next) => {
                env.SetValue("branch1", "pass");
                return(TaskHelper.Completed());
            });
            control.When(env => false, (env, next) => TaskHelper.Exception(new Exception()));
            control.When(env => true,
                         (env, next) => {
                env.SetValue("branch2", "pass");
                return(TaskHelper.Completed());
            });
            var environment       = OwinFactory.CreateEnvironment();
            var pipelineComponent = control as IPipelineComponent;

            pipelineComponent.Connect(Pipeline.ReturnDone);
            Task task = pipelineComponent.Execute(environment);

            task.Wait();
            task.IsCanceled.ShouldBeFalse();
            task.IsFaulted.ShouldBeFalse();
            task.IsCompleted.ShouldBeTrue();
            environment.GetValue <string>("branch1")
            .ShouldEqual("pass");
            environment.GetValue <string>("branch2")
            .ShouldEqual("pass");
        }
コード例 #3
0
        public static IPipeline All(this IPipeline pipeline, Action <ControlComponent> setup)
        {
            var controler = new ControlComponent(ControlComponent.Match.All);

            setup(controler);
            pipeline.Use(controler);
            return(pipeline);
        }
コード例 #4
0
 public static void IsGet(this ControlComponent component, string pathRegex, IPipelineComponent handler)
 {
     component.When(BuildGetFilter(pathRegex), handler);
 }
コード例 #5
0
 public static void IsGet(this ControlComponent component, string pathRegex, MiddlewareFunc middlewareFunc, SetupAction setup = null)
 {
     component.When(BuildGetFilter(pathRegex), middlewareFunc, setup);
 }
コード例 #6
0
 public static IPipeline All(this IPipeline pipeline, Action<ControlComponent> setup) {
     var controler = new ControlComponent(ControlComponent.Match.All);
     setup(controler);
     pipeline.Use(controler);
     return pipeline;
 }