예제 #1
0
        public void TestSimpleCompositeParsers()
        {
            string configXml = @"/Resources/composites.xml";
            MessageFactory <IsoMessage> mfact = Config(configXml);
            IsoMessage m = mfact.ParseMessage("01000040000000000000016one  03two12345.".GetSbytes(), 0);

            Assert.NotNull(m);
            CompositeField f = (CompositeField)m.GetObjectValue(10);

            Assert.NotNull(f);
            Assert.Equal(4, f.Values.Count);
            Assert.Equal("one  ", f.GetObjectValue(0));
            Assert.Equal("two", f.GetObjectValue(1));
            Assert.Equal("12345", f.GetObjectValue(2));
            Assert.Equal(".", f.GetObjectValue(3));

            m = mfact.ParseMessage("01000040000000000000018ALPHA05LLVAR12345X".GetSbytes(), 0);
            Assert.NotNull(m);
            Assert.True(m.HasField(10));
            f = (CompositeField)m.GetObjectValue(10);
            Assert.NotNull(f.GetField(0));
            Assert.NotNull(f.GetField(1));
            Assert.NotNull(f.GetField(2));
            Assert.NotNull(f.GetField(3));
            Assert.Null(f.GetField(4));
            Assert.Equal("ALPHA", f.GetObjectValue(0));
            Assert.Equal("LLVAR", f.GetObjectValue(1));
            Assert.Equal("12345", f.GetObjectValue(2));
            Assert.Equal("X", f.GetObjectValue(3));
        }
예제 #2
0
        public void TestEmptyFields()
        {
            string configXml = @"/Resources/issue64.xml";
            MessageFactory <IsoMessage> mfact = Config(configXml);
            IsoMessage msg = mfact.NewMessage(0x200);

            Assert.Equal("", msg.GetObjectValue(3));
        }
예제 #3
0
        public void TestParsing()
        {
            IsoMessage m = mfact.ParseMessage("010060000000000000000001X0002FF".GetSignedbytes(), 0);

            Assert.NotNull(m);
            Assert.Equal("X", m.GetObjectValue(2));
            Assert.Equal(new sbyte[] { unchecked ((sbyte)0xff) }, (sbyte[])m.GetObjectValue(3));
            mfact.UseBinaryMessages = (true);
            m = mfact.ParseMessage(new byte[]
            {
                1, 0, (byte)0x60, 0, 0, 0, 0, 0, 0, 0,
                0, 2, (byte)'X', (byte)'X', 0, 1, (byte)0xff
            }.ToSignedBytes(), 0);
            Assert.NotNull(m);
            Assert.Equal("XX", m.GetObjectValue(2));
            Assert.Equal(new sbyte[] { unchecked ((sbyte)0xff) }, (sbyte[])m.GetObjectValue(3));
        }
예제 #4
0
        public void TestTemplating()
        {
            IsoMessage iso1 = mf.NewMessage(0x200);
            IsoMessage iso2 = mf.NewMessage(0x200);

            Assert.NotSame(iso1, iso2);
            Assert.Equal(iso1.GetObjectValue(3), iso2.GetObjectValue(3));
            Assert.NotSame(iso1.GetField(3), iso2.GetField(3));
            Assert.NotSame(iso1.GetField(48), iso2.GetField(48));
            CustomField48 cf48_1 = (CustomField48)iso1.GetObjectValue(48);
            int           origv  = cf48_1.V2;

            cf48_1.V2 = (origv + 1000);
            CustomField48 cf48_2 = (CustomField48)iso2.GetObjectValue(48);

            Assert.Same(cf48_1, cf48_2);
            Assert.Equal(cf48_2.V2, origv + 1000);
        }
예제 #5
0
        public void TestParseLengthWithRadix10()
        {
            // Given
            var input = "0100" +                              // MTI
                        "7000000000000000" +                  // bitmap
                        "10" + "ABCDEFGHIJ" +                 // F2 length (10 = 10) + value
                        "26" + "01234567890123456789012345" + // F3 length (26 = 26) + value
                        "ZZZZZZZZ";                           // F4

            // When
            IsoMessage m = mfact.ParseMessage(input.GetSignedBytes(), 0);

            // Then
            Assert.NotNull(m);
            Assert.Equal("ABCDEFGHIJ", m.GetObjectValue(2));
            Assert.Equal("01234567890123456789012345", HexCodec.HexEncode((sbyte[])m.GetObjectValue(3), 0, 13));
            Assert.Equal("ZZZZZZZZ", m.GetObjectValue(4));
        }
예제 #6
0
        private void CheckBin(sbyte[] txt,
                              sbyte[] bin,
                              int field)
        {
            IsoMessage t = txtfact.ParseMessage(txt, 0);
            IsoMessage b = binfact.ParseMessage(bin, 0);

            Assert.True(t.HasField(field));
            Assert.True(b.HasField(field));
            Assert.Empty(((sbyte[])t.GetObjectValue(field)));
            Assert.Empty(((sbyte[])b.GetObjectValue(field)));
        }
