示例#1
0
        public void AddingHandlerBodyWithMapper()
        {
            var request = Request.Has(Method.Post)
                          .And("/posts/my-post/comment/my-comment".ToMatchableUri())
                          .And(Body.From("{\"given\":\"John\",\"family\":\"Doe\"}"))
                          .And(Version.Http1_1);
            var mappedParameters =
                new Action.MappedParameters(1, Method.Post, "ignored", new List <Action.MappedParameter>
            {
                new Action.MappedParameter("String", "my-post"),
                new Action.MappedParameter("String", "my-comment")
            });

#pragma warning disable 618
            var handler = CreateRequestHandler(
                Method.Post,
                "/posts/{postId}/comment/{commentId}/votes/{votesNumber}",
                ParameterResolver.Path <string>(0),
                ParameterResolver.Path <string>(1),
                ParameterResolver.Path <int>(2),
                ParameterResolver.Query("page", 10)
                )
                          .Body <NameData>(typeof(TestMapper));
#pragma warning restore 618

            AssertResolvesAreEquals(ParameterResolver.Body <NameData>(), handler.ResolverParam5);
            Assert.Equal(new NameData("John", "Doe"), handler.ResolverParam5.Apply(request, mappedParameters));
        }
示例#2
0
        public void ActionWithoutParamNameShouldNotThrowException()
        {
            var handler = CreateRequestHandler(Method.Post, "/posts", ParameterResolver.Body <string>())
                          .Handle(postId => Completes.WithSuccess(Response.Of(Response.ResponseStatus.Ok, JsonSerialization.Serialized(postId))));

            Assert.Equal("", handler.ActionSignature);
        }
示例#3
0
        public void BodyContentFormData()
        {
            var content = "--boundary\n" +
                          "Content-Disposition: form-data; name=\"field1\"\n\n" +
                          "value1\n" + "--boundary\n" +
                          "Content-Disposition: form-data; name=\"field2\"; filename=\"example.txt\"\n\n" +
                          "value2\n" + "--boundary--";

            var binaryMediaTypeDescriptor = "multipart/form-data;boundary=\"boundary\"";

            var binaryMediaType = ContentMediaType.ParseFromDescriptor(binaryMediaTypeDescriptor);
            var binaryRequest   = Request.Has(Method.Post)
                                  .And(Version.Http1_1)
                                  .And("/user/my-post".ToMatchableUri())
                                  .And(RequestHeader.FromString("Host:www.vlingo.io"))
                                  .And(RequestHeader.WithContentType(binaryMediaTypeDescriptor))
                                  .And(Http.Body.From(content));

            var resolver = ParameterResolver.Body <RequestData>();

            var result   = resolver.Apply(binaryRequest, _mappedParameters);
            var expected = new RequestData(
                Http.Body.From(content),
                ContentMediaType.ParseFromDescriptor(binaryMediaTypeDescriptor),
                ContentEncoding.None());

            Assert.Equal(expected.MediaType, result.MediaType);
            Assert.Equal(expected.ContentEncoding, result.ContentEncoding);
            Assert.Equal(expected.Body.Content, result.Body.Content);
            Assert.Equal(ParameterResolver.Type.Body, resolver.Type);
        }
示例#4
0
 public RequestHandler2 <T, R> Body <R>(IMapper mapper)
 => new RequestHandler2 <T, R>(
     Method,
     Path,
     Resolver,
     ParameterResolver.Body <R>(mapper),
     ErrorHandler,
     MediaTypeMapper);
 public RequestHandler3 <T, TR, TU> Body <TU>(IMapper mapper)
 => new RequestHandler3 <T, TR, TU>(
     Method,
     Path,
     ResolverParam1,
     ResolverParam2,
     ParameterResolver.Body <TU>(mapper),
     ErrorHandler,
     MediaTypeMapper);
