예제 #1
0
        public void GettingEdifactTransactionSets()
        {
            string edi = new StringBuilder()
                         .AppendLine("UNA:+.? '")
                         .AppendLine("UNB+1'")
                         .AppendLine("UNH+2'")
                         .AppendLine("MSG'")
                         .AppendLine("IFT'")
                         .AppendLine("UNT'")
                         .AppendLine("UNZ'")
                         .AppendLine("UNB+3'")
                         .AppendLine("UNG+4'")
                         .AppendLine("UNH+5'")
                         .AppendLine("UNT'")
                         .AppendLine("UNE'")
                         .AppendLine("UNZ'")
                         .ToString();
            EdiDocument document = EdiDocument.Parse(edi);
            IList <EdiTransactionSet> transactionSets = document.TransactionSets;

            Assert.AreEqual(2, transactionSets.Count);

            Assert.AreEqual("1", transactionSets[0].InterchangeHeader[01]);
            Assert.IsNull(transactionSets[0].FunctionalGroupHeader);
            Assert.AreEqual(4, transactionSets[0].Segments.Count);
            Assert.AreEqual("2", transactionSets[0].Segments[0][01]);
            Assert.AreEqual("MSG", transactionSets[0].Segments[1].Id);
            Assert.AreEqual("IFT", transactionSets[0].Segments[2].Id);
            Assert.AreEqual("UNT", transactionSets[0].Segments[3].Id);

            Assert.AreEqual("3", transactionSets[1].InterchangeHeader[01]);
            Assert.AreEqual("4", transactionSets[1].FunctionalGroupHeader[01]);
            Assert.AreEqual(2, transactionSets[1].Segments.Count);
            Assert.AreEqual("5", transactionSets[1].Segments[0][01]);
            Assert.AreEqual("UNT", transactionSets[1].Segments[1].Id);
        }
예제 #2
0
        public void MappingAHierarchy()
        {
            EdiDocument edi = EdiDocument.Parse(new StringBuilder()
                                                .AppendLine("ST~")
                                                .AppendLine("HL***S~")
                                                .AppendLine("TD1~")
                                                .AppendLine("N1~")
                                                .AppendLine("N3~")
                                                .AppendLine("N4~")
                                                .AppendLine("N1~")
                                                .AppendLine("N1~")
                                                .AppendLine("HL***O~")
                                                .AppendLine("PRF~")
                                                .AppendLine("TD1~")
                                                .AppendLine("N1~")
                                                .AppendLine("HL***I~")
                                                .AppendLine("HL***I~")
                                                .AppendLine("HL***O~")
                                                .AppendLine("PRF~")
                                                .AppendLine("TD1~")
                                                .AppendLine("N1~")
                                                .AppendLine("HL***I~")
                                                .AppendLine("CTT~")
                                                .AppendLine("SE~")
                                                .ToString(),
                                                new EdiOptions
            {
                ElementSeparator    = '*',
                RepetitionSeparator = '^',
                ComponentSeparator  = '>'
            });
            EdiMapping mapping = EdiMapping.Parse(new StringBuilder()
                                                  .AppendLine("<mapping>")
                                                  .AppendLine("    <loop>")
                                                  .AppendLine("        <hl>")
                                                  .AppendLine("            <hl03 restrict=\"true\">")
                                                  .AppendLine("                <option>s</option>")
                                                  .AppendLine("            </hl03>")
                                                  .AppendLine("        </hl>")
                                                  .AppendLine("        <loop>")
                                                  .AppendLine("            <n1/>")
                                                  .AppendLine("        </loop>")
                                                  .AppendLine("    </loop>")
                                                  .AppendLine("    <loop>")
                                                  .AppendLine("        <hl>")
                                                  .AppendLine("            <hl03 restrict=\"true\">")
                                                  .AppendLine("                <option>o</option>")
                                                  .AppendLine("            </hl03>")
                                                  .AppendLine("        </hl>")
                                                  .AppendLine("        <td1/>")
                                                  .AppendLine("    </loop>")
                                                  .AppendLine("    <loop>")
                                                  .AppendLine("        <hl>")
                                                  .AppendLine("            <hl03 restrict=\"true\">")
                                                  .AppendLine("                <option>i</option>")
                                                  .AppendLine("            </hl03>")
                                                  .AppendLine("        </hl>")
                                                  .AppendLine("    </loop>")
                                                  .AppendLine("    <ctt/>")
                                                  .AppendLine("</mapping>")
                                                  .ToString());
            XDocument actual = mapping.Map(edi.Segments);

            XDocument expected = XDocument.Parse(new StringBuilder()
                                                 .AppendLine("<mapping>")
                                                 .AppendLine("    <ST/>")
                                                 .AppendLine("    <loop>")
                                                 .AppendLine("        <hl>")
                                                 .AppendLine("            <hl03>S</hl03>")
                                                 .AppendLine("        </hl>")
                                                 .AppendLine("        <TD1/>")
                                                 .AppendLine("        <loop>")
                                                 .AppendLine("            <n1/>")
                                                 .AppendLine("            <N3/>")
                                                 .AppendLine("            <N4/>")
                                                 .AppendLine("        </loop>")
                                                 .AppendLine("        <loop>")
                                                 .AppendLine("            <n1/>")
                                                 .AppendLine("        </loop>")
                                                 .AppendLine("        <loop>")
                                                 .AppendLine("            <n1/>")
                                                 .AppendLine("        </loop>")
                                                 .AppendLine("    </loop>")
                                                 .AppendLine("    <loop>")
                                                 .AppendLine("        <hl>")
                                                 .AppendLine("            <hl03>O</hl03>")
                                                 .AppendLine("        </hl>")
                                                 .AppendLine("        <PRF/>")
                                                 .AppendLine("        <td1/>")
                                                 .AppendLine("        <N1/>")
                                                 .AppendLine("    </loop>")
                                                 .AppendLine("    <loop>")
                                                 .AppendLine("        <hl>")
                                                 .AppendLine("            <hl03>I</hl03>")
                                                 .AppendLine("        </hl>")
                                                 .AppendLine("    </loop>")
                                                 .AppendLine("    <loop>")
                                                 .AppendLine("        <hl>")
                                                 .AppendLine("            <hl03>I</hl03>")
                                                 .AppendLine("        </hl>")
                                                 .AppendLine("    </loop>")
                                                 .AppendLine("    <loop>")
                                                 .AppendLine("        <hl>")
                                                 .AppendLine("            <hl03>O</hl03>")
                                                 .AppendLine("        </hl>")
                                                 .AppendLine("        <PRF/>")
                                                 .AppendLine("        <td1/>")
                                                 .AppendLine("        <N1/>")
                                                 .AppendLine("    </loop>")
                                                 .AppendLine("    <loop>")
                                                 .AppendLine("        <hl>")
                                                 .AppendLine("            <hl03>I</hl03>")
                                                 .AppendLine("        </hl>")
                                                 .AppendLine("    </loop>")
                                                 .AppendLine("    <ctt/>")
                                                 .AppendLine("    <SE/>")
                                                 .AppendLine("</mapping>")
                                                 .ToString());

            Assert.IsTrue(XNode.DeepEquals(expected, actual));
        }