Example #1
0
        public void WriteMultipartWithIResource()
        {
            string fileToUpload = Path.Combine(Environment.CurrentDirectory, @"Http\Converters\FileToUpload.png");

            IDictionary <string, object> parts = new Dictionary <string, object>();

            parts.Add("name 1", "value 1");
            parts.Add("name 2", "value 2+1");
            HttpEntity entity = new HttpEntity("<root><child/></root>");

            entity.Headers.ContentType = MediaType.TEXT_XML;
            parts.Add("xml", entity);
            parts.Add("logo", new FileResource(fileToUpload));

            MockHttpOutputMessage message = new MockHttpOutputMessage();

            converter.Write(parts, MediaType.MULTIPART_FORM_DATA, message);

            MediaType contentType = message.Headers.ContentType;

            Assert.IsNotNull(contentType, "Invalid content-type");
            Assert.AreEqual("multipart", contentType.Type, "Invalid content-type");
            Assert.AreEqual("form-data", contentType.Subtype, "Invalid content-type");
            string boundary = contentType.GetParameter("boundary");

            Assert.IsNotNull(boundary, "Invalid content-type");

            string result = message.GetBodyAsString(Encoding.UTF8);

            Assert.IsTrue(result.Contains("--" + boundary + "\r\nContent-Disposition: form-data; name=\"name 1\"\r\nContent-Type: text/plain;charset=ISO-8859-1\r\n\r\nvalue 1\r\n"), "Invalid content-disposition");
            Assert.IsTrue(result.Contains("--" + boundary + "\r\nContent-Disposition: form-data; name=\"name 2\"\r\nContent-Type: text/plain;charset=ISO-8859-1\r\n\r\nvalue 2+1\r\n"), "Invalid content-disposition");
            Assert.IsTrue(result.Contains("--" + boundary + "\r\nContent-Disposition: form-data; name=\"xml\"\r\nContent-Type: text/xml\r\n\r\n<root><child/></root>\r\n"), "Invalid content-disposition");
            Assert.IsTrue(result.Contains("--" + boundary + "\r\nContent-Disposition: form-data; name=\"logo\"; filename=\"FileToUpload.png\"\r\nContent-Type: image/png\r\n\r\n"), "Invalid content-disposition");
        }
Example #2
0
        public void WriteWithUnknownExtension()
        {
            IResource body = new FileResource(@"C:\Dummy.unknown");

            MockHttpOutputMessage message = new MockHttpOutputMessage();

            converter.Write(body, null, message);

            Assert.AreEqual(new MediaType("application", "octet-stream"), message.Headers.ContentType, "Invalid content-type");
        }
Example #3
0
        public void WriteWithKnownExtension()
        {
            IResource body = new FileResource(@"C:\Dummy.txt");

            MockHttpOutputMessage message = new MockHttpOutputMessage();

            converter.Write(body, null, message);

            Assert.AreEqual(new MediaType("text", "plain"), message.Headers.ContentType, "Invalid content-type");
        }
        public void WriteWithKnownExtension()
        {
            FileInfo body = new FileInfo(@"C:\Dummy.txt");

            MockHttpOutputMessage message = new MockHttpOutputMessage();

            converter.Write(body, null, message);

            Assert.AreEqual(new MediaType("text", "plain"), message.Headers.ContentType, "Invalid content-type");
        }
        public void WriteWithUnknownExtension()
        {
            FileInfo body = new FileInfo(@"C:\Dummy.unknown");

            MockHttpOutputMessage message = new MockHttpOutputMessage();

            converter.Write(body, null, message);

            //Assert.AreEqual(body, message.GetBodyAsBytes(), "Invalid result");
            Assert.AreEqual(new MediaType("application", "octet-stream"), message.Headers.ContentType, "Invalid content-type");
        }
        public void WriteWithUnknownExtension()
        {
            FileInfo body = new FileInfo(@"C:\Dummy.unknown");

            MockHttpOutputMessage message = new MockHttpOutputMessage();

            converter.Write(body, null, message);

            //Assert.AreEqual(body, message.GetBodyAsBytes(), "Invalid result");
            Assert.AreEqual(new MediaType("application", "octet-stream"), message.Headers.ContentType, "Invalid content-type");
        }
	    public void Write() 
        {
            IResource body = new AssemblyResource("assembly://Spring.Rest.Tests/Spring.Http.Converters/Resource.txt");

            MockHttpOutputMessage message = new MockHttpOutputMessage();

            converter.Write(body, null, message);

            Assert.IsTrue(message.GetBodyAsBytes().Length > 0, "Invalid result");
            Assert.AreEqual(new MediaType("text", "plain"), message.Headers.ContentType, "Invalid content-type");
	    }
