public void JsonToXmlExecuteTest()
        {
            var jsonToXmlConverter = new JsonToXmlConverter
            {
                Namespace = "http://test",
                Prefix    = "ns0",
                RootNode  = "somenode"
            };

            IMessageInspectorContext context = new StubIMessageInspectorContext
            {
                TracerGet = () => new StubITracer(),
            };


            var testMessage = new TestMessage
            {
                ContentType = new ContentType("application/json"),
                Data        = GetJsonStream()
            };

            Task task = jsonToXmlConverter.Execute(testMessage, context);

            task.Wait();
            Assert.IsTrue(task.IsCompleted);

            var doc = new XmlDocument();

            doc.Load(testMessage.Data);

            Assert.IsTrue(doc.DocumentElement != null && doc.DocumentElement.Name == "ns0:somenode");
        }
Beispiel #2
0
        public void XmlToJsonExecuteTest()
        {
            var xmlToJsonConverter = new XmlToJsonConverter
            {
                TypeName = "Root"
            };

            var testMessage = new TestMessage
            {
                ContentType = new ContentType("application/xml"),
                Data        = GetXmlStream()
            };


            IMessageInspectorContext context = new StubIMessageInspectorContext
            {
                TracerGet = () => new StubITracer(),
            };

            Task task = xmlToJsonConverter.Execute(testMessage, context);

            task.Wait();
            Assert.IsTrue(task.IsCompleted);


            var     rdr    = new StreamReader(testMessage.Data);
            string  outMsg = rdr.ReadToEnd();
            JObject json   = JObject.Parse(outMsg);

            Assert.IsNotNull(json);
            JToken po = json.SelectToken("person");

            Assert.IsTrue(String.CompareOrdinal(po.SelectToken("name").Value <string>(), "Demo2") == 0);
        }