Пример #1
0
        public void RaisesEventAfterEachMessage()
        {
            var context = new FudgeContext();
            var messages = new FudgeMsg[]
            {
                new FudgeMsg(context, new Field("test", "data")),
                new FudgeMsg(context, new Field("life", 42))
            };
            var reader = new FudgeMsgStreamReader(context, messages);
            var writer = new FudgeMsgStreamWriter(context);

            var pipe = new FudgeStreamPipe(reader, writer);

            int count = 0;
            pipe.MessageProcessed += () =>
            {
                var message = writer.DequeueMessage();
                FudgeUtils.AssertAllFieldsMatch(messages[count], message);
                count++;
            };

            pipe.Process();

            Assert.Equal(2, count);
        }
Пример #2
0
        /// <summary>
        /// Convenience method for writing a <see cref="FudgeMsg"/> to a <see cref="IFudgeStreamWriter"/>.
        /// </summary>
        /// <param name="writer">Writer to write the data.</param>
        /// <param name="msg">Message to write.</param>
        public static void WriteMsg(this IFudgeStreamWriter writer, FudgeMsg msg)
        {
            var reader = new FudgeMsgStreamReader(msg.Context, msg);
            var pipe   = new FudgeStreamPipe(reader, writer);

            pipe.ProcessOne();
        }
Пример #3
0
        public void GeneralTest()
        {
            var context = new FudgeContext();

            var msg = StandardFudgeMessages.CreateMessageWithSubMsgs(context);
            var reader = new FudgeMsgStreamReader(context, msg);
            var writer = new FudgeMsgStreamWriter();

            var pipe = new FudgeStreamPipe(reader, writer);
            pipe.Process();

            var newMsg = writer.DequeueMessage();

            FudgeUtils.AssertAllFieldsMatch(msg, newMsg);
        }
Пример #4
0
        public void MultipleMessages()
        {
            var context = new FudgeContext();

            var msg1 = StandardFudgeMessages.CreateMessageWithSubMsgs(context);
            var msg2 = StandardFudgeMessages.CreateMessageAllNames(context);
            var reader = new FudgeMsgStreamReader(context, new FudgeMsg[] {msg1, msg2});
            var writer = new FudgeMsgStreamWriter();

            var pipe = new FudgeStreamPipe(reader, writer);
            pipe.Process();

            Assert.Equal(2, writer.PeekAllMessages().Count);
            FudgeUtils.AssertAllFieldsMatch(msg1, writer.DequeueMessage());
            FudgeUtils.AssertAllFieldsMatch(msg2, writer.DequeueMessage());
        }
        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);
        }
        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);
        }
Пример #7
0
        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);
        }
 /// <summary>
 /// Convenience method for writing a <see cref="FudgeMsg"/> to a <see cref="IFudgeStreamWriter"/>.
 /// </summary>
 /// <param name="writer">Writer to write the data.</param>
 /// <param name="msg">Message to write.</param>
 public static void WriteMsg(this IFudgeStreamWriter writer, FudgeMsg msg)
 {
     var reader = new FudgeMsgStreamReader(msg.Context, msg);
     var pipe = new FudgeStreamPipe(reader, writer);
     pipe.ProcessOne();
 }