Example #8
0
        public void Write()
        {
            IResource body = new AssemblyResource("assembly://Spring.Rest.Tests/Spring.Http.Converters/Resource.txt");

            MockHttpOutputMessage message = new MockHttpOutputMessage();

            converter.Write(body, null, message);

            Assert.IsTrue(message.GetBodyAsBytes().Length > 0, "Invalid result");
            Assert.AreEqual(new MediaType("text", "plain"), message.Headers.ContentType, "Invalid content-type");
        }
Example #9
0
        public void WriteWithCustomExtension()
        {
            IResource body = new FileResource(@"C:\Dummy.myext");

            MockHttpOutputMessage message = new MockHttpOutputMessage();

            converter.MimeMapping.Add(".myext", "spring/custom");
            converter.Write(body, null, message);

            Assert.AreEqual(new MediaType("spring", "custom"), message.Headers.ContentType, "Invalid content-type");
        }
        public void WriteWithCustomExtension()
        {
            FileInfo body = new FileInfo(@"C:\Dummy.myext");

            MockHttpOutputMessage message = new MockHttpOutputMessage();

            converter.MimeMapping.Add(".myext", "spring/custom");
            converter.Write(body, null, message);

            Assert.AreEqual(new MediaType("spring", "custom"), message.Headers.ContentType, "Invalid content-type");
        }
        public void Write()
        {
            byte[] body = new byte[] { 0x1, 0x2 };

            MockHttpOutputMessage message = new MockHttpOutputMessage();

            converter.Write(body, null, message);

            Assert.AreEqual(body, message.GetBodyAsBytes(), "Invalid result");
            Assert.AreEqual(new MediaType("application", "octet-stream"), message.Headers.ContentType, "Invalid content-type");
            //Assert.AreEqual(2, message.Headers.ContentLength, "Invalid content-length");
        }
Example #12
0
        public void Write()
        {
            byte[] body = new byte[] { 0x1, 0x2 };

            MockHttpOutputMessage message = new MockHttpOutputMessage();

            converter.Write(body, null, message);

            Assert.AreEqual(body, message.GetBodyAsBytes(), "Invalid result");
            Assert.AreEqual(new MediaType("application", "octet-stream"), message.Headers.ContentType, "Invalid content-type");
            //Assert.AreEqual(2, message.Headers.ContentLength, "Invalid content-length");
        }
