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


C# Routing.ResolveResult类代码示例

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


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

示例1: DefaultRequestDispatcherFixture

        public DefaultRequestDispatcherFixture()
        {
            this.responseProcessors = new List<IResponseProcessor>();
            this.routeResolver = A.Fake<IRouteResolver>();
            this.routeInvoker = A.Fake<IRouteInvoker>();
            this.negotiator = A.Fake<IResponseNegotiator>();

            A.CallTo(() => this.routeInvoker.Invoke(A<Route>._, A<CancellationToken>._, A<DynamicDictionary>._, A<NancyContext>._))
                .ReturnsLazily(async arg =>
                {
                    var routeResult = ((Route)arg.Arguments[0]).Invoke((DynamicDictionary)arg.Arguments[2], new CancellationToken()).ConfigureAwait(false);
                    var x = await routeResult;

                    return (Response)x;
                });

            this.requestDispatcher =
                new DefaultRequestDispatcher(this.routeResolver, this.responseProcessors, this.routeInvoker, this.negotiator);

            var resolvedRoute = new ResolveResult
            {
                Route = new FakeRoute(),
                Parameters = DynamicDictionary.Empty,
                Before = null,
                After = null,
                OnError = null
            };

            A.CallTo(() => this.routeResolver.Resolve(A<NancyContext>._)).Returns(resolvedRoute);
        }
开发者ID:sloncho,项目名称:Nancy,代码行数:30,代码来源:DefaultRequestDispatcherFixture.cs

示例2: DefaultRequestDispatcherFixture

        public DefaultRequestDispatcherFixture()
        {
            this.responseProcessors = new List<IResponseProcessor>();
            this.routeResolver = A.Fake<IRouteResolver>();
            this.routeInvoker = A.Fake<IRouteInvoker>();

            A.CallTo(() => this.routeInvoker.Invoke(A<Route>._, A<CancellationToken>._, A<DynamicDictionary>._, A<NancyContext>._)).ReturnsLazily(arg =>
                {
                    var tcs = new TaskCompletionSource<Response>();

                    var actionResult =
                        ((Route)arg.Arguments[0]).Action.Invoke(arg.Arguments[2], new CancellationToken());

                    var result =
                        actionResult.Result;

                    tcs.SetResult(result);

                    return tcs.Task;
                });

            this.requestDispatcher =
                new DefaultRequestDispatcher(this.routeResolver, this.responseProcessors, this.routeInvoker);

            var resolvedRoute = new ResolveResult
            {
                Route = new FakeRoute(),
                Parameters = DynamicDictionary.Empty,
                Before = null,
                After = null,
                OnError = null
            };

            A.CallTo(() => this.routeResolver.Resolve(A<NancyContext>._)).Returns(resolvedRoute);
        }
开发者ID:leoduran,项目名称:Nancy,代码行数:35,代码来源:DefaultRequestDispatcherFixture.cs

示例3: 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:randacc,项目名称:Nancy,代码行数:29,代码来源:DefaultRequestDispatcherFixture.cs

示例4: DefaultRequestDispatcherFixture

        public DefaultRequestDispatcherFixture()
        {
            this.responseProcessors = new List<IResponseProcessor>();
            this.routeResolver = A.Fake<IRouteResolver>();
            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(arg.Arguments[1]);
                });

            this.requestDispatcher =
                new DefaultRequestDispatcher(this.routeResolver, this.responseProcessors, this.routeInvoker);

            var resolvedRoute = new ResolveResult
            {
                Route = new FakeRoute(),
                Parameters = DynamicDictionary.Empty,
                Before = null,
                After = null,
                OnError = null
            };

            A.CallTo(() => this.routeResolver.Resolve(A<NancyContext>._)).Returns(resolvedRoute);
        }
开发者ID:kppullin,项目名称:Nancy,代码行数:25,代码来源:DefaultRequestDispatcherFixture.cs

示例5: 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

示例6: 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

