当前位置: 首页>>代码示例>>C#>>正文


C# BeforePipeline类代码示例

本文整理汇总了C#中BeforePipeline的典型用法代码示例。如果您正苦于以下问题:C# BeforePipeline类的具体用法?C# BeforePipeline怎么用?C# BeforePipeline使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BeforePipeline类属于命名空间,在下文中一共展示了BeforePipeline类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Pipeline_containing_another_pipeline_will_invoke_items_in_both_pipelines

        public void Pipeline_containing_another_pipeline_will_invoke_items_in_both_pipelines()
        {
            // Given
            var item1Called = false;
            Func<NancyContext, Response> item1 = (r) => { item1Called = true; return null; };
            var item2Called = false;
            Func<NancyContext, Response> item2 = (r) => { item2Called = true; return null; };
            var item3Called = false;
            Func<NancyContext, Response> item3 = (r) => { item3Called = true; return null; };
            var item4Called = false;
            Func<NancyContext, Response> item4 = (r) => { item4Called = true; return null; };
            pipeline += item1;
            pipeline += item2;
            var subPipeline = new BeforePipeline();
            subPipeline += item3;
            subPipeline += item4;

            // When
            pipeline.AddItemToEndOfPipeline(subPipeline);
            pipeline.Invoke(CreateContext(), new CancellationToken());

            // Then
            Assert.True(item1Called);
            Assert.True(item2Called);
            Assert.True(item3Called);
            Assert.True(item4Called);
        }
开发者ID:rahulchrty,项目名称:Nancy,代码行数:27,代码来源:BeforePipelineFixture.cs

示例2: HandleRequest_should_allow_module_after_hook_to_add_items_to_context

        public void HandleRequest_should_allow_module_after_hook_to_add_items_to_context()
        {
            // Given
            var route = new FakeRoute();

            var before = new BeforePipeline();
            before += ctx => null;

            var after = new AfterPipeline();
            after += ctx => ctx.Items.Add("RoutePostReq", new object());

            var resolvedRoute = new ResolveResult(
                route,
                DynamicDictionary.Empty,
                before,
                after,
                null);

            A.CallTo(() => this.routeResolver.Resolve(A<NancyContext>.Ignored)).Returns(resolvedRoute);

            var context =
                new NancyContext { Request = new Request("GET", "/", "http") };

            // When
            this.requestDispatcher.Dispatch(context, new CancellationToken());

            // Then
            context.Items.ContainsKey("RoutePostReq").ShouldBeTrue();
        }
开发者ID:rahulchrty,项目名称:Nancy,代码行数:29,代码来源:DefaultRequestDispatcherFixture.cs

示例3: ResolveResult

 /// <summary>
 /// Initializes a new instance of the <see cref="ResolveResult"/> class, with
 /// the provided <paramref name="route"/>, <paramref name="parameters"/>, <paramref name="before"/>, 
 /// <paramref name="after"/> and <paramref name="onError"/>.
 /// </summary>
 /// <param name="route">The request route instance.</param>
 /// <param name="parameters">The parameters.</param>
 /// <param name="before">The before pipeline instance</param>
 /// <param name="after">The after pipeline instace.</param>
 /// <param name="onError">The on error interceptor instance.</param>
 public ResolveResult(Route route, DynamicDictionary parameters, BeforePipeline before, AfterPipeline after, Func<NancyContext, Exception, dynamic> onError)
 {
     this.Route = route;
     this.Parameters = parameters;
     this.Before = before;
     this.After = after;
     this.OnError = onError;
 }
开发者ID:uliian,项目名称:Nancy,代码行数:18,代码来源:ResolveResult.cs

示例4: Should_add_pre_and_post_hooks_when_enabled

    public void Should_add_pre_and_post_hooks_when_enabled() {
      var beforePipeline = new BeforePipeline();
      var afterPipeline = new AfterPipeline();
      var hooks = A.Fake<IPipelines>();
      A.CallTo(() => hooks.BeforeRequest).Returns(beforePipeline);
      A.CallTo(() => hooks.AfterRequest).Returns(afterPipeline);

      hooks.Enable(_fakeSessionManager);

      Assert.Equal(1, beforePipeline.PipelineDelegates.Count());
      Assert.Equal(1, afterPipeline.PipelineItems.Count());
    }