Example #13
0
        public void Write()
        {
            string            expectedBody = "<DataContractHttpMessageConverterTests.DataContractClass xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://schemas.datacontract.org/2004/07/Spring.Http.Converters.Xml\"><ID>1</ID><Name>Bruno Baïa</Name></DataContractHttpMessageConverterTests.DataContractClass>";
            DataContractClass body         = new DataContractClass("1", "Bruno Baïa");

            MockHttpOutputMessage message = new MockHttpOutputMessage();

            converter.Write(body, null, message);

            Assert.AreEqual(expectedBody, message.GetBodyAsString(Encoding.UTF8), "Invalid result");
            Assert.AreEqual(new MediaType("application", "xml"), message.Headers.ContentType, "Invalid content-type");
            //Assert.IsTrue(message.Headers.ContentLength > -1, "Invalid content-length");
        }
        public void Write()
        {
            XmlDocument body = new XmlDocument();
            body.LoadXml("<TestElement testAttribute='value' />");

            MockHttpOutputMessage message = new MockHttpOutputMessage();

            converter.Write(body, null, message);

            Assert.AreEqual(body.OuterXml, message.GetBodyAsString(Encoding.UTF8), "Invalid result");
            Assert.AreEqual(new MediaType("application", "xml"), message.Headers.ContentType, "Invalid content-type");
            //Assert.IsTrue(message.Headers.ContentLength > -1, "Invalid content-length");
        }
        public void Write()
        {
            string expectedBody = "<CustomClass xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><ID>1</ID><Name>Bruno Baïa</Name></CustomClass>";
            CustomClass body = new CustomClass("1", "Bruno Baïa");

            MockHttpOutputMessage message = new MockHttpOutputMessage();

            converter.Write(body, null, message);

            Assert.AreEqual(expectedBody, message.GetBodyAsString(Encoding.UTF8), "Invalid result");
            Assert.AreEqual(new MediaType("application", "xml"), message.Headers.ContentType, "Invalid content-type");
            //Assert.IsTrue(message.Headers.ContentLength > -1, "Invalid content-length");
        }
Example #16
0
        public void Write()
        {
            string      expectedBody = "<CustomClass xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><ID>1</ID><Name>Bruno Baïa</Name></CustomClass>";
            CustomClass body         = new CustomClass("1", "Bruno Baïa");

            MockHttpOutputMessage message = new MockHttpOutputMessage();

            converter.Write(body, null, message);

            Assert.AreEqual(expectedBody, message.GetBodyAsString(Encoding.UTF8), "Invalid result");
            Assert.AreEqual(new MediaType("application", "xml"), message.Headers.ContentType, "Invalid content-type");
            //Assert.IsTrue(message.Headers.ContentLength > -1, "Invalid content-length");
        }
        public void Write()
        {
            string expectedBody = "{\"ID\":\"1\",\"Name\":\"Bruno Baïa\"}";
            CustomClass body = new CustomClass("1", "Bruno Baïa");

            MockHttpOutputMessage message = new MockHttpOutputMessage();

            converter.Write(body, null, message);

            Assert.AreEqual(expectedBody, message.GetBodyAsString(Encoding.UTF8), "Invalid result");
            Assert.AreEqual(new MediaType("application", "json"), message.Headers.ContentType, "Invalid content-type");
            //Assert.IsTrue(message.Headers.ContentLength > -1, "Invalid content-length");
        }
Example #18
0
        public void WriteClass()
        {
            string       expectedBody = "{\"ID\":1,\"Age\":31}";
            CustomClass2 body         = new CustomClass2(1, 31);

            MockHttpOutputMessage message = new MockHttpOutputMessage();

            converter.Write(body, null, message);

            Assert.AreEqual(expectedBody, message.GetBodyAsString(Encoding.UTF8), "Invalid result");
            Assert.AreEqual(new MediaType("application", "json"), message.Headers.ContentType, "Invalid content-type");
            //Assert.IsTrue(message.Headers.ContentLength > -1, "Invalid content-length");
        }