示例7: FakeRequest

        public void Should_invoke_route_resolver_with_distinct_mapped_media_ranged_when_path_contains_extension_and_mapped_response_processors_exists()
        {
            // Given
            var requestedAcceptHeaders =
                new List<Tuple<string, decimal>>();

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

            var jsonProcessor =
                A.Fake<IResponseProcessor>();

            var jsonProcessormappings =
                new List<Tuple<string, MediaRange>> { { new Tuple<string, MediaRange>("json", "application/json") } };

            A.CallTo(() => jsonProcessor.ExtensionMappings).Returns(jsonProcessormappings);

            var otherProcessor =
                A.Fake<IResponseProcessor>();

            var otherProcessormappings =
                new List<Tuple<string, MediaRange>>
                    {
                        { new Tuple<string, MediaRange>("json", "application/json") },
                        { new Tuple<string, MediaRange>("xml", "application/xml") }
                    };

            A.CallTo(() => otherProcessor.ExtensionMappings).Returns(otherProcessormappings);

            this.responseProcessors.Add(jsonProcessor);
            this.responseProcessors.Add(otherProcessor);

            var resolvedRoute = new ResolveResult(
               new FakeRoute(),
               DynamicDictionary.Empty,
               null,
               null,
               null);

            A.CallTo(() => this.routeResolver.Resolve(context))
                .Invokes(x => requestedAcceptHeaders = ((NancyContext)x.Arguments[0]).Request.Headers.Accept.ToList())
                .Returns(resolvedRoute);

            // When
            this.requestDispatcher.Dispatch(context);

            // Then
            requestedAcceptHeaders.ShouldHaveCount(1);
            requestedAcceptHeaders[0].Item1.ShouldEqual("application/json");
        }
开发者ID:kppullin,项目名称:Nancy,代码行数:53,代码来源:DefaultRequestDispatcherFixture.cs

示例8: 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

示例9: Should_not_rethrow_exception_when_onerror_hook_returns_response

        public async Task Should_not_rethrow_exception_when_onerror_hook_returns_response()
        {
            // Given
            var route = new FakeRoute
            {
                Action = (parameters, ct) => TaskHelpers.GetFaultedTask<dynamic>(new Exception())
            };

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

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

            var resolvedRoute = new ResolveResult(
                route,
                DynamicDictionary.Empty,
                before,
                after,
                (ctx, ex) => new Response());

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

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

            //When
            var exception = await RecordAsync.Exception(async () => await this.requestDispatcher.Dispatch(context, new CancellationToken()));

            // Then
            exception.ShouldBeNull();
        }
开发者ID:sloncho,项目名称:Nancy,代码行数:32,代码来源:DefaultRequestDispatcherFixture.cs

示例10: Should_call_route_invoker_with_context

        public async Task Should_call_route_invoker_with_context()
        {
            // Given
            var context =
                new NancyContext
                {
                    Request = new FakeRequest("GET", "/user.json")
                };

            var resolvedRoute = new ResolveResult(
               new FakeRoute(),
               DynamicDictionary.Empty,
               null,
               null,
               null);

            A.CallTo(() => this.routeResolver.Resolve(context)).Returns(resolvedRoute);

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

            // Then
            A.CallTo(() => this.routeInvoker.Invoke(A<Route>._, A<CancellationToken>._, A<DynamicDictionary>._, context)).MustHaveHappened(Repeated.Exactly.Once);
        }
开发者ID:sloncho,项目名称:Nancy,代码行数:24,代码来源:DefaultRequestDispatcherFixture.cs

示例11: FakeRequest

        public async Task Should_set_quality_to_high_for_mapped_media_ranges_before_invoking_route_resolver_when_path_contains_extension_and_mapped_response_processors_exists()
        {
            // Given
            var requestedAcceptHeaders =
                new List<Tuple<string, decimal>>();

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

            var jsonProcessor =
                A.Fake<IResponseProcessor>();

            var jsonProcessormappings =
                new List<Tuple<string, MediaRange>> { { new Tuple<string, MediaRange>("json", "application/json") } };

            A.CallTo(() => jsonProcessor.ExtensionMappings).Returns(jsonProcessormappings);

            this.responseProcessors.Add(jsonProcessor);

            var resolvedRoute = new ResolveResult(
               new FakeRoute(),
               DynamicDictionary.Empty,
               null,
               null,
               null);

            A.CallTo(() => this.routeResolver.Resolve(context))
                .Invokes(x => requestedAcceptHeaders = ((NancyContext)x.Arguments[0]).Request.Headers.Accept.ToList())
                .Returns(resolvedRoute);

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

            // Then
            requestedAcceptHeaders.ShouldHaveCount(1);
            Assert.True(requestedAcceptHeaders[0].Item2 > 1.0m);
        }
