public void EdiWriter_WriteComposite() { //nonexisting map with just SLN segment to test composites M_001 map = new M_001(); EdiTrans t = new EdiTrans(map); var sDef = (MapSegment)map.Content.First(s => s.Name == "SLN"); var seg = new EdiSegment(sDef); //create composite var c001 = new EdiCompositeDataElement(sDef.Content[4], null); c001.Content.AddRange(new[] { new EdiSimpleDataElement(c001.Definition.Content[0], "PC"), new EdiSimpleDataElement(c001.Definition.Content[1], "21.1"), new EdiSimpleDataElement(c001.Definition.Content[2], "22.2"), new EdiSimpleDataElement(c001.Definition.Content[3], "EA"), new EdiSimpleDataElement(c001.Definition.Content[4], "23.3"), new EdiSimpleDataElement(c001.Definition.Content[5], "24.4") }); //create segment seg.Content.AddRange(new DataElementBase[] { new EdiSimpleDataElement(sDef.Content[0], "1.1"), new EdiSimpleDataElement(sDef.Content[1], null), new EdiSimpleDataElement(sDef.Content[2], "I"), new EdiSimpleDataElement(sDef.Content[3], "10000"), c001, new EdiSimpleDataElement(sDef.Content[5], "1.56"), new EdiSimpleDataElement(sDef.Content[6], "TP"), new EdiSimpleDataElement(sDef.Content[7], null), new EdiSimpleDataElement(sDef.Content[8], "VC"), new EdiSimpleDataElement(sDef.Content[9], "P-875OS") }); t.Content.Add(seg); string data = TestUtils.WriteEdiEnvelope(t, "ZZ"); EdiDataReader r = new EdiDataReader("EdiEngine.Tests"); EdiBatch b = r.FromString(data); EdiTrans t2 = b.Interchanges[0].Groups[0].Transactions[0]; //1 error - unknown map Assert.AreEqual(1, t2.ValidationErrors.Count); var sln = (EdiSegment)t.Content.First(); Assert.IsTrue(sln.Content[4] is EdiCompositeDataElement); Assert.AreEqual(6, ((EdiCompositeDataElement)sln.Content[4]).Content.Count); }
public void XmlReadWrite_DeserializeComposite() { string xml = TestUtils.ReadResourceStream("EdiEngine.Tests.TestData.001.Fake.Composite.xml"); M_001 map = new M_001(); XmlMapReader r = new XmlMapReader(map); EdiTrans t = r.ReadToEnd(xml); Assert.AreEqual(0, t.ValidationErrors.Count); var sln = (EdiSegment)t.Content.First(); Assert.IsTrue(sln.Content[4] is EdiCompositeDataElement); Assert.AreEqual(6, ((EdiCompositeDataElement)sln.Content[4]).Content.Count); }