예제 #7
0
        private void CheckString(sbyte[] txt, sbyte[] bin, int field)
        {
            IsoMessage t = txtfact.ParseMessage(txt, 0);
            IsoMessage b = binfact.ParseMessage(bin, 0);

            Assert.True(t.HasField(field));
            Assert.True(b.HasField(field));
            string value  = (string)(t.GetObjectValue(field));
            string valueb = (string)(b.GetObjectValue(field));

            Assert.True(value.IsEmpty());
            Assert.True(valueb.IsEmpty());
        }
예제 #8
0
        public void TestSimpleFieldSetter()
        {
            IsoMessage iso = mf.NewMessage(0x200);
            IsoValue   f3  = iso.GetField(3);

            iso.UpdateValue(3, "999999");
            Assert.Equal("999999", iso.GetObjectValue(3));
            IsoValue nf3 = iso.GetField(3);

            Assert.NotSame(f3, nf3);
            Assert.Equal(f3.Type, nf3.Type);
            Assert.Equal(f3.Length, nf3.Length);
            Assert.Same(f3.Encoder, nf3.Encoder);
            Assert.Throws <ArgumentException>(() => iso.UpdateValue(4, "INVALID!"))
            ;
        }
예제 #9
0
        public void TestL4bin()
        {
            sbyte[] fieldData = new sbyte[1000];
            mfact.UseBinaryMessages = true;
            IsoMessage m = mfact.NewMessage(0x100);

            m.SetValue(3, fieldData, IsoType.LLLLBIN, 0);
            fieldData = m.WriteData();
            //2 for message header
            //8 bitmap
            //3 for field 2 (from template)
            //1002 for field 3
            Assert.Equal(1015, fieldData.Length);
            m = mfact.ParseMessage(fieldData, 0);
            Assert.True(m.HasField(3));
            fieldData = m.GetObjectValue(3) as sbyte[];
            Assert.Equal(1000, fieldData.Length);
        }
예제 #10
0
        public void PrintMessage(IsoMessage m)
        {
            Transaction transObj = new Transaction();

            if (m == null)
            {
                transObj.WriteLog("Mensaje nulo!");
                return;
            }
            transObj.WriteLog("TYPE: " + m.Type.ToString("x"));
            for (int i = 2; i < 128; i++)
            {
                if (m.HasField(i))
                {
                    transObj.WriteLog("F " + i.ToString() + ": " + m.GetObjectValue(i) + " -> '" + m.GetField(i).ToString() + "'");
                }
            }
        }
예제 #11
0
        public void TestSimpleCompositeTemplate()
        {
            string configXml = @"/Resources/composites.xml";
            MessageFactory <IsoMessage> mfact = Config(configXml);
            IsoMessage m = mfact.NewMessage(0x100);

            //Simple composite
            Assert.NotNull(m);
            Assert.False(m.HasField(1));
            Assert.False(m.HasField(2));
            Assert.False(m.HasField(3));
            Assert.False(m.HasField(4));
            CompositeField f = (CompositeField)m.GetObjectValue(10);

            Assert.NotNull(f);
            Assert.Equal(f.GetObjectValue(0), "abcde");
            Assert.Equal(f.GetObjectValue(1), "llvar");
            Assert.Equal(f.GetObjectValue(2), "12345");
            Assert.Equal(f.GetObjectValue(3), "X");
            Assert.False(m.HasField(4));
        }
예제 #12
0
        private void NestedCompositeTemplate(int type, int fnum)
        {
            string configXml = @"/Resources/composites.xml";
            MessageFactory <IsoMessage> mfact = Config(configXml);
            IsoMessage m = mfact.NewMessage(type);

            Assert.NotNull(m);
            Assert.False(m.HasField(1));
            Assert.False(m.HasField(2));
            Assert.False(m.HasField(3));
            Assert.False(m.HasField(4));
            CompositeField f = (CompositeField)m.GetObjectValue(fnum);

            Assert.Equal(f.GetObjectValue(0), "fghij");
            Assert.Equal(f.GetObjectValue(2), "67890");
            Assert.Equal(f.GetObjectValue(3), "Y");
            f = (CompositeField)f.GetObjectValue(1);
            Assert.Equal(f.GetObjectValue(0), "KL");
            Assert.Equal(f.GetObjectValue(1), "mn");
            f = (CompositeField)f.GetObjectValue(2);
            Assert.Equal(f.GetObjectValue(0), "123");
            Assert.Equal(f.GetObjectValue(1), "45");
        }