Example #19
0
        public void Write()
        {
            XElement body = new XElement("Root",
                                         new XElement("TestElement", 1),
                                         new XElement("TestElement", 2));

            MockHttpOutputMessage message = new MockHttpOutputMessage();

            converter.Write(body, null, message);

            Assert.AreEqual(body.ToString(SaveOptions.DisableFormatting), message.GetBodyAsString(Encoding.UTF8), "Invalid result");
            Assert.AreEqual(new MediaType("application", "xml"), message.Headers.ContentType, "Invalid content-type");
            //Assert.IsTrue(message.Headers.ContentLength > -1, "Invalid content-length");
        }
        public void WriteDefaultCharset()
        {
            string body = "H\u00e9llo W\u00f6rld";
            Encoding charSet = Encoding.GetEncoding("ISO-8859-1");
            MediaType mediaType = new MediaType("text", "plain", charSet);

            MockHttpOutputMessage message = new MockHttpOutputMessage();

            converter.Write(body, null, message);

            Assert.AreEqual(body, message.GetBodyAsString(charSet), "Invalid result");
            Assert.AreEqual(mediaType, message.Headers.ContentType, "Invalid content-type");
            //Assert.AreEqual(charSet.GetBytes(body).Length, message.Headers.ContentLength, "Invalid content-length");
        }
        public void WriteUTF8()
        {
            string    body      = "H\u00e9llo W\u00f6rld";
            Encoding  charSet   = Encoding.UTF8;
            MediaType mediaType = new MediaType("text", "plain", charSet);

            MockHttpOutputMessage message = new MockHttpOutputMessage();

            converter.Write(body, mediaType, message);

            Assert.AreEqual(body, message.GetBodyAsString(charSet), "Invalid result");
            Assert.AreEqual(mediaType, message.Headers.ContentType, "Invalid content-type");
            //Assert.AreEqual(charSet.GetBytes(body).Length, message.Headers.ContentLength, "Invalid content-length");
        }
Example #22
0
        public void Write()
        {
            XmlDocument body = new XmlDocument();

            body.LoadXml("<TestElement testAttribute='value' />");

            MockHttpOutputMessage message = new MockHttpOutputMessage();

            converter.Write(body, null, message);

            Assert.AreEqual(body.OuterXml, message.GetBodyAsString(Encoding.UTF8), "Invalid result");
            Assert.AreEqual(new MediaType("application", "xml"), message.Headers.ContentType, "Invalid content-type");
            //Assert.IsTrue(message.Headers.ContentLength > -1, "Invalid content-length");
        }
        public void WriteJToken()
        {
            string  expectedBody = "{\"ID\":1,\"Name\":\"Bruno Baïa\"}";
            JObject body         = new JObject(
                new JProperty("ID", new JValue(1)),
                new JProperty("Name", new JValue("Bruno Baïa")));

            MockHttpOutputMessage message = new MockHttpOutputMessage();

            converter.Write(body, null, message);

            Assert.AreEqual(expectedBody, message.GetBodyAsString(Encoding.UTF8), "Invalid result");
            Assert.AreEqual(new MediaType("application", "json"), message.Headers.ContentType, "Invalid content-type");
            //Assert.IsTrue(message.Headers.ContentLength > -1, "Invalid content-length");
        }
Example #24
0
        public void WriteJsonValue()
        {
            string     expectedBody = "{\"ID\":1,\"Age\":31}";
            JsonObject body         = new JsonObject();

            body.AddValue("ID", new JsonValue(1));
            body.AddValue("Age", new JsonValue(31));

            MockHttpOutputMessage message = new MockHttpOutputMessage();

            converter.Write(body, null, message);

            Assert.AreEqual(expectedBody, message.GetBodyAsString(Encoding.UTF8), "Invalid result");
            Assert.AreEqual(new MediaType("application", "json"), message.Headers.ContentType, "Invalid content-type");
            //Assert.IsTrue(message.Headers.ContentLength > -1, "Invalid content-length");
        }
