Inheritance: IWriter
Example #1
8
        public void GivenXdocumentWhenReadThenDlvAndPtnsAreMapped()
        {
            _memStream = new MemoryStream();
            using (var xmlWriter = XmlWriter.Create(_memStream, new XmlWriterSettings { Encoding = new UTF8Encoding(false) }))
            {
                xmlWriter.WriteStartElement("TIM");
                xmlWriter.WriteStartElement("PTN");
                xmlWriter.WriteEndElement();
                xmlWriter.WriteStartElement("DLV");
                xmlWriter.WriteEndElement();
                xmlWriter.WriteStartElement("DLV");
                xmlWriter.WriteEndElement();
                xmlWriter.WriteStartElement("DLV");
                xmlWriter.WriteEndElement();
                xmlWriter.WriteEndElement();
                xmlWriter.Flush();
                xmlWriter.Close();
            }

            var xpathDoc = CreateXDoc();

            var ptn = new PTN();
            _ptnReaderMock.Setup(x => x.Read(It.IsAny<XPathNodeIterator>())).Returns(new List<PTN> { ptn });

            var dlvs = new List<DLV> { new DLV(), new DLV(), new DLV() };
            _dlvReaderMock.Setup(x => x.Read(It.Is<XPathNodeIterator>(y => y.Count == 3))).Returns(dlvs);

            var result = _timReader.Read(xpathDoc).First();
            Assert.AreSame(ptn, result.Items[0]);
            Assert.AreSame(dlvs[0], result.Items[1]);
            Assert.AreSame(dlvs[1], result.Items[2]);
            Assert.AreSame(dlvs[2], result.Items[3]);
        }
Example #2
0
        public void GivenMetersWhenMapThenPtnHeaderIsMapped()
        {
            var ptn = new PTN();
            _ptnHeaderMapperMock.Setup(x => x.Map()).Returns(ptn);

            var result = _timHeaderMapper.Map(_meters);
            var resultPtn = result.Items.First(x => x.GetType() == typeof (PTN));
            Assert.AreEqual(ptn, resultPtn);
        }
Example #3
0
        public void GivenXdocumentWhenReadThenPtnHeaderIsMapped()
        {
            _memStream = new MemoryStream();
            using (var xmlWriter = XmlWriter.Create(_memStream, new XmlWriterSettings { Encoding = new UTF8Encoding(false) }))
            {
                xmlWriter.WriteStartElement("TIM");
                xmlWriter.WriteStartElement("PTN");
                xmlWriter.WriteEndElement();
                xmlWriter.WriteEndElement();
                xmlWriter.Flush();
                xmlWriter.Close();
            }

            var xpathDoc = CreateXDoc();

            var ptn = new PTN();
            _ptnReaderMock.Setup(x => x.Read(It.IsAny<XPathNodeIterator>())).Returns(new List<PTN> {ptn});

            var result = _timReader.Read(xpathDoc).First();
            var ptnResult = result.Items[0];
            Assert.AreSame(ptn, ptnResult);
        }
Example #4
0
        public void Setup()
        {
            _numberOfDlvs = 0;
            _bytes = new List<byte>();
            _ptn = new PTN
            {
                A = 94.1234,
                ASpecified = true,
                B = 49.4321,
                BSpecified = true,
                C = 5,
                CSpecified = true,
                D = 1,
                DSpecified = true,
                E = 33,
                ESpecified = true,
                F = 44,
                FSpecified = true,
                G = 13,
                GSpecified = true,
                H = 123123213,
                HSpecified = true,
                I = 13213,
                ISpecified = true
            };
            _tim = new TIM
            {
                A = DateTime.Today,
                ASpecified = true,
                Items = new List<IWriter>
                {
                    _ptn,
                    new DLV
                    {
                        A = "0075",
                        B = 32,
                        C = "DEC-1",
                        D = null,
                        E = null,
                        F = null
                    }
                }.ToArray()
            };

            _binaryReader = new BinaryReader();
        }
