public void InstantiationAndProperties() { BinaryConstantExpression bce = new BinaryConstantExpression(); Assert.IsTrue(bce.Constant == null); Assert.IsTrue(bce.GetValue() == null); bce = new BinaryConstantExpression("303020"); Assert.IsTrue(bce.Constant == "303020"); Assert.IsTrue(MessagesProvider.CompareByteArrays(bce.GetValue(), new byte[] { 0x30, 0x30, 0x20 })); bce.Constant = null; Assert.IsTrue(bce.Constant == null); Assert.IsTrue(bce.GetValue() == null); bce.Constant = "203020"; Assert.IsTrue(bce.Constant == "203020"); Assert.IsTrue(MessagesProvider.CompareByteArrays(bce.GetValue(), new byte[] { 0x20, 0x30, 0x20 })); bce.Constant = "2030A"; Assert.IsTrue(bce.Constant == "2030A"); Assert.IsTrue(MessagesProvider.CompareByteArrays(bce.GetValue(), new byte[] { 0x20, 0x30, 0xA0 })); }
public void Evaluate() { ParserContext pc = new ParserContext(ParserContext.DefaultBufferSize); FormatterContext fc = new FormatterContext(FormatterContext.DefaultBufferSize); IsSetExpression ee = new IsSetExpression(new MessageExpression(3)); // Passing null message (as parameter and in the contexts). try { ee.EvaluateParse(ref pc); Assert.Fail(); } catch (ExpressionEvaluationException) { } try { ee.EvaluateFormat(new StringField(3, "000000"), ref fc); Assert.Fail(); } catch (ExpressionEvaluationException) { } // Evaluate. Message msg = MessagesProvider.GetMessage(); pc.CurrentMessage = msg; Assert.IsTrue(ee.EvaluateParse(ref pc)); fc.CurrentMessage = msg; Assert.IsTrue(ee.EvaluateFormat(new StringField(3, "000000"), ref fc)); ee = new IsSetExpression(new MessageExpression(4)); Assert.IsFalse(ee.EvaluateParse(ref pc)); Assert.IsFalse(ee.EvaluateFormat(new StringField(3, "000000"), ref fc)); }
public void GetLeafMessage() { MessageExpression me = new MessageExpression(); ParserContext pc = new ParserContext(ParserContext.DefaultBufferSize); FormatterContext fc = new FormatterContext(FormatterContext.DefaultBufferSize); // Passing null message (as parameter and in the contexts). try { me.GetLeafMessage(ref fc, null); Assert.Fail(); } catch (ExpressionEvaluationException) { } try { me.GetLeafMessage(ref pc, null); Assert.Fail(); } catch (ExpressionEvaluationException) { } Message msg = MessagesProvider.GetMessage(); Message anotherMsg = MessagesProvider.GetAnotherMessage(); Assert.IsTrue(me.GetLeafMessage(ref fc, msg) == msg); fc.CurrentMessage = anotherMsg; Assert.IsTrue(me.GetLeafMessage(ref fc, msg) == msg); Assert.IsTrue(me.GetLeafMessage(ref fc, null) == anotherMsg); Assert.IsTrue(me.GetLeafMessage(ref pc, msg) == msg); pc.CurrentMessage = anotherMsg; Assert.IsTrue(me.GetLeafMessage(ref pc, msg) == msg); Assert.IsTrue(me.GetLeafMessage(ref pc, null) == anotherMsg); }
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 Evaluate() { ParserContext pc = new ParserContext(ParserContext.DefaultBufferSize); FormatterContext fc = new FormatterContext(FormatterContext.DefaultBufferSize); MtiEqualsExpression ee = new MtiEqualsExpression(200, new MessageExpression()); // Passing null message (as parameter and in the contexts). try { ee.EvaluateParse(ref pc); Assert.Fail(); } catch (ExpressionEvaluationException) { } try { ee.EvaluateFormat(new StringField(3, "000000"), ref fc); Assert.Fail(); } catch (ExpressionEvaluationException) { } // Evaluate with incorrect message type. Message msg = MessagesProvider.GetMessage(); pc.CurrentMessage = msg; try { ee.EvaluateParse(ref pc); Assert.Fail(); } catch (ExpressionEvaluationException) { } fc.CurrentMessage = msg; try { ee.EvaluateFormat(new StringField(3, "000000"), ref fc); Assert.Fail(); } catch (ExpressionEvaluationException) { } // Evaluate against an ISO 8583 message. Iso8583Message isoMsg = MessagesProvider.GetIso8583Message(); pc.CurrentMessage = isoMsg; Assert.IsTrue(ee.EvaluateParse(ref pc)); fc.CurrentMessage = isoMsg; Assert.IsTrue(ee.EvaluateFormat(new StringField(3, "000000"), ref fc)); isoMsg = MessagesProvider.GetAnotherIso8583Message(); pc.CurrentMessage = isoMsg; Assert.IsFalse(ee.EvaluateParse(ref pc)); fc.CurrentMessage = isoMsg; Assert.IsFalse(ee.EvaluateFormat(new StringField(3, "000000"), ref fc)); }
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 })); }
public void Evaluate() { ParserContext pc = new ParserContext(ParserContext.DefaultBufferSize); FormatterContext fc = new FormatterContext(FormatterContext.DefaultBufferSize); FieldValueEqualsBinaryOperator ee = new FieldValueEqualsBinaryOperator( new MessageExpression(1), new BinaryConstantExpression(null)); Message msg = new Message(); msg.Fields.Add(new BinaryField(1, null)); // Both values are null. pc.CurrentMessage = msg; Assert.IsTrue(ee.EvaluateParse(ref pc)); fc.CurrentMessage = msg; Assert.IsTrue(ee.EvaluateFormat(new StringField(3, "000000"), ref fc)); ee = new FieldValueEqualsBinaryOperator( new MessageExpression(1), new BinaryConstantExpression("1520253035404550")); // Field value is null. Assert.IsFalse(ee.EvaluateParse(ref pc)); Assert.IsFalse(ee.EvaluateFormat(new StringField(3, "000000"), ref fc)); ee = new FieldValueEqualsBinaryOperator( new MessageExpression(52), new BinaryConstantExpression(null)); msg = MessagesProvider.GetMessage(); // Constant is null. pc.CurrentMessage = msg; Assert.IsFalse(ee.EvaluateParse(ref pc)); fc.CurrentMessage = msg; Assert.IsFalse(ee.EvaluateFormat(new StringField(3, "000000"), ref fc)); ee = new FieldValueEqualsBinaryOperator( new MessageExpression(52), new BinaryConstantExpression("152025303540")); // Different lengths. Assert.IsFalse(ee.EvaluateParse(ref pc)); Assert.IsFalse(ee.EvaluateFormat(new StringField(3, "000000"), ref fc)); ee = new FieldValueEqualsBinaryOperator( new MessageExpression(52), new BinaryConstantExpression("1520253035404551")); // Different data. Assert.IsFalse(ee.EvaluateParse(ref pc)); Assert.IsFalse(ee.EvaluateFormat(new StringField(3, "000000"), ref fc)); ee = new FieldValueEqualsBinaryOperator( new MessageExpression(52), new BinaryConstantExpression("1520253035404550")); // Equals. Assert.IsTrue(ee.EvaluateParse(ref pc)); Assert.IsTrue(ee.EvaluateFormat(new StringField(3, "000000"), ref fc)); }
public void GetLeafMessage() { Message msg = MessagesProvider.GetMessage(); ParserContext pc = new ParserContext(ParserContext.DefaultBufferSize); FormatterContext fc = new FormatterContext(FormatterContext.DefaultBufferSize); ParentMessageExpression pme = new ParentMessageExpression( new MessageExpression()); // Parent of a message without one. try { pme.GetLeafMessage(ref fc, msg); Assert.Fail(); } catch (ExpressionEvaluationException) { } // Passing null message (as parameter and in the contexts). try { pme.GetLeafMessage(ref fc, null); Assert.Fail(); } catch (ExpressionEvaluationException) { } try { pme.GetLeafMessage(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.GetLeafMessage(ref fc, msg)[41].Value as string) == "TEST1"); fc.CurrentMessage = anotherMsg; Assert.IsTrue((pme.GetLeafMessage(ref fc, msg)[41].Value as string) == "TEST1"); Assert.IsTrue((pme.GetLeafMessage(ref fc, null)[41].Value as string) == "TEST2"); Assert.IsTrue((pme.GetLeafMessage(ref pc, msg)[41].Value as string) == "TEST1"); pc.CurrentMessage = anotherMsg; Assert.IsTrue((pme.GetLeafMessage(ref pc, msg)[41].Value as string) == "TEST1"); Assert.IsTrue((pme.GetLeafMessage(ref pc, null)[41].Value as string) == "TEST2"); }
public void Evaluate() { ParserContext pc = new ParserContext(ParserContext.DefaultBufferSize); FormatterContext fc = new FormatterContext(FormatterContext.DefaultBufferSize); MidEqualsBinaryOperator ee = new MidEqualsBinaryOperator( new MessageExpression(1), new BinaryConstantExpression(null), 0, 1); Message msg = new Message(); msg.Fields.Add(new BinaryField(1, null)); // Both values are null. pc.CurrentMessage = msg; Assert.IsTrue(ee.EvaluateParse(ref pc)); fc.CurrentMessage = msg; Assert.IsTrue(ee.EvaluateFormat(new StringField(3, "000000"), ref fc)); ee = new MidEqualsBinaryOperator( new MessageExpression(1), new BinaryConstantExpression("1520253035404550"), 0, 1); // Field value is null. Assert.IsFalse(ee.EvaluateParse(ref pc)); Assert.IsFalse(ee.EvaluateFormat(new StringField(3, "000000"), ref fc)); ee = new MidEqualsBinaryOperator( new MessageExpression(52), new BinaryConstantExpression(null), 0, 1); msg = MessagesProvider.GetMessage(); // Constant is null. pc.CurrentMessage = msg; Assert.IsFalse(ee.EvaluateParse(ref pc)); fc.CurrentMessage = msg; Assert.IsFalse(ee.EvaluateFormat(new StringField(3, "000000"), ref fc)); ee = new MidEqualsBinaryOperator( new MessageExpression(52), new BinaryConstantExpression("152025303540"), 0, 1); // Different lengths. Assert.IsFalse(ee.EvaluateParse(ref pc)); Assert.IsFalse(ee.EvaluateFormat(new StringField(3, "000000"), ref fc)); ee = new MidEqualsBinaryOperator( new MessageExpression(52), new BinaryConstantExpression("1520253035404551"), 0, 1); // Different data. Assert.IsFalse(ee.EvaluateParse(ref pc)); Assert.IsFalse(ee.EvaluateFormat(new StringField(3, "000000"), ref fc)); ee = new MidEqualsBinaryOperator( new MessageExpression(52), new BinaryConstantExpression("1520253035"), 0, 5); // Equals. Assert.IsTrue(ee.EvaluateParse(ref pc)); Assert.IsTrue(ee.EvaluateFormat(new StringField(3, "000000"), ref fc)); // The start index of the set of bytes is greater than the field value length ee = new MidEqualsBinaryOperator( new MessageExpression(52), new BinaryConstantExpression("1520253035"), 8, 5); try { Assert.IsTrue(ee.EvaluateParse(ref pc)); Assert.Fail(); } catch (ExpressionEvaluationException) { } try { Assert.IsTrue(ee.EvaluateFormat(new StringField(3, "000000"), ref fc)); Assert.Fail(); } catch (ExpressionEvaluationException) { } // There isn't enough data in the field value to get a subset of bytes ee = new MidEqualsBinaryOperator( new MessageExpression(52), new BinaryConstantExpression("1520253035"), 6, 5); try { Assert.IsTrue(ee.EvaluateParse(ref pc)); Assert.Fail(); } catch (ExpressionEvaluationException) { } try { Assert.IsTrue(ee.EvaluateFormat(new StringField(3, "000000"), ref fc)); Assert.Fail(); } catch (ExpressionEvaluationException) { } }