示例#6
0
        public void Body()
        {
            var resolver = ParameterResolver.Body <NameData>();

            var result   = resolver.Apply(_request, _mappedParameters);
            var expected = new NameData("John", "Doe");

            Assert.Equal(expected.ToString(), result.ToString());
            Assert.Equal(ParameterResolver.Type.Body, resolver.Type);
        }
 public RequestHandler4 <T, TR, TU, TI> Body <TI>()
 => new RequestHandler4 <T, TR, TU, TI>(
     Method,
     Path,
     ResolverParam1,
     ResolverParam2,
     ResolverParam3,
     ParameterResolver.Body <TI>(MediaTypeMapper),
     ErrorHandler,
     MediaTypeMapper);
    public void GenerateActionSignatureWhenNoPathIsSpecifiedIsEmptyString()
    {
        var handler = new RequestHandlerFake(
            Method.Get,
            "/hello",
            new List <IParameterResolver> {
            ParameterResolver.Body <NameData>()
        });

        Assert.Equal("", handler.ActionSignature);
    }
    public void GenerateActionWithOnePathParameterAndBodyJustReturnPathParameterSignature()
    {
        var handler = new RequestHandlerFake(
            Method.Get,
            "/user/{userId}",
            new List <IParameterResolver> {
            ParameterResolver.Path <string>(0), ParameterResolver.Body <NameData>()
        });

        Assert.Equal("String userId", handler.ActionSignature);
    }
示例#10
0
 public RequestHandler5 <T, TR, TU, TI, TJ> Body <TJ>(MediaTypeMapper mediaTypeMapper)
 => new RequestHandler5 <T, TR, TU, TI, TJ>(
     Method,
     Path,
     ResolverParam1,
     ResolverParam2,
     ResolverParam3,
     ResolverParam4,
     ParameterResolver.Body <TJ>(mediaTypeMapper),
     ErrorHandler,
     mediaTypeMapper);
示例#11
0
 public RequestHandler2 <T, R> Body <R>(MediaTypeMapper mediaTypeMapper)
 {
     MediaTypeMapper = mediaTypeMapper;
     return(new RequestHandler2 <T, R>(
                Method,
                Path,
                Resolver,
                ParameterResolver.Body <R>(mediaTypeMapper),
                ErrorHandler,
                mediaTypeMapper));
 }
示例#12
0
 public RequestHandler6 <T, TR, TU, TI, TJ, TK> Body <TK>() =>
 new RequestHandler6 <T, TR, TU, TI, TJ, TK>(
     Method,
     Path,
     ResolverParam1,
     ResolverParam2,
     ResolverParam3,
     ResolverParam4,
     ResolverParam5,
     ParameterResolver.Body <TK>(MediaTypeMapper),
     ErrorHandler,
     MediaTypeMapper);
示例#13
0
 public RequestHandler3 <T, TR, TU> Body <TU>(MediaTypeMapper mediaTypeMapper)
 {
     MediaTypeMapper = mediaTypeMapper;
     return(new RequestHandler3 <T, TR, TU>(
                Method,
                Path,
                ResolverParam1,
                ResolverParam2,
                ParameterResolver.Body <TU>(mediaTypeMapper),
                ErrorHandler,
                MediaTypeMapper));
 }
 public void UnsortedPathParametersThrowsException()
 {
     Assert.Throws <ArgumentException>(() =>
     {
         return(new RequestHandlerFake(
                    Method.Get,
                    "/user/{userId}",
                    new List <IParameterResolver>
         {
             ParameterResolver.Body <NameData>(), ParameterResolver.Path <string>(0)
         }));
     });
 }
示例#15
0
        public void BodyWithContentTypeMapper()
        {
            var mediaTypeMapper = new MediaTypeMapper.Builder()
                                  .AddMapperFor(ContentMediaType.Json, DefaultJsonMapper.Instance)
                                  .Build();

            var resolver = ParameterResolver.Body <NameData>(mediaTypeMapper);

            var result   = resolver.Apply(_request, _mappedParameters);
            var expected = new NameData("John", "Doe");

            Assert.Equal(expected.ToString(), result.ToString());
            Assert.Equal(ParameterResolver.Type.Body, resolver.Type);
        }
        public void AddingHandlerBody()
        {
            var request = Request.Has(Method.Post)
                          .And("/user/admin/name".ToMatchableUri())
                          .And(Body.From("{\"given\":\"John\",\"family\":\"Doe\"}"))
                          .And(Version.Http1_1);
            var mappedParameters =
                new Action.MappedParameters(1, Method.Post, "ignored", new List <Action.MappedParameter>
            {
                new Action.MappedParameter("String", "admin")
            });

            var handler = new RequestHandler0(Method.Get, "/user/admin/name").Body <NameData>();

            AssertResolvesAreEquals(ParameterResolver.Body <NameData>(), handler.Resolver);
            Assert.Equal(new NameData("John", "Doe"), handler.Resolver.Apply(request, mappedParameters));
        }
        public void AddingHandlerBodyWithMediaTypeMapper()
        {
            var request = Request.Has(Method.Post)
                          .And("/user/admin/name".ToMatchableUri())
                          .And(Body.From("{\"given\":\"John\",\"family\":\"Doe\"}"))
                          .And(RequestHeader.Of(RequestHeader.ContentType, "application/json"))
                          .And(Version.Http1_1);
            var mappedParameters =
                new Action.MappedParameters(1, Method.Post, "ignored", new List <Action.MappedParameter>
            {
                new Action.MappedParameter("String", "admin")
            });

#pragma warning disable 618
            var handler = new RequestHandler0(Method.Get, "/user/admin/name").Body <NameData>(typeof(TestMapper));
#pragma warning restore 618

            AssertResolvesAreEquals(ParameterResolver.Body <NameData>(new TestMapper()), handler.Resolver);
            Assert.Equal(new NameData("John", "Doe"), handler.Resolver.Apply(request, mappedParameters));
        }
