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


C# Bootstrapper.Pipelines类代码示例

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


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

示例1: NancyEngineFixture

        public NancyEngineFixture()
        {
            this.resolver = A.Fake<IRouteResolver>();
            this.response = new Response();
            this.route = new FakeRoute(response);
            this.context = new NancyContext();
            this.errorHandler = A.Fake<IErrorHandler>();
            this.requestDispatcher = A.Fake<IRequestDispatcher>();

            A.CallTo(() => this.requestDispatcher.Dispatch(A<NancyContext>._)).Invokes(x => this.context.Response = new Response());

            A.CallTo(() => errorHandler.HandlesStatusCode(A<HttpStatusCode>.Ignored, A<NancyContext>.Ignored)).Returns(false);

            contextFactory = A.Fake<INancyContextFactory>();
            A.CallTo(() => contextFactory.Create()).Returns(context);

            A.CallTo(() => resolver.Resolve(A<NancyContext>.Ignored)).Returns(new ResolveResult(route, DynamicDictionary.Empty, null, null, null));

            var applicationPipelines = new Pipelines();

            this.routeInvoker = A.Fake<IRouteInvoker>();

            A.CallTo(() => this.routeInvoker.Invoke(A<Route>._, A<DynamicDictionary>._, A<NancyContext>._)).ReturnsLazily(arg =>
            {
                return (Response)((Route)arg.Arguments[0]).Action.Invoke((DynamicDictionary)arg.Arguments[1]);
            });

            this.engine =
                new NancyEngine(this.requestDispatcher, contextFactory, new[] { this.errorHandler }, A.Fake<IRequestTracing>())
                {
                    RequestPipelinesFactory = ctx => applicationPipelines
                };
        }
开发者ID:rhwy,项目名称:Nancy,代码行数:33,代码来源:NancyEngineFixture.cs

示例2: NancyEngineFixture

        public NancyEngineFixture()
        {
            this.resolver = A.Fake<IRouteResolver>();
            this.response = new Response();
            this.route = new FakeRoute(response);
            this.context = new NancyContext();
            this.statusCodeHandler = A.Fake<IStatusCodeHandler>();
            this.requestDispatcher = A.Fake<IRequestDispatcher>();
            this.diagnosticsConfiguration = new DiagnosticsConfiguration();

            A.CallTo(() => this.requestDispatcher.Dispatch(A<NancyContext>._, A<CancellationToken>._)).Invokes((x) => this.context.Response = new Response());

            A.CallTo(() => this.statusCodeHandler.HandlesStatusCode(A<HttpStatusCode>.Ignored, A<NancyContext>.Ignored)).Returns(false);

            contextFactory = A.Fake<INancyContextFactory>();
            A.CallTo(() => contextFactory.Create(A<Request>._)).Returns(context);

            var resolveResult = new ResolveResult { Route = route, Parameters = DynamicDictionary.Empty, Before = null, After = null, OnError = null };
            A.CallTo(() => resolver.Resolve(A<NancyContext>.Ignored)).Returns(resolveResult);

            var applicationPipelines = new Pipelines();

            this.routeInvoker = A.Fake<IRouteInvoker>();

            A.CallTo(() => this.routeInvoker.Invoke(A<Route>._, A<CancellationToken>._, A<DynamicDictionary>._, A<NancyContext>._)).ReturnsLazily(arg =>
            {
                return ((Route)arg.Arguments[0]).Action.Invoke((DynamicDictionary)arg.Arguments[1], A<CancellationToken>._).Result;
            });

            this.engine =
                new NancyEngine(this.requestDispatcher, this.contextFactory, new[] { this.statusCodeHandler }, A.Fake<IRequestTracing>(), this.diagnosticsConfiguration, new DisabledStaticContentProvider())
                {
                    RequestPipelinesFactory = ctx => applicationPipelines
                };
        }
开发者ID:randacc,项目名称:Nancy,代码行数:35,代码来源:NancyEngineFixture.cs

示例3: Should_create_default_error_hook_when_created_with_default_ctor

        public void Should_create_default_error_hook_when_created_with_default_ctor()
        {
            // Given, When
            var pipelines = new Pipelines();

            // Then
            pipelines.OnError.ShouldNotBeNull();
        }
开发者ID:JulianRooze,项目名称:Nancy,代码行数:8,代码来源:PipelinesFixture.cs

示例4: Should_create_default_before_request_hook_when_created_with_default_ctor

        public void Should_create_default_before_request_hook_when_created_with_default_ctor()
        {
            // Given, When
            var pipelines = new Pipelines();

            // Then
            pipelines.BeforeRequest.ShouldNotBeNull();
        }
开发者ID:JulianRooze,项目名称:Nancy,代码行数:8,代码来源:PipelinesFixture.cs

示例5: Should_clone_after_request_hooks_when_created_with_existing_pipeline

        public void Should_clone_after_request_hooks_when_created_with_existing_pipeline()
        {
            // Given
            Action<NancyContext> hook = ctx => ctx.Items.Add("foo", 1);

            var existing = new Pipelines();
            existing.AfterRequest.AddItemToEndOfPipeline(hook);

            // When
            var pipelines = new Pipelines(existing);

            // Then
            pipelines.AfterRequest.PipelineItems.ShouldHaveCount(1);
        }
