コード例 #1
0
        public void GetLeafFieldValueBytes()
        {
            Message          msg = MessagesProvider.GetMessage();
            ParserContext    pc  = new ParserContext(ParserContext.DefaultBufferSize);
            FormatterContext fc  = new FormatterContext(FormatterContext.DefaultBufferSize);

            ParentMessageExpression pme = new ParentMessageExpression(
                new MessageExpression(52));

            // Parent of a message without one.
            try {
                pme.GetLeafFieldValueString(ref fc, msg);
                Assert.Fail();
            }
            catch (ExpressionEvaluationException) {
            }

            // Passing null message (as parameter and in the contexts).
            try {
                pme.GetLeafFieldValueString(ref fc, null);
                Assert.Fail();
            }
            catch (ExpressionEvaluationException) {
            }
            try {
                pme.GetLeafFieldValueString(ref pc, null);
                Assert.Fail();
            }
            catch (ExpressionEvaluationException) {
            }

            msg = msg[62].Value as Message;
            Message anotherMsg = MessagesProvider.GetAnotherMessage();

            anotherMsg = anotherMsg[61].Value as Message;

            Assert.IsTrue(MessagesProvider.CompareByteArrays(pme.GetLeafFieldValueBytes(ref fc, msg),
                                                             new byte[] { 0x15, 0x20, 0x25, 0x30, 0x35, 0x40, 0x45, 0x50 }));
            fc.CurrentMessage = anotherMsg;
            Assert.IsTrue(MessagesProvider.CompareByteArrays(pme.GetLeafFieldValueBytes(ref fc, msg),
                                                             new byte[] { 0x15, 0x20, 0x25, 0x30, 0x35, 0x40, 0x45, 0x50 }));
            Assert.IsTrue(MessagesProvider.CompareByteArrays(pme.GetLeafFieldValueBytes(ref fc, null),
                                                             new byte[] { 0x55, 0x60, 0x65, 0x70, 0x75, 0x80, 0x85, 0x90 }));

            Assert.IsTrue(MessagesProvider.CompareByteArrays(pme.GetLeafFieldValueBytes(ref pc, msg),
                                                             new byte[] { 0x15, 0x20, 0x25, 0x30, 0x35, 0x40, 0x45, 0x50 }));
            pc.CurrentMessage = anotherMsg;
            Assert.IsTrue(MessagesProvider.CompareByteArrays(pme.GetLeafFieldValueBytes(ref pc, msg),
                                                             new byte[] { 0x15, 0x20, 0x25, 0x30, 0x35, 0x40, 0x45, 0x50 }));
            Assert.IsTrue(MessagesProvider.CompareByteArrays(pme.GetLeafFieldValueBytes(ref pc, null),
                                                             new byte[] { 0x55, 0x60, 0x65, 0x70, 0x75, 0x80, 0x85, 0x90 }));
        }
コード例 #2
0
        public void GetLeafFieldValueString()
        {
            Message          msg = MessagesProvider.GetMessage();
            ParserContext    pc  = new ParserContext(ParserContext.DefaultBufferSize);
            FormatterContext fc  = new FormatterContext(FormatterContext.DefaultBufferSize);

            ParentMessageExpression pme = new ParentMessageExpression(
                new MessageExpression(41));

            // Parent of a message without one.
            try {
                pme.GetLeafFieldValueString(ref fc, msg);
                Assert.Fail();
            }
            catch (ExpressionEvaluationException) {
            }

            // Passing null message (as parameter and in the contexts).
            try {
                pme.GetLeafFieldValueString(ref fc, null);
                Assert.Fail();
            }
            catch (ExpressionEvaluationException) {
            }
            try {
                pme.GetLeafFieldValueString(ref pc, null);
                Assert.Fail();
            }
            catch (ExpressionEvaluationException) {
            }

            msg = msg[61].Value as Message;
            Message anotherMsg = MessagesProvider.GetAnotherMessage();

            anotherMsg = anotherMsg[62].Value as Message;

            Assert.IsTrue(pme.GetLeafFieldValueString(ref fc, msg) == "TEST1");
            fc.CurrentMessage = anotherMsg;
            Assert.IsTrue(pme.GetLeafFieldValueString(ref fc, msg) == "TEST1");
            Assert.IsTrue(pme.GetLeafFieldValueString(ref fc, null) == "TEST2");

            Assert.IsTrue(pme.GetLeafFieldValueString(ref pc, msg) == "TEST1");
            pc.CurrentMessage = anotherMsg;
            Assert.IsTrue(pme.GetLeafFieldValueString(ref pc, msg) == "TEST1");
            Assert.IsTrue(pme.GetLeafFieldValueString(ref pc, null) == "TEST2");
        }