public void Read()
        {
            string body = "{\"ID\":\"1\",\"Name\":\"Bruno Baïa\"}";

            MockHttpInputMessage message = new MockHttpInputMessage(body, Encoding.UTF8);

            CustomClass result = converter.Read<CustomClass>(message);
            Assert.IsNotNull(result, "Invalid result");
            Assert.AreEqual("1", result.ID, "Invalid result");
            Assert.AreEqual("Bruno Baïa", result.Name, "Invalid result");
        }
        public void ReadJToken()
        {
            string body = "{\"ID\":1,\"Name\":\"Bruno Baïa\"}";

            MockHttpInputMessage message = new MockHttpInputMessage(body, Encoding.UTF8);

            JToken result = converter.Read<JToken>(message);
            Assert.IsNotNull(result, "Invalid result");
            Assert.AreEqual(1, result.Value<int>("ID"), "Invalid result");
            Assert.AreEqual("Bruno Baïa", result.Value<string>("Name"), "Invalid result");
        }
Exemplo n.º 3
0
        public void ReadJsonValue()
        {
            string body = "{\"ID\":1,\"Name\":\"Bruno Baïa\"}";

            MockHttpInputMessage message = new MockHttpInputMessage(body, Encoding.UTF8);

            JsonValue result = converter.Read <JsonValue>(message);

            Assert.IsNotNull(result, "Invalid result");
            Assert.AreEqual(1, result.GetValue <int>("ID"), "Invalid result");
            Assert.AreEqual("Bruno Baïa", result.GetValue <string>("Name"), "Invalid result");
        }
        public void Read()
        {
            byte[] body = new byte[] { 0x1, 0x2 };

            MockHttpInputMessage message = new MockHttpInputMessage(body);
            message.Headers.ContentLength = body.Length;

            byte[] result = converter.Read<byte[]>(message);
            Assert.AreEqual(body.Length, result.Length, "Invalid result");
            Assert.AreEqual(body[0], result[0], "Invalid result");
            Assert.AreEqual(body[1], result[1], "Invalid result");
        }
	    public void Read() 
        {
            string body = "Hello Bruno Baïa";
            Encoding charSet = Encoding.UTF8;
            MediaType mediaType = new MediaType("text", "plain", charSet);

            MockHttpInputMessage message = new MockHttpInputMessage(body, charSet);
            message.Headers.ContentType = mediaType;
            
            string result = converter.Read<string>(message);
            Assert.AreEqual(body, result, "Invalid result");
	    }
Exemplo n.º 6
0
        public void ReadClass()
        {
            string body = "{\"ID\":1,\"Name\":\"Bruno Baïa\"}";

            MockHttpInputMessage message = new MockHttpInputMessage(body, Encoding.UTF8);

            CustomClass1 result = converter.Read <CustomClass1>(message);

            Assert.IsNotNull(result, "Invalid result");
            Assert.AreEqual(1, result.ID, "Invalid result");
            Assert.AreEqual("Bruno Baïa", result.Name, "Invalid result");
        }
Exemplo n.º 7
0
        public void Read()
        {
            byte[] body = new byte[] { 0x1, 0x2 };

            MockHttpInputMessage message = new MockHttpInputMessage(body);

            message.Headers.ContentLength = body.Length;

            byte[] result = converter.Read <byte[]>(message);
            Assert.AreEqual(body.Length, result.Length, "Invalid result");
            Assert.AreEqual(body[0], result[0], "Invalid result");
            Assert.AreEqual(body[1], result[1], "Invalid result");
        }
        public void Read()
        {
            string    body      = "Hello Bruno Baïa";
            Encoding  charSet   = Encoding.UTF8;
            MediaType mediaType = new MediaType("text", "plain", charSet);

            MockHttpInputMessage message = new MockHttpInputMessage(body, charSet);

            message.Headers.ContentType = mediaType;

            string result = converter.Read <string>(message);

            Assert.AreEqual(body, result, "Invalid result");
        }
        public void Read()
        {
            string body = "<TestElement testAttribute='value' />";

            MockHttpInputMessage message = new MockHttpInputMessage(body, Encoding.UTF8);

            XmlDocument result = converter.Read<XmlDocument>(message);
            Assert.IsNotNull(result, "Invalid result");
            XmlNode xmlNodeResult = result.SelectSingleNode("//TestElement");
            Assert.IsNotNull(xmlNodeResult, "Invalid result");
            Assert.AreEqual("TestElement", xmlNodeResult.LocalName, "Invalid result");
            Assert.IsNotNull(xmlNodeResult.Attributes["testAttribute"], "Invalid result");
            Assert.AreEqual("value", xmlNodeResult.Attributes["testAttribute"].Value, "Invalid result");
        }
        public void Read()
        {
            string body = @"<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>";

            MockHttpInputMessage message = new MockHttpInputMessage(body, Encoding.UTF8);

            CustomClass result = converter.Read<CustomClass>(message);
            Assert.IsNotNull(result, "Invalid result");
            Assert.AreEqual("1", result.ID, "Invalid result");
            Assert.AreEqual("Bruno Baïa", result.Name, "Invalid result");
        }