示例#18
0
        public void BodyContentRequest()
        {
            var content = new byte[] { 0xD, 0xE, 0xA, 0xD, 0xB, 0xE, 0xE, 0xF };
            var binaryMediaTypeDescriptor = "application/octet-stream";
            var binaryMediaType           = ContentMediaType.ParseFromDescriptor(binaryMediaTypeDescriptor);
            var binaryRequest             = Request.Has(Method.Post)
                                            .And(Version.Http1_1)
                                            .And("/user/my-post".ToMatchableUri())
                                            .And(RequestHeader.FromString("Host:www.vlingo.io"))
                                            .And(RequestHeader.WithContentType(binaryMediaTypeDescriptor))
                                            .And(RequestHeader.WithContentEncoding(ContentEncodingMethod.Gzip.ToString()))
                                            .And(Http.Body.From(content, Http.Body.Encoding.None));

            var resolver = ParameterResolver.Body <RequestData>();

            var result   = resolver.Apply(binaryRequest, _mappedParameters);
            var expected = new RequestData(Http.Body.From(content, Http.Body.Encoding.None), binaryMediaType, new ContentEncoding(ContentEncodingMethod.Gzip));

            Assert.Equal(expected.ContentEncoding, result.ContentEncoding);
            Assert.Equal(expected.MediaType, result.MediaType);
            Assert.Equal(expected.Body.BinaryContent, result.Body.BinaryContent);
            Assert.Equal(ParameterResolver.Type.Body, resolver.Type);
        }
        public void AddingHandlerBody()
        {
            var request = Request.Has(Method.Post)
                          .And("/posts/my-post/comment/my-comment".ToMatchableUri())
                          .And(Body.From("{\"given\":\"John\",\"family\":\"Doe\"}"))
                          .And(Version.Http1_1);
            var mappedParameters =
                new Action.MappedParameters(1, Method.Post, "ignored", new List <Action.MappedParameter>
            {
                new Action.MappedParameter("String", "my-post"),
                new Action.MappedParameter("String", "my-comment")
            });

            var handler = CreateRequestHandler(
                Method.Post,
                "/posts/{postId}/comment/{commentId}",
                ParameterResolver.Path <string>(0),
                ParameterResolver.Path <string>(1))
                          .Body <NameData>();

            AssertResolvesAreEquals(ParameterResolver.Body <NameData>(), handler.ResolverParam3);
            Assert.Equal(new NameData("John", "Doe"), handler.ResolverParam3.Apply(request, mappedParameters));
        }
示例#20
0
        public void AddingHandlerBodyWithMapper()
        {
            var request = Request.Has(Method.Post)
                          .And("/user/admin/name".ToMatchableUri())
                          .And(Body.From("{\"given\":\"John\",\"family\":\"Doe\"}"))
                          .And(Version.Http1_1);
            var mappedParameters =
                new Action.MappedParameters(1, Method.Post, "ignored", new List <Action.MappedParameter>
            {
                new Action.MappedParameter("String", "admin")
            });

#pragma warning disable 618
            var handler = CreateRequestHandler(
                Method.Post,
                "/user/{userId}/picture/{pictureId}",
                ParameterResolver.Path <string>(0))
                          .Body <NameData>(typeof(TestMapper));
#pragma warning restore 618

            AssertResolvesAreEquals(ParameterResolver.Body <NameData>(), handler.ResolverParam2);
            Assert.Equal(new NameData("John", "Doe"), handler.ResolverParam2.Apply(request, mappedParameters));
        }
示例#21
0
 public RequestHandler1 <T> Body <T>()
 => new RequestHandler1 <T>(Method, Path, ParameterResolver.Body <T>(MediaTypeMapper), ErrorHandler, MediaTypeMapper);