當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。