예제 #13
0
        public void TestNestedCompositeParser()
        {
            string configXml = @"/Resources/composites.xml";
            MessageFactory <IsoMessage> mfact = Config(configXml);
            IsoMessage m = mfact.ParseMessage("01010040000000000000019ALPHA11F1F205F03F4X".GetSbytes(), 0);

            Assert.NotNull(m);
            Assert.True(m.HasField(10));
            CompositeField f = (CompositeField)m.GetObjectValue(10);

            Assert.NotNull(f.GetField(0));
            Assert.NotNull(f.GetField(1));
            Assert.NotNull(f.GetField(2));
            Assert.Null(f.GetField(3));
            Assert.Equal("ALPHA", f.GetObjectValue(0));
            Assert.Equal("X", f.GetObjectValue(2));
            f = (CompositeField)f.GetObjectValue(1);
            Assert.Equal("F1", f.GetObjectValue(0));
            Assert.Equal("F2", f.GetObjectValue(1));
            f = (CompositeField)f.GetObjectValue(2);
            Assert.Equal("F03", f.GetObjectValue(0));
            Assert.Equal("F4", f.GetObjectValue(1));
        }
예제 #14
0
        public void TestMessages()
        {
            //Create a message with both factories
            var ascii = _mfactAscii.NewMessage(0x600);
            var bin   = _mfactBin.NewMessage(0x600);

            Assert.False(ascii.Binary || ascii.BinBitmap);
            Assert.True(bin.Binary);
            //HEXencode the binary message, headers should be similar to the ASCII version
            sbyte[] v        = bin.WriteData();
            var     hexBin   = HexCodec.HexEncode(v, 0, v.Length);
            var     hexAscii = ascii.WriteData().SbyteString(Encoding.Default).ToUpper(CultureInfo.CurrentCulture);

            Assert.Equal("0600", hexBin.Substring(0, 4));

            //Should be the same up to the field 42 (first 80 chars)
            Assert.Equal(hexAscii.Substring(0, 88), hexBin.Substring(0, 88));
            Assert.Equal(ascii.GetObjectValue(43), v.SbyteString(44, 40, Encoding.Default).Trim());
            //Parse both messages
            sbyte[]    asciiBuf = ascii.WriteData();
            IsoMessage ascii2   = _mfactAscii.ParseMessage(asciiBuf, 0);

            TestParsed(ascii2);
            Assert.Equal(ascii.GetObjectValue(7).ToString(), ascii2.GetObjectValue(7).ToString());
            IsoMessage bin2 = _mfactBin.ParseMessage(bin.WriteData(), 0);

            //Compare values, should be the same
            TestParsed(bin2);
            Assert.Equal(bin.GetObjectValue(7).ToString(), bin2.GetObjectValue(7).ToString());

            //Test the debug string
            ascii.SetValue(60, "XXX", IsoType.LLVAR, 0);
            bin.SetValue(60, "XXX", IsoType.LLVAR, 0);
            Assert.Equal(ascii.DebugString(), bin.DebugString()); // "Debug strings differ"
            Assert.True(ascii.DebugString().Contains("03XXX"), "LLVAR fields wrong");
        }
예제 #15
0
        public void TestMultilevelExtendParseGuides()
        {
            string configXml = @"/Resources/issue34.xml";
            MessageFactory <IsoMessage> mfact = Config(configXml);

            //Parse a 200
            string m200 = "0200422000000880800001X1231235959123456101010202020TERMINAL484";
            string m210 = "0210422000000A80800001X123123595912345610101020202099TERMINAL484";
            string m400 = "0400422000000880800401X1231235959123456101010202020TERMINAL484001X";
            string m410 = "0410422000000a80800801X123123595912345610101020202099TERMINAL484001X";

            IsoMessage m = mfact.ParseMessage(m200.GetSbytes(), 0);

            Assert.NotNull(m);
            Assert.Equal("X", m.GetObjectValue(2));
            Assert.Equal("123456", m.GetObjectValue(11));
            Assert.Equal("TERMINAL", m.GetObjectValue(41));
            Assert.Equal("484", m.GetObjectValue(49));
            m = mfact.ParseMessage(m210.GetSbytes(), 0);
            Assert.NotNull(m);
            Assert.Equal("X", m.GetObjectValue(2));
            Assert.Equal("123456", m.GetObjectValue(11));
            Assert.Equal("TERMINAL", m.GetObjectValue(41));
            Assert.Equal("484", m.GetObjectValue(49));
            Assert.Equal("99", m.GetObjectValue(39));
            m = mfact.ParseMessage(m400.GetSbytes(), 0);
            Assert.NotNull(m);
            Assert.Equal("X", m.GetObjectValue(2));
            Assert.Equal("123456", m.GetObjectValue(11));
            Assert.Equal("TERMINAL", m.GetObjectValue(41));
            Assert.Equal("484", m.GetObjectValue(49));
            Assert.Equal("X", m.GetObjectValue(62));
            m = mfact.ParseMessage(m410.GetSbytes(), 0);
            Assert.NotNull(m);
            Assert.Equal("X", m.GetObjectValue(2));
            Assert.Equal("123456", m.GetObjectValue(11));
            Assert.Equal("TERMINAL", m.GetObjectValue(41));
            Assert.Equal("484", m.GetObjectValue(49));
            Assert.Equal("99", m.GetObjectValue(39));
            Assert.Equal("X", m.GetObjectValue(61));
        }