开发者ID:DavidLievrouw,项目名称:Nancy.Session.InProc,代码行数:12,代码来源:InProcSessionsFixture.cs

示例5: Should_add_pre_and_post_hooks_when_enabled

        public void Should_add_pre_and_post_hooks_when_enabled()
        {
            var beforePipeline = new BeforePipeline();
            var afterPipeline = new AfterPipeline();
            var hooks = A.Fake<IApplicationPipelines>();
            A.CallTo(() => hooks.BeforeRequest).Returns(beforePipeline);
            A.CallTo(() => hooks.AfterRequest).Returns(afterPipeline);

            CookieBasedSessions.Enable(hooks, encryptionProvider, "this passphrase", "this is a salt");

            beforePipeline.PipelineItems.Count().ShouldEqual(1);
            afterPipeline.PipelineItems.Count().ShouldEqual(1);
        }
开发者ID:ToJans,项目名称:Nancy,代码行数:13,代码来源:CookieBasedSessionsFixture.cs

示例6: Should_add_pre_and_post_hooks_when_enabled

        public void Should_add_pre_and_post_hooks_when_enabled()
        {
            var beforePipeline = new BeforePipeline();
            var afterPipeline = new AfterPipeline();
            var hooks = A.Fake<IPipelines>();
            A.CallTo(() => hooks.BeforeRequest).Returns(beforePipeline);
            A.CallTo(() => hooks.AfterRequest).Returns(afterPipeline);

            CookieBasedSessions.Enable(hooks, new CryptographyConfiguration(this.fakeEncryptionProvider, this.fakeHmacProvider));

            beforePipeline.PipelineDelegates.Count().ShouldEqual(1);
            afterPipeline.PipelineItems.Count().ShouldEqual(1);
        }
开发者ID:Borzoo,项目名称:Nancy,代码行数:13,代码来源:CookieBasedSessionsFixture.cs

示例7: Should_invoke_module_before_hook_followed_by_resolved_route_followed_by_module_after_hook

        public async Task Should_invoke_module_before_hook_followed_by_resolved_route_followed_by_module_after_hook()
        {
            // Given
            var capturedExecutionOrder = new List<string>();
            var expectedExecutionOrder = new[] { "Prehook", "RouteInvoke", "Posthook" };

            var route = new FakeRoute
            {
                Action = (parameters, token) =>
                {
                    capturedExecutionOrder.Add("RouteInvoke");
                    return Task.FromResult<object>(null);
                }
            };

            var before = new BeforePipeline();
            before += (ctx) =>
            {
                capturedExecutionOrder.Add("Prehook");
                return null;
            };

            var after = new AfterPipeline();
            after += (ctx) =>
            {
                capturedExecutionOrder.Add("Posthook");
            };

            var resolvedRoute = new ResolveResult
            {
                Route = route,
                Parameters = DynamicDictionary.Empty,
                Before = before,
                After = after,
                OnError = null
            };

            A.CallTo(() => this.routeResolver.Resolve(A<NancyContext>.Ignored)).Returns(resolvedRoute);

            var context =
                new NancyContext { Request = new Request("GET", "/", "http") };

            // When
            await this.requestDispatcher.Dispatch(context, new CancellationToken());

            // Then
            capturedExecutionOrder.Count().ShouldEqual(3);
            capturedExecutionOrder.SequenceEqual(expectedExecutionOrder).ShouldBeTrue();
        }
开发者ID:sloncho,项目名称:Nancy,代码行数:49,代码来源:DefaultRequestDispatcherFixture.cs

示例8: PlusEquals_with_another_pipeline_adds_those_pipeline_items_to_end_of_pipeline

        public void PlusEquals_with_another_pipeline_adds_those_pipeline_items_to_end_of_pipeline()
        {
            // Given
            pipeline.AddItemToEndOfPipeline(r => null);
            pipeline.AddItemToEndOfPipeline(r => CreateResponse());
            var pipeline2 = new BeforePipeline();
            pipeline2.AddItemToEndOfPipeline(r => null);
            pipeline2.AddItemToEndOfPipeline(r => CreateResponse());

            // When
            pipeline += pipeline2;

            // Then
            Assert.Equal(4, pipeline.PipelineItems.Count());
            Assert.Same(pipeline2.PipelineDelegates.ElementAt(0), pipeline.PipelineDelegates.ElementAt(2));
            Assert.Same(pipeline2.PipelineDelegates.ElementAt(1), pipeline.PipelineDelegates.Last());
        }
