Example #1
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);
        }