Exemplo n.º 11
0
        public void Read()
        {
            byte[] body = new byte[] { 0x1, 0x2 };

            MockHttpInputMessage message = new MockHttpInputMessage(body);

            IResource resource = converter.Read <IResource>(message);

            Assert.IsNotNull(resource, "Invalid result");
            Assert.IsTrue(resource is ByteArrayResource, "Invalid result");
            byte[] result = ((ByteArrayResource)resource).Bytes;
            Assert.AreEqual(body[0], result[0], "Invalid result");
            Assert.AreEqual(body[1], result[1], "Invalid result");
        }
        public void Read()
        {
            byte[] body = new byte[] { 0x1, 0x2 };

            MockHttpInputMessage message = new MockHttpInputMessage(body);

            IResource resource = converter.Read<IResource>(message);

            Assert.IsNotNull(resource, "Invalid result");
            Assert.IsTrue(resource is ByteArrayResource, "Invalid result");
            byte[] result = ((ByteArrayResource)resource).Bytes;
            Assert.AreEqual(body[0], result[0], "Invalid result");
            Assert.AreEqual(body[1], result[1], "Invalid result");
        }
Exemplo n.º 13
0
        public void Read()
        {
            string body = @"<?xml version='1.0' encoding='UTF-8' ?>
                <DataContractHttpMessageConverterTests.DataContractClass xmlns='http://schemas.datacontract.org/2004/07/Spring.Http.Converters.Xml' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>
                    <ID>1</ID><Name>Bruno Baïa</Name>
                </DataContractHttpMessageConverterTests.DataContractClass>";

            MockHttpInputMessage message = new MockHttpInputMessage(body, Encoding.UTF8);

            DataContractClass result = converter.Read <DataContractClass>(message);

            Assert.IsNotNull(result, "Invalid result");
            Assert.AreEqual("1", result.ID, "Invalid result");
            Assert.AreEqual("Bruno Baïa", result.Name, "Invalid result");
        }
Exemplo n.º 14
0
        public void Read()
        {
            string body = @"<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>";

            MockHttpInputMessage message = new MockHttpInputMessage(body, Encoding.UTF8);

            CustomClass result = converter.Read <CustomClass>(message);

            Assert.IsNotNull(result, "Invalid result");
            Assert.AreEqual("1", result.ID, "Invalid result");
            Assert.AreEqual("Bruno Baïa", result.Name, "Invalid result");
        }