开发者ID:rahulchrty,项目名称:Nancy,代码行数:17,代码来源:BeforePipelineFixture.cs

示例9: PlusEquals_with_another_pipeline_adds_those_pipeline_items_to_end_of_pipeline

        public void PlusEquals_with_another_pipeline_adds_those_pipeline_items_to_end_of_pipeline()
        {
            Func<NancyContext, Response> item1 = (r) => { return null; };
            Func<NancyContext, Response> item2 = (r) => { return CreateResponse(); };
            pipeline.AddItemToEndOfPipeline(item1);
            pipeline.AddItemToEndOfPipeline(item2);
            Func<NancyContext, Response> item3 = (r) => { return null; };
            Func<NancyContext, Response> item4 = (r) => { return CreateResponse(); };
            var pipeline2 = new BeforePipeline();
            pipeline2.AddItemToEndOfPipeline(item3);
            pipeline2.AddItemToEndOfPipeline(item4);

            pipeline += pipeline2;

            Assert.Equal(4, pipeline.PipelineDelegates.Count());
            Assert.Same(item3, pipeline.PipelineDelegates.ElementAt(2));
            Assert.Same(item4, pipeline.PipelineDelegates.Last());
        }
开发者ID:leoduran,项目名称:Nancy,代码行数:18,代码来源:BeforePipelineFixture.cs

示例10: Should_add_response_cookie_if_it_has_changed

        public void Should_add_response_cookie_if_it_has_changed()
        {
            var beforePipeline = new BeforePipeline();
            var afterPipeline = new AfterPipeline();
            var hooks = A.Fake<IApplicationPipelines>();
            A.CallTo(() => hooks.BeforeRequest).Returns(beforePipeline);
            A.CallTo(() => hooks.AfterRequest).Returns(afterPipeline);
            CookieBasedSessions.Enable(hooks, encryptionProvider, "this passphrase", "this is a salt").WithFormatter(new Fakes.FakeSessionObjectFormatter());
            var request = CreateRequest("encryptedkey1=value1");
            A.CallTo(() => this.encryptionProvider.Decrypt("encryptedkey1=value1", A<string>.Ignored, A<byte[]>.Ignored)).Returns("key1=value1;");
            var response = A.Fake<Response>();
            var nancyContext = new NancyContext() { Request = request, Response = response };
            beforePipeline.Invoke(nancyContext);
            request.Session["Testing"] = "Test";

            afterPipeline.Invoke(nancyContext);

            response.Cookies.Count.ShouldEqual(1);
        }
开发者ID:ToJans,项目名称:Nancy,代码行数:19,代码来源:CookieBasedSessionsFixture.cs

示例11: Should_add_response_cookie_if_it_has_changed

        public void Should_add_response_cookie_if_it_has_changed()
        {
            var beforePipeline = new BeforePipeline();
            var afterPipeline = new AfterPipeline();
            var hooks = A.Fake<IPipelines>();
            A.CallTo(() => hooks.BeforeRequest).Returns(beforePipeline);
            A.CallTo(() => hooks.AfterRequest).Returns(afterPipeline);
            CookieBasedSessions.Enable(hooks, new CryptographyConfiguration(this.fakeEncryptionProvider, this.fakeHmacProvider)).WithSerializer(this.fakeObjectSerializer);
            var request = CreateRequest("encryptedkey1=value1");
            A.CallTo(() => this.fakeEncryptionProvider.Decrypt("encryptedkey1=value1")).Returns("key1=value1;");
            var response = A.Fake<Response>();
            var nancyContext = new NancyContext() { Request = request, Response = response };
            beforePipeline.Invoke(nancyContext, new CancellationToken());
            request.Session["Testing"] = "Test";

            afterPipeline.Invoke(nancyContext, new CancellationToken());

            response.Cookies.Count.ShouldEqual(1);
        }
开发者ID:Borzoo,项目名称:Nancy,代码行数:19,代码来源:CookieBasedSessionsFixture.cs

示例12: FakeOwinEnvironment

        private static BeforePipeline FakeOwinEnvironment()
        {
            var pipeline = new BeforePipeline();

            pipeline.AddItemToStartOfPipeline(
                context =>
                    {
                        context.Items.Add("OWIN_REQUEST_ENVIRONMENT", new Dictionary<string, object>());
                        return context.Response;
                    });

            return pipeline;
        }
