Exemplo n.º 1
0
            public void SetUp()
            {
                const string verb            = "GET";
                const string applicationPath = "/";
                var          uri             = new Uri("http://example.com/resources/1?query=2");
                var          routeParameters = new Dictionary <string, string> {
                    { "route", "1" }
                };

                HttpContextBase.Request.HttpMethod.Returns(verb);
                HttpContextBase.Request.ApplicationPath.Returns(applicationPath);
                HttpContextBase.Request.Url.Returns(uri);

                var inputStream = Substitute.For <Stream>();

                inputStream.CanRead.Returns(false);
                HttpContextBase.Request.InputStream.Returns(inputStream);

                RequestRouter.FindRequestHandler(verb, applicationPath, uri).Returns(new RouteHandlerLookupResult(typeof(GetResource), routeParameters));

                RequestHandlerInvoker.Execute(
                    Arg.Any <GetResource>(),
                    verb,
                    routeParameters,
                    Arg.Is <IDictionary <string, string> >(x => x["query"] == "2"),
                    Arg.Is <IDictionary <string, object> >(x => (string)x["context"] == "3"),
                    Arg.Is <string>(x => x == null)).Returns(new HttpResponseMessage {
                    Content = new ObjectContent("test")
                });

                _piccoloContext = new PiccoloContext(HttpContextBase);
                _piccoloContext.Data.context = "3";

                Engine.ProcessRequest(_piccoloContext);
            }
Exemplo n.º 2
0
            public void SetUp()
            {
                const string verb            = "POST";
                const string applicationPath = "/";
                var          uri             = new Uri("http://example.com/resources");
                var          routeParameters = new Dictionary <string, string>();

                HttpContextBase.Request.HttpMethod.Returns(verb);
                HttpContextBase.Request.ApplicationPath.Returns(applicationPath);
                HttpContextBase.Request.Url.Returns(uri);
                HttpContextBase.Request.InputStream.Returns(new MemoryStream(Encoding.UTF8.GetBytes("\"request_payload\"")));

                RequestRouter.FindRequestHandler(verb, applicationPath, uri).Returns(new RouteHandlerLookupResult(typeof(CreateResource), routeParameters));

                var httpResponseMessage = new HttpResponseMessage(HttpStatusCode.Created);

                httpResponseMessage.Headers.Location = new Uri("http://example.com/resources/1");

                RequestHandlerInvoker.Execute(
                    Arg.Any <CreateResource>(),
                    verb,
                    routeParameters,
                    Arg.Is <IDictionary <string, string> >(x => x.Count == 0),
                    Arg.Any <IDictionary <string, object> >(),
                    Arg.Is <string>(x => x == "request_payload")).Returns(httpResponseMessage);

                _piccoloContext = new PiccoloContext(HttpContextBase);

                Engine.ProcessRequest(_piccoloContext);
            }
Exemplo n.º 3
0
            public void SetUp()
            {
                const string verb            = "DELETE";
                const string applicationPath = "/";
                var          uri             = new Uri("http://example.com/resources/1");
                var          routeParameters = new Dictionary <string, string> {
                    { "route", "1" }
                };

                HttpContextBase.Request.HttpMethod.Returns(verb);
                HttpContextBase.Request.ApplicationPath.Returns(applicationPath);
                HttpContextBase.Request.Url.Returns(uri);

                var inputStream = Substitute.For <Stream>();

                inputStream.CanRead.Returns(false);
                HttpContextBase.Request.InputStream.Returns(inputStream);

                RequestRouter.FindRequestHandler(verb, applicationPath, uri).Returns(new RouteHandlerLookupResult(typeof(DeleteResource), routeParameters));

                RequestHandlerInvoker.Execute(
                    Arg.Any <DeleteResource>(),
                    verb,
                    routeParameters,
                    Arg.Is <IDictionary <string, string> >(x => x.Count == 0),
                    Arg.Any <IDictionary <string, object> >(),
                    Arg.Is <string>(x => x == string.Empty)).Returns(new HttpResponseMessage(HttpStatusCode.NoContent));

                _piccoloContext = new PiccoloContext(HttpContextBase);

                Engine.ProcessRequest(_piccoloContext);
            }
Exemplo n.º 4
0
        public void ProcessRequest(PiccoloContext context)
        {
            try
            {
                _eventDispatcher.RaiseRequestProcessingEvent(context);

                var lookupResult = _requestRouter.FindRequestHandler(context.RequestVerb, context.RequestUri);
                if (lookupResult.IsSuccessful)
                {
                    var requestHandler      = _configuration.ObjectFactory.CreateInstance <IRequestHandler>(lookupResult.RequestHandlerType);
                    var httpResponseMessage = _requestHandlerInvoker.Execute(requestHandler, context.RequestVerb, lookupResult.RouteParameters, context.RequestQueryParameters, context.RequestPayload);
                    InjectResponse(context, httpResponseMessage);
                }
                else
                {
                    InjectResponse(context, new HttpResponseMessage(HttpStatusCode.NotFound));
                }
            }
            catch (Exception ex)
            {
                _eventDispatcher.RaiseRequestFaultedEvent(context, ex);
                InjectResponse(context, new HttpResponseMessage(HttpStatusCode.InternalServerError));
            }
            finally
            {
                _eventDispatcher.RaiseRequestProcessedEvent(context);
            }
        }
Exemplo n.º 5
0
        public void ProcessRequest(PiccoloContext context)
        {
            var lookupResult = _requestRouter.FindRequestHandler(context.RequestVerb, context.RequestUri);

            if (lookupResult.IsSuccessful)
            {
                var requestHandler      = _configuration.RequestHandlerFactory.CreateInstance(lookupResult.RequestHandlerType);
                var httpResponseMessage = _requestHandlerInvoker.Execute(requestHandler, context.RequestVerb, lookupResult.RouteParameters, context.RequestQueryParameters, context.RequestPayload);
                InjectResponse(context, httpResponseMessage);
            }
            else
            {
                InjectResponse(context, new HttpResponseMessage(HttpStatusCode.NotFound));
            }
        }
Exemplo n.º 6
0
            public void SetUp()
            {
                const string verb            = "POST";
                const string applicationPath = "/";
                var          uri             = new Uri("http://example.com/resources/1");

                HttpContextBase.Request.HttpMethod.Returns(verb);
                HttpContextBase.Request.ApplicationPath.Returns(applicationPath);
                HttpContextBase.Request.Url.Returns(uri);

                var inputStream = Substitute.For <Stream>();

                inputStream.CanRead.Returns(false);
                HttpContextBase.Request.InputStream.Returns(inputStream);

                RequestRouter.FindRequestHandler(verb, applicationPath, uri).Returns(RouteHandlerLookupResult.FailedResult);

                _piccoloContext = new PiccoloContext(HttpContextBase);

                Engine.ProcessRequest(_piccoloContext);
            }
Exemplo n.º 7
0
 public void SetUp()
 {
     _routeHandlerLookupResult = RequestRouter.FindRequestHandler("get", string.Empty, new Uri("http://test.com/level-1/level-2", UriKind.Absolute));
 }
Exemplo n.º 8
0
 public void SetUp()
 {
     _routeHandlerLookupResult = RequestRouter.FindRequestHandler("get", string.Empty, new Uri("http://test.com/specificity/static", UriKind.Absolute));
 }
Exemplo n.º 9
0
 public void SetUp()
 {
     _routeHandlerLookupResult = RequestRouter.FindRequestHandler("get", "/v1", new Uri("http://test.com/v1", UriKind.Absolute));
 }