Exemplo n.º 15
0
        public void Read()
        {
            string body = "<TestElement testAttribute='value' />";

            MockHttpInputMessage message = new MockHttpInputMessage(body, Encoding.UTF8);

            XmlDocument result = converter.Read <XmlDocument>(message);

            Assert.IsNotNull(result, "Invalid result");
            XmlNode xmlNodeResult = result.SelectSingleNode("//TestElement");

            Assert.IsNotNull(xmlNodeResult, "Invalid result");
            Assert.AreEqual("TestElement", xmlNodeResult.LocalName, "Invalid result");
            Assert.IsNotNull(xmlNodeResult.Attributes["testAttribute"], "Invalid result");
            Assert.AreEqual("value", xmlNodeResult.Attributes["testAttribute"].Value, "Invalid result");
        }
        public void Read()
        {
            string body = "<?xml version='1.0' encoding='UTF-8' ?><Root><TestElement testAttribute='value'/><TestElement testAttribute='novalue'/></Root>";

            MockHttpInputMessage message = new MockHttpInputMessage(body, Encoding.UTF8);

            XElement result = converter.Read<XElement>(message);
            Assert.IsNotNull(result, "Invalid result");
            //XElement xResult = result.Elements()
            //    .Where(x => x.Name == "TestElement" && x.Attribute("testAttribute").Value == "value")
            //    .Single();
            XElement xResult = (from el in result.Elements()
                                where el.Name == "TestElement" && el.Attribute("testAttribute").Value == "value"
                                select el)
                               .Single();
            Assert.IsNotNull(xResult, "Invalid result");
        }
        public void ReadForm()
        {
            String body = "name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3";
            Encoding charSet = Encoding.GetEncoding("ISO-8859-1");
            MediaType mediaType = new MediaType("application", "x-www-form-urlencoded", charSet);

            MockHttpInputMessage message = new MockHttpInputMessage(body, charSet);
            message.Headers.ContentType = mediaType;

            NameValueCollection result = converter.Read<NameValueCollection>(message);
            Assert.AreEqual(3, result.Count, "Invalid result");
            Assert.AreEqual(1, result.GetValues(0).Length, "Invalid result");
            Assert.AreEqual("value 1", result.GetValues(0)[0], "Invalid result");
            Assert.AreEqual(2, result.GetValues("name 2").Length, "Invalid result");
            Assert.AreEqual("value 2+1", result.GetValues("name 2")[0], "Invalid result");
            Assert.AreEqual("value 2+2", result.GetValues("name 2")[1], "Invalid result");
            Assert.IsNull(result["name 3"], "Invalid result");
        }
Exemplo n.º 18
0
        public void Read()
        {
            string body = "<?xml version='1.0' encoding='UTF-8' ?><Root><TestElement testAttribute='value'/><TestElement testAttribute='novalue'/></Root>";

            MockHttpInputMessage message = new MockHttpInputMessage(body, Encoding.UTF8);

            XElement result = converter.Read <XElement>(message);

            Assert.IsNotNull(result, "Invalid result");
            //XElement xResult = result.Elements()
            //    .Where(x => x.Name == "TestElement" && x.Attribute("testAttribute").Value == "value")
            //    .Single();
            XElement xResult = (from el in result.Elements()
                                where el.Name == "TestElement" && el.Attribute("testAttribute").Value == "value"
                                select el)
                               .Single();

            Assert.IsNotNull(xResult, "Invalid result");
        }
        public void Read()
        {
            DateTimeOffset offset = DateTimeOffset.UtcNow;

            string body = 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));

            MockHttpInputMessage message = new MockHttpInputMessage(body, Encoding.UTF8);

            SyndicationFeed result = converter.Read<SyndicationFeed>(message);
            Assert.IsNotNull(result, "Invalid result");
            Assert.AreEqual("Atom10FeedHttpMessageConverterTests.Write", result.Id, "Invalid result");
            Assert.AreEqual("Test Feed", result.Title.Text, "Invalid result");
            Assert.AreEqual("This is a test feed", result.Description.Text, "Invalid result");
            Assert.IsTrue(result.Links.Count == 1, "Invalid result");
            Assert.AreEqual(new Uri("http://www.springframework.net/Feed"), result.Links[0].Uri, "Invalid result");
            Assert.AreEqual("Copyright 2010", result.Copyright.Text, "Invalid result");
            Assert.IsTrue(result.Authors.Count == 1, "Invalid result");
            Assert.AreEqual("*****@*****.**", result.Authors[0].Email, "Invalid result");
        }
Exemplo n.º 20
0
        public void ReadForm()
        {
            String    body      = "name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3";
            Encoding  charSet   = Encoding.GetEncoding("ISO-8859-1");
            MediaType mediaType = new MediaType("application", "x-www-form-urlencoded", charSet);

            MockHttpInputMessage message = new MockHttpInputMessage(body, charSet);

            message.Headers.ContentType = mediaType;

            NameValueCollection result = converter.Read <NameValueCollection>(message);

            Assert.AreEqual(3, result.Count, "Invalid result");
            Assert.AreEqual(1, result.GetValues(0).Length, "Invalid result");
            Assert.AreEqual("value 1", result.GetValues(0)[0], "Invalid result");
            Assert.AreEqual(2, result.GetValues("name 2").Length, "Invalid result");
            Assert.AreEqual("value 2+1", result.GetValues("name 2")[0], "Invalid result");
            Assert.AreEqual("value 2+2", result.GetValues("name 2")[1], "Invalid result");
            Assert.IsNull(result["name 3"], "Invalid result");
        }
