示例#1
0
 public void Setup()
 {
     _urlBuilder        = A.Fake <IUrlBuilder>();
     _putRequestMaker   = A.Fake <IPutRequestMaker>();
     _statusCodeHandler = A.Fake <IStatusCodeHandler>();
     _putRequestHandler = new PutRequestHandler(_urlBuilder, _putRequestMaker, _statusCodeHandler);
 }
示例#2
0
 public GetRequestHandler(IGetRequestMaker getRequestMaker, IUrlBuilder urlBuilder,
                          IStatusCodeHandler statusCodeHandler)
 {
     _getRequestMaker   = getRequestMaker;
     _urlBuilder        = urlBuilder;
     _statusCodeHandler = statusCodeHandler;
 }
示例#3
0
 public PutRequestHandler(IUrlBuilder urlBuilder, IPutRequestMaker putRequestMaker,
                          IStatusCodeHandler statusCodeHandler)
 {
     _urlBuilder        = urlBuilder;
     _putRequestMaker   = putRequestMaker;
     _statusCodeHandler = statusCodeHandler;
 }
示例#4
0
        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>._)).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);

            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, this.contextFactory, new[] { this.statusCodeHandler }, A.Fake<IRequestTracing>(), this.diagnosticsConfiguration, new DisabledStaticContentProvider())
                {
                    RequestPipelinesFactory = ctx => applicationPipelines
                };
        }
示例#5
0
        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> ._)).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()).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, this.contextFactory, new[] { this.statusCodeHandler }, A.Fake <IRequestTracing>(), this.diagnosticsConfiguration)
            {
                RequestPipelinesFactory = ctx => applicationPipelines
            };
        }
示例#6
0
 public PostRequestHandler(IPostRequestMaker postRequestMaker, IUrlBuilder urlBuilder,
                           IStatusCodeHandler statusCodeHandler)
 {
     _postRequestMaker  = postRequestMaker;
     _urlBuilder        = urlBuilder;
     _statusCodeHandler = statusCodeHandler;
 }
        public void Setup()
        {
            _getRequestMaker   = A.Fake <IGetRequestMaker>();
            _urlBuilder        = A.Fake <IUrlBuilder>();
            _statusCodeHandler = A.Fake <IStatusCodeHandler>();

            _getRequestHandler = new GetRequestHandler(_getRequestMaker, _urlBuilder, _statusCodeHandler);
        }
        private void CheckStatusCodeHandler(NancyContext context)
        {
            if (context.Response == null)
            {
                return;
            }

            IStatusCodeHandler defaultHandler = null;
            IStatusCodeHandler customHandler  = null;

            foreach (var statusCodeHandler in this.statusCodeHandlers)
            {
                if (!statusCodeHandler.HandlesStatusCode(context.Response.StatusCode, context))
                {
                    continue;
                }

                if (defaultHandler == null && (statusCodeHandler is DefaultStatusCodeHandler))
                {
                    defaultHandler = statusCodeHandler;
                    continue;
                }

                if (customHandler == null && !(statusCodeHandler is DefaultStatusCodeHandler))
                {
                    customHandler = statusCodeHandler;
                    continue;
                }

                if ((defaultHandler != null) && (customHandler != null))
                {
                    break;
                }
            }

            var handler = customHandler ?? defaultHandler;

            if (handler == null)
            {
                return;
            }

            try
            {
                handler.Handle(context.Response.StatusCode, context);
            }
            catch (Exception)
            {
                if (defaultHandler == null)
                {
                    throw;
                }

                defaultHandler.Handle(context.Response.StatusCode, context);
            }
        }
 public void Setup()
 {
     _urlBuilder         = A.Fake <IUrlBuilder>();
     _postRequestMaker   = A.Fake <IPostRequestMaker>();
     _statusCodeHandler  = A.Fake <IStatusCodeHandler>();
     _postRequestHandler = new PostRequestHandler(_postRequestMaker, _urlBuilder, _statusCodeHandler);
     _token      = "ABC";
     _playerId   = "12345";
     _startPrice = 1200;
     _binPrice   = 1100;
 }
示例#10
0
        public DefaultStatusCodeHandlerFixture()
        {
            var environment =
                new DefaultNancyEnvironment();

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

            this.responseNegotiator = A.Fake <IResponseNegotiator>();
            this.statusCodeHandler  = new DefaultStatusCodeHandler(this.responseNegotiator, environment);
        }
        public DefaultStatusCodeHandlerFixture()
        {
            var environment =
                new DefaultNancyEnvironment();

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

            this.responseNegotiator = A.Fake<IResponseNegotiator>();
            this.statusCodeHandler = new DefaultStatusCodeHandler(this.responseNegotiator, environment);
        }
示例#12
0
        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>();

            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>(), new DisabledStaticContentProvider(), this.negotiator, this.environment)
            {
                RequestPipelinesFactory = ctx => applicationPipelines
            };
        }
示例#13
0
        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>();

            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>(), new DisabledStaticContentProvider(), this.negotiator, this.environment)
                {
                    RequestPipelinesFactory = ctx => applicationPipelines
                };
        }
 public DefaultStatusCodeHandlerFixture()
 {
     this.responseNegotiator = A.Fake<IResponseNegotiator>();
     this.statusCodeHandler = new DefaultStatusCodeHandler(this.responseNegotiator);
 }
 public NotFoundErrorHandler(IResponseNegotiator responseNegotiator)
 {
     _defaultStatusCodeHandler = new DefaultStatusCodeHandler(responseNegotiator);
 }
示例#16
0
 public DefaultStatusCodeHandlerFixture()
 {
     this.statusCodeHandler = new DefaultStatusCodeHandler();
 }
 public DefaultStatusCodeHandlerFixture()
 {
     this.statusCodeHandler = new DefaultStatusCodeHandler();
 }
示例#18
0
 public void Setup()
 {
     _statusCodeHandler = new StatusCodeHandler();
 }
 public NotFoundErrorHandler(ILogger logger, IResponseNegotiator responseNegotiator)
 {
     _logger = logger;
     _defaultStatusCodeHandler = new DefaultStatusCodeHandler(responseNegotiator);
 }
 public DefaultStatusCodeHandlerFixture()
 {
     this.responseNegotiator = A.Fake <IResponseNegotiator>();
     this.statusCodeHandler  = new DefaultStatusCodeHandler(this.responseNegotiator);
 }