Example #5
0
        public void GivenTimHeaderWithIsNullStateWhenWriteThenPtnDoesntAddAtributes()
        {
            var ptn = new PTN
            {
                ASpecified = false,
                A = null,

                BSpecified = false,
                B = null,

                CSpecified = false,
                C = null,

                DSpecified = false,
                D = null,

                ESpecified = false,
                E = null,

                FSpecified = false,
                F = null,

                GSpecified = false,
                G = null,

                HSpecified = false,
                H = null,

                ISpecified = false,
                I = null

            };
            var tim = new TIM
            {
                Items = new List<IWriter> { ptn }.ToArray()
            };

            var xdoc = _xmlReader.WriteTlgXmlData(_dataPath, _fileName, tim);
            var actualPtn = xdoc.Element("TIM").Element("PTN");

            Assert.IsNull(actualPtn.Attribute("A"));
            Assert.IsNull(actualPtn.Attribute("B"));
            Assert.IsNull(actualPtn.Attribute("C"));
            Assert.IsNull(actualPtn.Attribute("D"));
            Assert.IsNull(actualPtn.Attribute("E"));
            Assert.IsNull(actualPtn.Attribute("F"));
            Assert.IsNull(actualPtn.Attribute("G"));
            Assert.IsNull(actualPtn.Attribute("H"));
            Assert.IsNull(actualPtn.Attribute("I"));
        }
Example #6
0
        public void GivenTimHeaderWhenWriteThenPtnHasValues()
        {
            var ptn = new PTN
            {
                ASpecified = true,
                A = -123,

                BSpecified = true,
                B = 145,

                CSpecified = true,
                C = 123415,

                DSpecified = true,
                D = 7,

                ESpecified = true,
                E = 98.3,

                FSpecified = true,
                F = 33.2,

                GSpecified = true,
                G = 231,

                HSpecified = true,
                H = 21344,

                ISpecified = true,
                I = 231

            };
            var tim = new TIM
            {
                Items = new List<IWriter> { ptn }.ToArray()
            };

            var xdoc = _xmlReader.WriteTlgXmlData(_dataPath, _fileName, tim);
            var actualPtn = xdoc.Element("TIM").Element("PTN");

            Assert.AreEqual(ptn.A.Value.ToString(), actualPtn.Attribute("A").Value);
            Assert.AreEqual(ptn.B.Value.ToString(), actualPtn.Attribute("B").Value);
            Assert.AreEqual(ptn.C.Value.ToString(), actualPtn.Attribute("C").Value);
            Assert.AreEqual(ptn.D.Value.ToString(), actualPtn.Attribute("D").Value);
            Assert.AreEqual(ptn.E.Value.ToString(), actualPtn.Attribute("E").Value);
            Assert.AreEqual(ptn.F.Value.ToString(), actualPtn.Attribute("F").Value);
            Assert.AreEqual(ptn.G.Value.ToString(), actualPtn.Attribute("G").Value);
            Assert.AreEqual(ptn.H.Value.ToString(), actualPtn.Attribute("H").Value);
            Assert.AreEqual(ptn.I.Value.ToString(), actualPtn.Attribute("I").Value);
        }
Example #7
0
        private void SetGpsUtcDateTime(PTN ptn, ISOSpatialRow record, System.IO.BinaryReader binaryReader)
        {
            if (ptn.HSpecified)
            {
                if (ptn.H.HasValue)
                    record.GpsUtcTime = Convert.ToInt32(ptn.H.Value);
                else
                    record.GpsUtcTime = binaryReader.ReadInt32();
            }

            if (ptn.ISpecified)
            {
                if (ptn.I.HasValue)
                    record.GpsUtcDate = (short)ptn.I.Value;
                else
                    record.GpsUtcDate = binaryReader.ReadInt16();
            }

            if (record.GpsUtcDate != null && record.GpsUtcTime != null)
                record.GpsUtcDateTime = _firstDayOf1980.AddDays((double) record.GpsUtcDate).AddMilliseconds((double) record.GpsUtcTime);
        }