Exemplo n.º 21
0
        public void Read()
        {
            DateTimeOffset offset = DateTimeOffset.UtcNow;

            string body = 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));

            MockHttpInputMessage message = new MockHttpInputMessage(body, Encoding.UTF8);

            SyndicationFeed result = converter.Read <SyndicationFeed>(message);

            Assert.IsNotNull(result, "Invalid result");
            Assert.AreEqual("Atom10FeedHttpMessageConverterTests.Write", result.Id, "Invalid result");
            Assert.AreEqual("Test Feed", result.Title.Text, "Invalid result");
            Assert.AreEqual("This is a test feed", result.Description.Text, "Invalid result");
            Assert.IsTrue(result.Links.Count == 1, "Invalid result");
            Assert.AreEqual(new Uri("http://www.springframework.net/Feed"), result.Links[0].Uri, "Invalid result");
            Assert.AreEqual("Copyright 2010", result.Copyright.Text, "Invalid result");
            Assert.IsTrue(result.Authors.Count == 1, "Invalid result");
            Assert.AreEqual("*****@*****.**", result.Authors[0].Email, "Invalid result");
        }
        public void Read()
        {
            DateTimeOffset offset = DateTimeOffset.UtcNow;

            string body = 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));

            MockHttpInputMessage message = new MockHttpInputMessage(body, Encoding.UTF8);

            SyndicationFeed result = converter.Read<SyndicationFeed>(message);
            Assert.IsNotNull(result, "Invalid result");
            Assert.AreEqual("Atom10FeedHttpMessageConverterTests.Write", result.Id, "Invalid result");
            Assert.AreEqual("Test Feed", result.Title.Text, "Invalid result");
            Assert.AreEqual("This is a test feed", result.Description.Text, "Invalid result");
            Assert.IsTrue(result.Links.Count == 1, "Invalid result");
            Assert.AreEqual(new Uri("http://www.springframework.net/Feed"), result.Links[0].Uri, "Invalid result");
            Assert.AreEqual("Copyright 2010", result.Copyright.Text, "Invalid result");
            Assert.IsTrue(result.Authors.Count == 1, "Invalid result");
            Assert.AreEqual("Bruno Baïa", result.Authors[0].Name, "Invalid result");
            Assert.AreEqual("*****@*****.**", result.Authors[0].Email, "Invalid result");
            Assert.AreEqual("http://www.springframework.net/bbaia", result.Authors[0].Uri, "Invalid result");
        }
        public void Read()
        {
            DateTimeOffset offset = DateTimeOffset.UtcNow;

            string body = 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));

            MockHttpInputMessage message = new MockHttpInputMessage(body, Encoding.UTF8);

            SyndicationFeed result = converter.Read <SyndicationFeed>(message);

            Assert.IsNotNull(result, "Invalid result");
            Assert.AreEqual("Atom10FeedHttpMessageConverterTests.Write", result.Id, "Invalid result");
            Assert.AreEqual("Test Feed", result.Title.Text, "Invalid result");
            Assert.AreEqual("This is a test feed", result.Description.Text, "Invalid result");
            Assert.IsTrue(result.Links.Count == 1, "Invalid result");
            Assert.AreEqual(new Uri("http://www.springframework.net/Feed"), result.Links[0].Uri, "Invalid result");
            Assert.AreEqual("Copyright 2010", result.Copyright.Text, "Invalid result");
            Assert.IsTrue(result.Authors.Count == 1, "Invalid result");
            Assert.AreEqual("Bruno Baïa", result.Authors[0].Name, "Invalid result");
            Assert.AreEqual("*****@*****.**", result.Authors[0].Email, "Invalid result");
            Assert.AreEqual("http://www.springframework.net/bbaia", result.Authors[0].Uri, "Invalid result");
        }