开发者ID:JulianRooze,项目名称:Nancy,代码行数:14,代码来源:PipelinesFixture.cs

示例6: Should_clone_before_request_hooks_when_created_with_existing_pipeline

        public void Should_clone_before_request_hooks_when_created_with_existing_pipeline()
        {
            // Given
            Func<NancyContext, Response> hook = ctx => null;

            var existing = new Pipelines();
            existing.BeforeRequest.AddItemToEndOfPipeline(hook);

            // When
            var pipelines = new Pipelines(existing);

            // Then
            pipelines.BeforeRequest.PipelineItems.ShouldHaveCount(1);
        }
开发者ID:JulianRooze,项目名称:Nancy,代码行数:14,代码来源:PipelinesFixture.cs

示例7: Should_clone_error_hooks_when_created_with_existing_pipeline

        public void Should_clone_error_hooks_when_created_with_existing_pipeline()
        {
            // Given
            Func<NancyContext, Exception, Response> hook = (ctx, ex) => null;

            var existing = new Pipelines();
            existing.OnError.AddItemToEndOfPipeline(hook);

            // When
            var pipelines = new Pipelines(existing);

            // Then
            pipelines.OnError.PipelineItems.First().Delegate.ShouldBeSameAs(hook);
        }
开发者ID:JulianRooze,项目名称:Nancy,代码行数:14,代码来源:PipelinesFixture.cs

示例8: Post_request_hook_should_not_return_a_challenge_when_set_to_never

        public void Post_request_hook_should_not_return_a_challenge_when_set_to_never()
        {
            // Given
            var config = new BasicAuthenticationConfiguration(A.Fake<IUserValidator>(), "realm", UserPromptBehaviour.Never);
            var hooks = new Pipelines();
            BasicAuthentication.Enable(hooks, config);

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

            context.Response = new Response { StatusCode = HttpStatusCode.Unauthorized };

            // When
            hooks.AfterRequest.Invoke(context);

            // Then
            context.Response.Headers.ContainsKey("WWW-Authenticate").ShouldBeFalse();
        }
开发者ID:kppullin,项目名称:Nancy,代码行数:20,代码来源:BasicAuthenticationFixture.cs

示例9: HandleRequest_prereq_returns_response_should_still_run_postreq

        public void HandleRequest_prereq_returns_response_should_still_run_postreq()
        {
            // Given
            var returnedResponse = A.Fake<Response>();
            var postReqCalled = false;

            var pipelines = new Pipelines();
            pipelines.BeforeRequest.AddItemToStartOfPipeline(ctx => returnedResponse);
            pipelines.AfterRequest.AddItemToEndOfPipeline(ctx => postReqCalled = true);

            engine.RequestPipelinesFactory = (ctx) => pipelines;

            var request = new Request("GET", "/", "http");

            // When
            this.engine.HandleRequest(request);

            // Then
            postReqCalled.ShouldBeTrue();
        }
开发者ID:rhwy,项目名称:Nancy,代码行数:20,代码来源:NancyEngineFixture.cs

示例10: Post_request_hook_should_not_return_a_challenge_on_an_ajax_request_when_set_to_nonajax

        public void Post_request_hook_should_not_return_a_challenge_on_an_ajax_request_when_set_to_nonajax()
        {
            // Given
            var config = new BasicAuthenticationConfiguration(A.Fake<IUserValidator>(), "realm", UserPromptBehaviour.NonAjax);
            var hooks = new Pipelines();
            BasicAuthentication.Enable(hooks, config);
            var headers = new Dictionary<string,IEnumerable<string>>();
            headers.Add(ajaxRequestHeaderKey, new [] { ajaxRequestHeaderValue });

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

            context.Response = new Response { StatusCode = HttpStatusCode.Unauthorized };

            // When
            hooks.AfterRequest.Invoke(context);

            // Then
            context.Response.Headers.ContainsKey("WWW-Authenticate").ShouldBeFalse();
        }
开发者ID:kppullin,项目名称:Nancy,代码行数:22,代码来源:BasicAuthenticationFixture.cs

示例11: NancyEngineFixture

        public NancyEngineFixture()
        {
            this.environment =
                new DefaultNancyEnvironment();

            this.environment.Tracing(
                enabled: true,
                displayErrorTraces: true);

            this.resolver = A.Fake<IRouteResolver>();
            this.response = new Response();
            this.route = new FakeRoute(response);
            this.context = new NancyContext();
            this.statusCodeHandler = A.Fake<IStatusCodeHandler>();
            this.requestDispatcher = A.Fake<IRequestDispatcher>();
            this.negotiator = A.Fake<IResponseNegotiator>();

            A.CallTo(() => this.requestDispatcher.Dispatch(A<NancyContext>._, A<CancellationToken>._))
                .Returns(Task.FromResult(new Response()));

            A.CallTo(() => this.statusCodeHandler.HandlesStatusCode(A<HttpStatusCode>.Ignored, A<NancyContext>.Ignored)).Returns(false);

            contextFactory = A.Fake<INancyContextFactory>();
            A.CallTo(() => contextFactory.Create(A<Request>._)).Returns(context);

            var resolveResult = new ResolveResult { Route = route, Parameters = DynamicDictionary.Empty, Before = null, After = null, OnError = null };
            A.CallTo(() => resolver.Resolve(A<NancyContext>.Ignored)).Returns(resolveResult);

            var applicationPipelines = new Pipelines();

            this.routeInvoker = A.Fake<IRouteInvoker>();

            this.engine =
                new NancyEngine(this.requestDispatcher, this.contextFactory, new[] { this.statusCodeHandler }, A.Fake<IRequestTracing>(), new DisabledStaticContentProvider(), this.negotiator, this.environment)
                {
                    RequestPipelinesFactory = ctx => applicationPipelines
                };
        }