예제 #16
0
        private void TestParsed(IsoMessage m)
        {
            Assert.Equal(m.Type,
                         0x600);
            Assert.Equal(decimal.Parse("1234.00"),
                         m.GetObjectValue(4));
            Assert.True(m.HasField(7),
                        "No field 7!");
            Assert.Equal("000123",
                         m.GetField(11).ToString()); // Wrong Trace
            var buf = (sbyte[])m.GetObjectValue(41);

            sbyte[] exp =
            {
                unchecked ((sbyte)0xab),
                unchecked ((sbyte)0xcd),
                unchecked ((sbyte)0xef),
                0,
                0,
                0,
                0,
                0
            };
            Assert.Equal(8,
                         buf.Length); //Field 41 wrong length

            Assert.Equal(exp,
                         buf); //"Field 41 wrong value"

            buf = (sbyte[])m.GetObjectValue(42);
            exp = new sbyte[]
            {
                0x0a,
                unchecked ((sbyte)0xbc),
                unchecked ((sbyte)0xde),
                0
            };
            Assert.Equal(4,
                         buf.Length); // "field 42 wrong length"
            Assert.Equal(exp,
                         buf);        // "Field 42 wrong value"
            Assert.True(((string)m.GetObjectValue(43)).StartsWith("Field of length 40",
                                                                  StringComparison.Ordinal));

            buf = (sbyte[])m.GetObjectValue(62);
            exp = new sbyte[]
            {
                1,
                0x23,
                0x45,
                0x67,
                unchecked ((sbyte)0x89),
                unchecked ((sbyte)0xab),
                unchecked ((sbyte)0xcd),
                unchecked ((sbyte)0xef),
                0x62,
                1,
                0x23,
                0x45,
                0x67,
                unchecked ((sbyte)0x89),
                unchecked ((sbyte)0xab),
                unchecked ((sbyte)0xcd)
            };
            Assert.Equal(exp,
                         buf);
            buf    = (sbyte[])m.GetObjectValue(64);
            exp[8] = 0x64;
            Assert.Equal(exp,
                         buf);
            buf = (sbyte[])m.GetObjectValue(63);
            exp = new sbyte[]
            {
                0,
                0x12,
                0x34,
                0x56,
                0x78,
                0x63
            };
            Assert.Equal(exp,
                         buf);
            buf    = (sbyte[])m.GetObjectValue(65);
            exp[5] = 0x65;
            Assert.Equal(exp,
                         buf);
        }
예제 #17
0
        private void TestFieldType(IsoType type,
                                   FieldParseInfo fieldParser,
                                   int offset1,
                                   int offset2)
        {
            var bigintCodec = new BigIntBcdCodec();
            var longCodec   = new LongBcdCodec();
            var mfact       = new MessageFactory <IsoMessage>();
            var tmpl        = new IsoMessage
            {
                Binary = true,
                Type   = 0x200
            };

            tmpl.SetValue(2,
                          1234567890L,
                          longCodec,
                          type,
                          0);
            tmpl.SetValue(3,
                          b29,
                          bigintCodec,
                          type,
                          0);
            mfact.AddMessageTemplate(tmpl);
            mfact.SetCustomField(2,
                                 longCodec);
            mfact.SetCustomField(3,
                                 bigintCodec);
            var parser = new Dictionary <int, FieldParseInfo>
            {
                { 2, fieldParser },
                { 3, fieldParser }
            };

            mfact.SetParseMap(0x200,
                              parser);
            mfact.UseBinaryMessages = true;

            //Test encoding
            tmpl = mfact.NewMessage(0x200);
            var buf     = tmpl.WriteData();
            var message = HexCodec.HexEncode(buf,
                                             0,
                                             buf.Length);

            Console.WriteLine("MESSAGE: " + message);
            for (var i = 0; i < 5; i++)
            {
                var b = longData2[i];
                Assert.Equal(b,
                             buf[i + offset1]);
            }

            for (var i = 0; i < 15; i++)
            {
                Assert.Equal(bigintData1[i],
                             buf[i + offset2]);
            }

            //Test parsing
            tmpl = mfact.ParseMessage(buf,
                                      0);
            Assert.Equal(1234567890L,
                         tmpl.GetObjectValue(2));
            Assert.Equal(b29,
                         tmpl.GetObjectValue(3));
        }