public void GetLeafFieldValueBytes() { Message msg = MessagesProvider.GetMessage(); ParserContext pc = new ParserContext(ParserContext.DefaultBufferSize); FormatterContext fc = new FormatterContext(FormatterContext.DefaultBufferSize); SubMessageExpression sme = new SubMessageExpression(24, null); // Sub field of a field isn't an inner message. try { sme.GetLeafFieldValueString(ref fc, msg); Assert.Fail(); } catch (ExpressionEvaluationException) { } sme = new SubMessageExpression(61, null); msg.Fields.Add(new InnerMessageField(61)); try { sme.GetLeafFieldValueString(ref fc, msg); Assert.Fail(); } catch (ExpressionEvaluationException) { } sme = new SubMessageExpression(62, new MessageExpression(7)); // Passing null message (as parameter and in the contexts). try { sme.GetLeafFieldValueBytes(ref fc, null); Assert.Fail(); } catch (ExpressionEvaluationException) { } try { sme.GetLeafFieldValueBytes(ref pc, null); Assert.Fail(); } catch (ExpressionEvaluationException) { } msg = MessagesProvider.GetMessage(); Message anotherMsg = MessagesProvider.GetAnotherMessage(); Assert.IsTrue(MessagesProvider.CompareByteArrays(sme.GetLeafFieldValueBytes(ref fc, msg), new byte[] { 0x75, 0xB0, 0xB5 })); fc.CurrentMessage = anotherMsg; Assert.IsTrue(MessagesProvider.CompareByteArrays(sme.GetLeafFieldValueBytes(ref fc, msg), new byte[] { 0x75, 0xB0, 0xB5 })); Assert.IsTrue(MessagesProvider.CompareByteArrays(sme.GetLeafFieldValueBytes(ref fc, null), new byte[] { 0x95, 0xA0, 0xA5 })); Assert.IsTrue(MessagesProvider.CompareByteArrays(sme.GetLeafFieldValueBytes(ref pc, msg), new byte[] { 0x75, 0xB0, 0xB5 })); pc.CurrentMessage = anotherMsg; Assert.IsTrue(MessagesProvider.CompareByteArrays(sme.GetLeafFieldValueBytes(ref pc, msg), new byte[] { 0x75, 0xB0, 0xB5 })); Assert.IsTrue(MessagesProvider.CompareByteArrays(sme.GetLeafFieldValueBytes(ref pc, null), new byte[] { 0x95, 0xA0, 0xA5 })); }
public void GetLeafMessage() { Message msg = MessagesProvider.GetMessage(); ParserContext pc = new ParserContext(ParserContext.DefaultBufferSize); FormatterContext fc = new FormatterContext(FormatterContext.DefaultBufferSize); SubMessageExpression sme = new SubMessageExpression(24, null); // Sub field of a field isn't an inner message. try { sme.GetLeafMessage(ref fc, msg); Assert.Fail(); } catch (ExpressionEvaluationException) { } sme = new SubMessageExpression(61, null); msg.Fields.Add(new InnerMessageField(61)); try { sme.GetLeafMessage(ref fc, msg); Assert.Fail(); } catch (ExpressionEvaluationException) { } sme = new SubMessageExpression(61, new MessageExpression()); // Passing null message (as parameter and in the contexts). try { sme.GetLeafMessage(ref fc, null); Assert.Fail(); } catch (ExpressionEvaluationException) { } try { sme.GetLeafMessage(ref pc, null); Assert.Fail(); } catch (ExpressionEvaluationException) { } msg = MessagesProvider.GetMessage(); Message anotherMsg = MessagesProvider.GetAnotherMessage(); Assert.IsTrue((sme.GetLeafMessage(ref fc, msg)[6].Value as string) == "123"); fc.CurrentMessage = anotherMsg; Assert.IsTrue((sme.GetLeafMessage(ref fc, msg)[6].Value as string) == "123"); Assert.IsTrue((sme.GetLeafMessage(ref fc, null)[6].Value as string) == "456"); Assert.IsTrue((sme.GetLeafMessage(ref pc, msg)[6].Value as string) == "123"); pc.CurrentMessage = anotherMsg; Assert.IsTrue((sme.GetLeafMessage(ref pc, msg)[6].Value as string) == "123"); Assert.IsTrue((sme.GetLeafMessage(ref pc, null)[6].Value as string) == "456"); }
public void GetLeafFieldNumber() { MessageExpression me = new MessageExpression(4); SubMessageExpression sme = new SubMessageExpression(5, me); Assert.IsTrue(sme.GetLeafFieldNumber() == 4); me = new MessageExpression(11); sme.MessageExpression = me; Assert.IsTrue(sme.GetLeafFieldNumber() == 11); me.FieldNumber = 5; Assert.IsTrue(sme.GetLeafFieldNumber() == 5); }
public void InstantiationAndProperties() { SubMessageExpression sme = new SubMessageExpression(); Assert.IsTrue(sme.FieldNumber == -1); Assert.IsNull(sme.MessageExpression); MessageExpression me1 = new MessageExpression(); sme = new SubMessageExpression(5, me1); Assert.IsTrue(sme.FieldNumber == 5); Assert.IsTrue(sme.MessageExpression == me1); sme.FieldNumber = 9; Assert.IsTrue(sme.FieldNumber == 9); MessageExpression me2 = new MessageExpression(); sme.MessageExpression = me2; Assert.IsTrue(sme.MessageExpression == me2); }