开发者ID:RadifMasud,项目名称:Nancy,代码行数:38,代码来源:NancyEngineFixture.cs

示例12: NancyEngineFixture

        public NancyEngineFixture()
        {
            this.resolver = A.Fake<IRouteResolver>();
            this.response = new Response();
            this.route = new FakeRoute(response);
            this.context = new NancyContext();
            this.errorHandler = A.Fake<IErrorHandler>();

            A.CallTo(() => errorHandler.HandlesStatusCode(A<HttpStatusCode>.Ignored, A<NancyContext>.Ignored)).Returns(false);

            contextFactory = A.Fake<INancyContextFactory>();
            A.CallTo(() => contextFactory.Create()).Returns(context);

            A.CallTo(() => resolver.Resolve(A<NancyContext>.Ignored)).Returns(new ResolveResult(route, DynamicDictionary.Empty, null, null));

            var applicationPipelines = new Pipelines();

            this.engine =
                new NancyEngine(resolver, contextFactory, new[] { this.errorHandler }, A.Fake<IRequestTracing>())
                {
                    RequestPipelinesFactory = ctx => applicationPipelines
                };
        }
开发者ID:RobertTheGrey,项目名称:Nancy,代码行数:23,代码来源:NancyEngineFixture.cs

示例13: Should_allow_post_request_hook_to_replace_response

        public void Should_allow_post_request_hook_to_replace_response()
        {
            // Given
            var newResponse = new Response();

            var pipelines = new Pipelines();
            pipelines.BeforeRequest.AddItemToStartOfPipeline(ctx => ctx.Response = newResponse);
            engine.RequestPipelinesFactory = (ctx) => pipelines;

            var request = new Request("GET", "/", "http");

            // When
            var result = this.engine.HandleRequest(request);

            // Then
            result.Response.ShouldBeSameAs(newResponse);
        }
开发者ID:ravindrapro,项目名称:Nancy,代码行数:17,代码来源:NancyEngineFixture.cs

示例14: Should_allow_post_request_hook_to_modify_context_items

        public void Should_allow_post_request_hook_to_modify_context_items()
        {
            // Given
            var pipelines = new Pipelines();
            pipelines.BeforeRequest.AddItemToStartOfPipeline(ctx =>
            {
                ctx.Items.Add("PostReqTest", new object());
                return null;
            });

            engine.RequestPipelinesFactory = (ctx) => pipelines;

            var request = new Request("GET", "/", "http");

            // When
            var result = this.engine.HandleRequest(request);

            // Then
            result.Items.ContainsKey("PostReqTest").ShouldBeTrue();
        }
开发者ID:ravindrapro,项目名称:Nancy,代码行数:20,代码来源:NancyEngineFixture.cs

示例15: Should_add_unhandled_exception_to_context_as_requestexecutionexception

        public void Should_add_unhandled_exception_to_context_as_requestexecutionexception()
        {
            // Given
            var routeUnderTest =
                new Route("GET", "/", null, (x,c) => { throw new Exception(); });

            var resolved =
                new ResolveResult(routeUnderTest, DynamicDictionary.Empty, null, null, null);

            A.CallTo(() => resolver.Resolve(A<NancyContext>.Ignored)).Returns(resolved);

            A.CallTo(() => this.routeInvoker.Invoke(A<Route>._, A<CancellationToken>._, A<DynamicDictionary>._, A<NancyContext>._))
                .Invokes((x) => routeUnderTest.Action.Invoke(DynamicDictionary.Empty, new CancellationToken()));

            A.CallTo(() => this.requestDispatcher.Dispatch(context, A<CancellationToken>._))
                .Returns(TaskHelpers.GetFaultedTask<Response>(new Exception()));

            var pipelines = new Pipelines();
            pipelines.OnError.AddItemToStartOfPipeline((ctx, exception) => null);
            engine.RequestPipelinesFactory = (ctx) => pipelines;

            var request = new Request("GET", "/", "http");

            // When
            var result = this.engine.HandleRequest(request);

            // Then
            result.Items.Keys.Contains("ERROR_EXCEPTION").ShouldBeTrue();
            result.Items["ERROR_EXCEPTION"].ShouldBeOfType<RequestExecutionException>();
        }
开发者ID:ravindrapro,项目名称:Nancy,代码行数:30,代码来源:NancyEngineFixture.cs


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