Example #25
0
        public void WriteForm()
        {
            string expectedBody      = "name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3";
            NameValueCollection body = new NameValueCollection();

            body.Add("name 1", "value 1");
            body.Add("name 2", "value 2+1");
            body.Add("name 2", "value 2+2");
            body.Add("name 3", null);
            Encoding charSet = Encoding.GetEncoding("ISO-8859-1");

            MockHttpOutputMessage message = new MockHttpOutputMessage();

            converter.Write(body, MediaType.APPLICATION_FORM_URLENCODED, message);

            Assert.AreEqual(expectedBody, message.GetBodyAsString(charSet), "Invalid result");
            Assert.AreEqual(new MediaType("application", "x-www-form-urlencoded"), message.Headers.ContentType, "Invalid content-type");
            //Assert.AreEqual(charSet.GetBytes(expectedBody).Length, message.Headers.ContentLength, "Invalid content-length");
        }
        public void Write()
        {
            DateTimeOffset offset = DateTimeOffset.UtcNow;

            string expectedBody = String.Format("<feed xmlns=\"http://www.w3.org/2005/Atom\"><title type=\"text\">Test Feed</title><subtitle type=\"text\">This is a test feed</subtitle><id>Atom10FeedHttpMessageConverterTests.Write</id><rights type=\"text\">Copyright 2010</rights><updated>{0}</updated><author><name>Bruno Baïa</name><uri>http://www.springframework.net/bbaia</uri><email>[email protected]</email></author><link rel=\"alternate\" href=\"http://www.springframework.net/Feed\" /></feed>",
                                                offset.ToString("yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture));

            SyndicationFeed   body = new SyndicationFeed("Test Feed", "This is a test feed", new Uri("http://www.springframework.net/Feed"), "Atom10FeedHttpMessageConverterTests.Write", offset);
            SyndicationPerson sp   = new SyndicationPerson("*****@*****.**", "Bruno Baïa", "http://www.springframework.net/bbaia");

            body.Authors.Add(sp);
            body.Copyright = new TextSyndicationContent("Copyright 2010");

            MockHttpOutputMessage message = new MockHttpOutputMessage();

            converter.Write(body, null, message);

            Assert.AreEqual(expectedBody, message.GetBodyAsString(Encoding.UTF8), "Invalid result");
            Assert.AreEqual(new MediaType("application", "atom+xml"), message.Headers.ContentType, "Invalid content-type");
            //Assert.IsTrue(message.Headers.ContentLength > -1, "Invalid content-length");
        }
Example #27
0
        public void Write()
        {
            DateTimeOffset offset = DateTimeOffset.UtcNow;

            string expectedBody = String.Format("<rss xmlns:a10=\"http://www.w3.org/2005/Atom\" version=\"2.0\"><channel><title>Test Feed</title><link>http://www.springframework.net/Feed</link><description>This is a test feed</description><copyright>Copyright 2010</copyright><managingEditor>[email protected]</managingEditor><lastBuildDate>{0}</lastBuildDate><a10:id>Atom10FeedHttpMessageConverterTests.Write</a10:id></channel></rss>",
                                                offset.ToString("ddd, dd MMM yyyy HH:mm:ss Z", CultureInfo.InvariantCulture));

            SyndicationFeed   body = new SyndicationFeed("Test Feed", "This is a test feed", new Uri("http://www.springframework.net/Feed"), "Atom10FeedHttpMessageConverterTests.Write", offset);
            SyndicationPerson sp   = new SyndicationPerson("*****@*****.**", "Bruno Baïa", "http://www.springframework.net/bbaia");

            body.Authors.Add(sp);
            body.Copyright = new TextSyndicationContent("Copyright 2010");

            MockHttpOutputMessage message = new MockHttpOutputMessage();

            converter.Write(body, null, message);

            Assert.AreEqual(expectedBody, message.GetBodyAsString(Encoding.UTF8), "Invalid result");
            Assert.AreEqual(new MediaType("application", "rss+xml"), message.Headers.ContentType, "Invalid content-type");
            //Assert.IsTrue(message.Headers.ContentLength > -1, "Invalid content-length");
        }
        public void Write()
        {
            XElement body = new XElement("Root",
                new XElement("TestElement", 1),
                new XElement("TestElement", 2));

            MockHttpOutputMessage message = new MockHttpOutputMessage();

            converter.Write(body, null, message);

            Assert.AreEqual(body.ToString(SaveOptions.DisableFormatting), message.GetBodyAsString(Encoding.UTF8), "Invalid result");
            Assert.AreEqual(new MediaType("application", "xml"), message.Headers.ContentType, "Invalid content-type");
            //Assert.IsTrue(message.Headers.ContentLength > -1, "Invalid content-length");
        }
        public void Write()
        {
            DateTimeOffset offset = DateTimeOffset.UtcNow;

            string expectedBody = String.Format("<rss xmlns:a10=\"http://www.w3.org/2005/Atom\" version=\"2.0\"><channel><title>Test Feed</title><link>http://www.springframework.net/Feed</link><description>This is a test feed</description><copyright>Copyright 2010</copyright><managingEditor>[email protected]</managingEditor><lastBuildDate>{0}</lastBuildDate><a10:id>Atom10FeedHttpMessageConverterTests.Write</a10:id></channel></rss>", 
                offset.ToString("ddd, dd MMM yyyy HH:mm:ss Z", CultureInfo.InvariantCulture));
            
            SyndicationFeed body = new SyndicationFeed("Test Feed", "This is a test feed", new Uri("http://www.springframework.net/Feed"), "Atom10FeedHttpMessageConverterTests.Write", offset);
            SyndicationPerson sp = new SyndicationPerson("*****@*****.**", "Bruno Baïa", "http://www.springframework.net/bbaia");
            body.Authors.Add(sp);
            body.Copyright = new TextSyndicationContent("Copyright 2010");

            MockHttpOutputMessage message = new MockHttpOutputMessage();

            converter.Write(body, null, message);

            Assert.AreEqual(expectedBody, message.GetBodyAsString(Encoding.UTF8), "Invalid result");
            Assert.AreEqual(new MediaType("application", "rss+xml"), message.Headers.ContentType, "Invalid content-type");
            //Assert.IsTrue(message.Headers.ContentLength > -1, "Invalid content-length");
        }
        public void Write()
        {
            DateTimeOffset offset = DateTimeOffset.UtcNow;

            string expectedBody = String.Format("<feed xmlns=\"http://www.w3.org/2005/Atom\"><title type=\"text\">Test Feed</title><subtitle type=\"text\">This is a test feed</subtitle><id>Atom10FeedHttpMessageConverterTests.Write</id><rights type=\"text\">Copyright 2010</rights><updated>{0}</updated><author><name>Bruno Baïa</name><uri>http://www.springframework.net/bbaia</uri><email>[email protected]</email></author><link rel=\"alternate\" href=\"http://www.springframework.net/Feed\" /></feed>",
                offset.ToString("yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture));

            SyndicationFeed body = new SyndicationFeed("Test Feed", "This is a test feed", new Uri("http://www.springframework.net/Feed"), "Atom10FeedHttpMessageConverterTests.Write", offset);
            SyndicationPerson sp = new SyndicationPerson("*****@*****.**", "Bruno Baïa", "http://www.springframework.net/bbaia");
            body.Authors.Add(sp);
            body.Copyright = new TextSyndicationContent("Copyright 2010");

            MockHttpOutputMessage message = new MockHttpOutputMessage();

            converter.Write(body, null, message);

            Assert.AreEqual(expectedBody, message.GetBodyAsString(Encoding.UTF8), "Invalid result");
            Assert.AreEqual(new MediaType("application", "atom+xml"), message.Headers.ContentType, "Invalid content-type");
            //Assert.IsTrue(message.Headers.ContentLength > -1, "Invalid content-length");
        }
        public void WriteForm()
        {
            string expectedBody = "name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3";
            NameValueCollection body = new NameValueCollection();
            body.Add("name 1", "value 1");
            body.Add("name 2", "value 2+1");
            body.Add("name 2", "value 2+2");
            body.Add("name 3", null);
            Encoding charSet = Encoding.GetEncoding("ISO-8859-1");

            MockHttpOutputMessage message = new MockHttpOutputMessage();

            converter.Write(body, MediaType.APPLICATION_FORM_URLENCODED, message);

            Assert.AreEqual(expectedBody, message.GetBodyAsString(charSet), "Invalid result");
            Assert.AreEqual(new MediaType("application", "x-www-form-urlencoded"), message.Headers.ContentType, "Invalid content-type");
            //Assert.AreEqual(charSet.GetBytes(expectedBody).Length, message.Headers.ContentLength, "Invalid content-length");
        }
        public void WriteMultipartWithIResource()
        {
            string fileToUpload = Path.Combine(Environment.CurrentDirectory, @"Http\Converters\FileToUpload.png");

            IDictionary<string, object> parts = new Dictionary<string, object>();
            parts.Add("name 1", "value 1");
            parts.Add("name 2", "value 2+1");
            HttpEntity entity = new HttpEntity("<root><child/></root>");
            entity.Headers.ContentType = MediaType.TEXT_XML;
            parts.Add("xml", entity);
            parts.Add("logo", new FileResource(fileToUpload));

            MockHttpOutputMessage message = new MockHttpOutputMessage();

            converter.Write(parts, MediaType.MULTIPART_FORM_DATA, message);

            MediaType contentType = message.Headers.ContentType;
            Assert.IsNotNull(contentType, "Invalid content-type");
            Assert.AreEqual("multipart", contentType.Type, "Invalid content-type");
            Assert.AreEqual("form-data", contentType.Subtype, "Invalid content-type");
            string boundary = contentType.GetParameter("boundary");
            Assert.IsNotNull(boundary, "Invalid content-type");

            string result = message.GetBodyAsString(Encoding.UTF8);
            Assert.IsTrue(result.Contains("--" + boundary + "\r\nContent-Disposition: form-data; name=\"name 1\"\r\nContent-Type: text/plain;charset=ISO-8859-1\r\n\r\nvalue 1\r\n"), "Invalid content-disposition");
            Assert.IsTrue(result.Contains("--" + boundary + "\r\nContent-Disposition: form-data; name=\"name 2\"\r\nContent-Type: text/plain;charset=ISO-8859-1\r\n\r\nvalue 2+1\r\n"), "Invalid content-disposition");
            Assert.IsTrue(result.Contains("--" + boundary + "\r\nContent-Disposition: form-data; name=\"xml\"\r\nContent-Type: text/xml\r\n\r\n<root><child/></root>\r\n"), "Invalid content-disposition");
            Assert.IsTrue(result.Contains("--" + boundary + "\r\nContent-Disposition: form-data; name=\"logo\"; filename=\"FileToUpload.png\"\r\nContent-Type: image/png\r\n\r\n"), "Invalid content-disposition");
        }
        public void WriteWithUnknownExtension()
        {
            IResource body = new FileResource(@"C:\Dummy.unknown");

            MockHttpOutputMessage message = new MockHttpOutputMessage();

            converter.Write(body, null, message);

            Assert.AreEqual(new MediaType("application", "octet-stream"), message.Headers.ContentType, "Invalid content-type");
        }
        public void WriteJToken()
        {
            string expectedBody = "{\"ID\":1,\"Name\":\"Bruno Baïa\"}";
            JObject body = new JObject(
                new JProperty("ID", new JValue(1)),
                new JProperty("Name", new JValue("Bruno Baïa")));

            MockHttpOutputMessage message = new MockHttpOutputMessage();

            converter.Write(body, null, message);

            Assert.AreEqual(expectedBody, message.GetBodyAsString(Encoding.UTF8), "Invalid result");
            Assert.AreEqual(new MediaType("application", "json"), message.Headers.ContentType, "Invalid content-type");
            //Assert.IsTrue(message.Headers.ContentLength > -1, "Invalid content-length");
        }
        public void WriteJsonValue()
        {
            string expectedBody = "{\"ID\":1,\"Age\":31}";
            JsonObject body = new JsonObject();
            body.AddValue("ID", new JsonValue(1));
            body.AddValue("Age", new JsonValue(31));

            MockHttpOutputMessage message = new MockHttpOutputMessage();

            converter.Write(body, null, message);

            Assert.AreEqual(expectedBody, message.GetBodyAsString(Encoding.UTF8), "Invalid result");
            Assert.AreEqual(new MediaType("application", "json"), message.Headers.ContentType, "Invalid content-type");
            //Assert.IsTrue(message.Headers.ContentLength > -1, "Invalid content-length");
        }