public void NestedMessages()
        {
            string xml = "<?xml version=\"1.0\" encoding=\"utf-16\"?><msg><name>Fred</name><address><number>17</number><line1>Our House</line1><line2>In the middle of our street</line2><phone>1234</phone><local /></address></msg>";

            var reader = new FudgeXmlStreamReader(context, xml);
            var writer = new FudgeMsgStreamWriter();

            new FudgeStreamPipe(reader, writer).Process();

            var msg = writer.DequeueMessage();

            Assert.Equal("Our House", msg.GetMessage("address").GetString("line1"));

            // Convert back to XML and see if it matches
            var sb        = new StringBuilder();
            var xmlWriter = XmlWriter.Create(sb);
            var reader2   = new FudgeMsgStreamReader(context, msg);
            var writer2   = new FudgeXmlStreamWriter(context, xmlWriter, "msg")
            {
                AutoFlushOnMessageEnd = true
            };

            new FudgeStreamPipe(reader2, writer2).Process();

            var xml2 = sb.ToString();

            Assert.Equal(xml, xml2);
        }
        public void PicksUpPropertiesFromContext()
        {
            var newContext = new FudgeContext();

            var writer = new FudgeXmlStreamWriter(newContext, XmlWriter.Create(new MemoryStream()), "msg");

            Assert.True(writer.AutoFlushOnMessageEnd);

            newContext.SetProperty(FudgeXmlStreamWriter.AutoFlushOnMessageEndProperty, false);
            writer = new FudgeXmlStreamWriter(newContext, XmlWriter.Create(new MemoryStream()), "msg");
            Assert.False(writer.AutoFlushOnMessageEnd);
        }
        public void LargeMsg()
        {
            var      stringWriter = new StringWriter();
            var      xmlWriter    = new XmlTextWriter(stringWriter);
            var      streamWriter = new FudgeXmlStreamWriter(context, xmlWriter, "msg");
            FudgeMsg inMsg        = StandardFudgeMessages.CreateLargeMessage(context);

            streamWriter.WriteMsg(inMsg);

            string msgString = stringWriter.GetStringBuilder().ToString();
            var    msg       = new FudgeXmlStreamReader(context, msgString).ReadMsg();

            FudgeUtils.AssertAllFieldsMatch(inMsg, msg);
        }
        public void SimpleTest()
        {
            var sb        = new StringBuilder();
            var xmlWriter = XmlWriter.Create(sb, new XmlWriterSettings {
                OmitXmlDeclaration = true
            });
            var writer = new FudgeXmlStreamWriter(context, xmlWriter, "msg")
            {
                AutoFlushOnMessageEnd = true
            };

            writer.StartMessage();
            writer.WriteField("name", null, StringFieldType.Instance, "Bob");
            writer.EndMessage();

            Assert.Equal("<msg><name>Bob</name></msg>", sb.ToString());
        }
        public void MultipleMessages()
        {
            var sb        = new StringBuilder();
            var xmlWriter = XmlWriter.Create(sb, new XmlWriterSettings {
                OmitXmlDeclaration = true, ConformanceLevel = ConformanceLevel.Fragment
            });
            var writer = new FudgeXmlStreamWriter(context, xmlWriter, "msg")
            {
                AutoFlushOnMessageEnd = true
            };

            writer.StartMessage();
            writer.WriteField("name", null, StringFieldType.Instance, "Bob");
            writer.EndMessage();
            writer.StartMessage();
            writer.WriteField("hat", null, StringFieldType.Instance, "Stand");
            writer.EndMessage();

            Assert.Equal("<msg><name>Bob</name></msg><msg><hat>Stand</hat></msg>", sb.ToString());
        }
        public void WriteIndicatorType()
        {
            var msg       = new FudgeMsg(new Field("blank", IndicatorType.Instance));
            var sb        = new StringBuilder();
            var xmlWriter = XmlWriter.Create(sb, new XmlWriterSettings {
                OmitXmlDeclaration = true
            });
            var writer = new FudgeXmlStreamWriter(context, xmlWriter, "msg")
            {
                AutoFlushOnMessageEnd = true
            };
            var reader = new FudgeMsgStreamReader(context, msg);

            new FudgeStreamPipe(reader, writer).Process();
            xmlWriter.Flush();

            string s = sb.ToString();

            Assert.Equal("<msg><blank /></msg>", s);
        }
        public void MultipleMessages()
        {
            string inputXml = "<msg><name>Fred</name></msg><msg><name>Bob</name></msg>";
            var    reader   = new FudgeXmlStreamReader(context, inputXml);

            var sb        = new StringBuilder();
            var xmlWriter = XmlWriter.Create(sb, new XmlWriterSettings {
                OmitXmlDeclaration = true, ConformanceLevel = ConformanceLevel.Fragment
            });
            var writer = new FudgeXmlStreamWriter(context, xmlWriter, "msg")
            {
                AutoFlushOnMessageEnd = true
            };
            var multiwriter = new FudgeStreamMultiwriter(new DebuggingWriter(), writer);

            new FudgeStreamPipe(reader, multiwriter).Process();
            string outputXml = sb.ToString();

            Assert.Equal(inputXml, outputXml);
        }
        public void NestedMessages()
        {
            var msg = new FudgeMsg(new Field("name", "Fred"),
                                   new Field("address",
                                             new Field("number", 17),
                                             new Field("line1", "Our House"),
                                             new Field("line2", "In the middle of our street")));

            var sb        = new StringBuilder();
            var xmlWriter = XmlWriter.Create(sb, new XmlWriterSettings {
                OmitXmlDeclaration = true
            });
            var writer = new FudgeXmlStreamWriter(context, xmlWriter, "msg");
            var reader = new FudgeMsgStreamReader(context, msg);

            new FudgeStreamPipe(reader, writer).Process();
            xmlWriter.Flush();

            string s = sb.ToString();

            Assert.Equal("<msg><name>Fred</name><address><number>17</number><line1>Our House</line1><line2>In the middle of our street</line2></address></msg>", s);
        }