开发者ID:sloncho,项目名称:Nancy,代码行数:40,代码来源:DefaultRequestDispatcherFixture.cs

示例12: Should_invoke_route_resolver_with_passed_in_accept_headers_when_path_does_not_contain_file_extensions

        public async Task Should_invoke_route_resolver_with_passed_in_accept_headers_when_path_does_not_contain_file_extensions()
        {
            // Given
            var expectedAcceptHeaders = new List<Tuple<string, decimal>>
            {
                { new Tuple<string, decimal>("application/json", 0.8m) },
                { new Tuple<string, decimal>("application/xml", 0.4m) }
            };

            var requestedAcceptHeaders =
                new List<Tuple<string, decimal>>();

            var request = new FakeRequest("GET", "/")
            {
                Headers = { Accept = expectedAcceptHeaders }
            };

            var context =
                new NancyContext { Request = request };

            var resolvedRoute = new ResolveResult(
               new FakeRoute(),
               DynamicDictionary.Empty,
               null,
               null,
               null);

            A.CallTo(() => this.routeResolver.Resolve(context))
                .Invokes(x => requestedAcceptHeaders = ((NancyContext)x.Arguments[0]).Request.Headers.Accept.ToList())
                .Returns(resolvedRoute);

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

            // Then
            requestedAcceptHeaders.ShouldHaveCount(2);
            requestedAcceptHeaders[0].Item1.ShouldEqual("application/json");
            requestedAcceptHeaders[0].Item2.ShouldEqual(0.8m);
            requestedAcceptHeaders[1].Item1.ShouldEqual("application/xml");
            requestedAcceptHeaders[1].Item2.ShouldEqual(0.4m);
        }
开发者ID:sloncho,项目名称:Nancy,代码行数:41,代码来源:DefaultRequestDispatcherFixture.cs

示例13: Should_set_the_context_resolved_route_from_resolve_result

        public async Task Should_set_the_context_resolved_route_from_resolve_result()
        {
            // Given
            const string expectedPath = "/the/path";

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

            var expectedRoute = new FakeRoute();

            var resolveResult = new ResolveResult(
               expectedRoute,
               new DynamicDictionary(),
               null,
               null,
               null);

            A.CallTo(() => this.routeResolver.Resolve(context)).Returns(resolveResult);

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

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

示例14: Should_invoke_module_onerror_hook_when_route_invoker_throws_exception

        public void Should_invoke_module_onerror_hook_when_route_invoker_throws_exception()
        {
            // Given
            var capturedExecutionOrder = new List<string>();
            var expectedExecutionOrder = new[] { "RouteInvoke", "OnErrorHook" };

            var route = new FakeRoute
            {
                Action = parameters =>
                {
                    capturedExecutionOrder.Add("RouteInvoke");
                    throw new Exception("RouteInvoke");
                }
            };

            var resolvedRoute = new ResolveResult(
                route,
                DynamicDictionary.Empty,
                ctx => null,
                ctx => capturedExecutionOrder.Add("Posthook"),
                (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
            this.requestDispatcher.Dispatch(context);

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

示例15: Should_invoke_module_before_hook_followed_by_resolved_route_followed_by_module_after_hook

        public void 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 =>
                {
                    capturedExecutionOrder.Add("RouteInvoke");
                    return null;
                }
            };

            var resolvedRoute = new ResolveResult
            {
                Route = route,
                Parameters = DynamicDictionary.Empty,
                Before = ctx => { capturedExecutionOrder.Add("Prehook"); return null; },
                After = ctx => capturedExecutionOrder.Add("Posthook"),
                OnError = 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);

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


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