开发者ID:mr-sandy,项目名称:kola,代码行数:13,代码来源:ContextBase.cs

示例13: Should_invoke_module_onerror_hook_when_module_after_hook_throws_exception

        public async Task Should_invoke_module_onerror_hook_when_module_after_hook_throws_exception()
        {
            // Given
            var capturedExecutionOrder = new List<string>();
            var expectedExecutionOrder = new[] { "Posthook", "OnErrorHook" };

            var route = new FakeRoute
            {
                Action = (parameters, ct) => Task.FromResult<object>(null)
            };

            var before = new BeforePipeline();
            before += ctx => null;

            var after = new AfterPipeline();
            after += ctx =>
                         {
                             capturedExecutionOrder.Add("Posthook");
                             throw new Exception("Posthook");
                         };

            var resolvedRoute = new ResolveResult(
                route,
                DynamicDictionary.Empty,
                before,
                after,
                (ctx, ex) => { capturedExecutionOrder.Add("OnErrorHook"); return new Response(); });

            A.CallTo(() => this.routeResolver.Resolve(A<NancyContext>.Ignored)).Returns(resolvedRoute);

            var context =
                new NancyContext { Request = new Request("GET", "/", "http") };

            // When
            await this.requestDispatcher.Dispatch(context, new CancellationToken());

            // Then
            capturedExecutionOrder.Count().ShouldEqual(2);
            capturedExecutionOrder.SequenceEqual(expectedExecutionOrder).ShouldBeTrue();
        }
开发者ID:sloncho,项目名称:Nancy,代码行数:40,代码来源:DefaultRequestDispatcherFixture.cs

示例14: BeforePipeline

        public async Task Should_not_invoke_resolved_route_if_module_before_hook_returns_response_but_should_invoke_module_after_hook()
        {
            // Given
            var capturedExecutionOrder = new List<string>();
            var expectedExecutionOrder = new[] { "Prehook", "Posthook" };

            var route = new FakeRoute
            {
                Action = (parameters, token) =>
                {
                    capturedExecutionOrder.Add("RouteInvoke");
                    return null;
                }
            };

            var before = new BeforePipeline();
            before += ctx =>
                          {
                              capturedExecutionOrder.Add("Prehook");
                              return new Response();
                          };

            var after = new AfterPipeline();
            after += ctx => capturedExecutionOrder.Add("Posthook");

            var resolvedRoute = new ResolveResult(
                route,
                DynamicDictionary.Empty,
                before,
                after,
                null);

            A.CallTo(() => this.routeResolver.Resolve(A<NancyContext>.Ignored)).Returns(resolvedRoute);

            var context =
                new NancyContext { Request = new Request("GET", "/", "http") };

            // When
            await this.requestDispatcher.Dispatch(context, new CancellationToken());

            // Then
            capturedExecutionOrder.Count().ShouldEqual(2);
            capturedExecutionOrder.SequenceEqual(expectedExecutionOrder).ShouldBeTrue();
        }
开发者ID:sloncho,项目名称:Nancy,代码行数:44,代码来源:DefaultRequestDispatcherFixture.cs

示例15: Should_allow_module_after_hook_to_change_response

        public async Task Should_allow_module_after_hook_to_change_response()
        {
            // Given
            var before = new BeforePipeline();
            before += ctx => null;

            var response = new Response();

            Func<NancyContext, Response> moduleAfterHookResponse = ctx => response;

            var after = new AfterPipeline();
            after += ctx =>
            {
                ctx.Response = moduleAfterHookResponse(ctx);
            };

            var route = new FakeRoute();

            var resolvedRoute = new ResolveResult(
                route,
                DynamicDictionary.Empty,
                before,
                after,
                null);

            A.CallTo(() => this.routeResolver.Resolve(A<NancyContext>.Ignored)).Returns(resolvedRoute);

            var context =
                new NancyContext { Request = new Request("GET", "/", "http") };

            // When
            await this.requestDispatcher.Dispatch(context, new CancellationToken());

            // Then
            context.Response.ShouldBeSameAs(response);
        }
开发者ID:sloncho,项目名称:Nancy,代码行数:36,代码来源:DefaultRequestDispatcherFixture.cs


注:本文中的BeforePipeline类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。