Наследование: IWriter
Пример #1
0
        public void GivenEnumeratedDlvWhenMapThenEnumeratatedMeterCreatorReturnsFactory()
        {
            const int ddivalue = 98282;
            var dlv = new DLV { A = ddivalue.ToString("x4") };
            _tim.Items = new List<DLV> { dlv }.ToArray();
            Map();

            _enumeratorMeterFactoryMock.Verify(x => x.GetMeterCreator(ddivalue), Times.Once);
        }
Пример #2
0
        public void GivenDlvWithDdiWhenMapThenCallsRepresentationMapper()
        {
            var dlv = new DLV { A = "7" };
            _tim.Items = new List<DLV> { dlv }.ToArray();

            MapSingle();

            _representationMapperMock.Verify(x => x.Map(7));
        }
Пример #3
0
 private NumericWorkingData MapNumericMeter(DLV dlv, int sectionId, int order)
 {
     var meter = new NumericWorkingData
     {
         UnitOfMeasure = _representationMapper.GetUnitForDdi(Convert.ToInt32(dlv.A, 16)),
         DeviceElementUseId = sectionId,
         Representation = _representationMapper.Map(Convert.ToInt32(dlv.A, 16))
     };
     meter.Id.UniqueIds.Add(_uniqueIdMapper.Map("DLV" + order));
     return meter;
 }
Пример #4
0
        public void GivenDlvWhenMapThenStoresOrderInMeterCompoundId()
        {
            var dlv1 = new DLV { A = "1" };
            var dlv2 = new DLV { A = "7" };
            _tim.Items = new List<DLV> { dlv1, dlv2 }.ToArray();

            var uniqueId1 = new UniqueId();
            _uniqueIdMapperMock.Setup(x => x.Map("DLV0")).Returns(uniqueId1);

            var uniqueId2 = new UniqueId();
            _uniqueIdMapperMock.Setup(x => x.Map("DLV1")).Returns(uniqueId2);

            var result = Map();

            Assert.Contains(uniqueId1, result[0].Id.UniqueIds);
            Assert.Contains(uniqueId2, result[1].Id.UniqueIds);
        }
Пример #5
0
 private IEnumerable<WorkingData> Map(DLV dlv, IEnumerable<ISOSpatialRow> isoSpatialRows, int sectionId, int order)
 {
     var meters = new List<WorkingData>();
     if (_ddis.ContainsKey(Convert.ToInt32(dlv.A, 16)))
     {
         meters.Add(MapNumericMeter(dlv, sectionId, order));
         return meters;
     }
     var meterCreator = _enumeratedMeterCreatorFactory.GetMeterCreator(Convert.ToInt32(dlv.A, 16));
     if(meterCreator != null)
     {
         var isoEnumeratedMeters = meterCreator.CreateMeters(isoSpatialRows);
         isoEnumeratedMeters.ForEach(x => x.Id.UniqueIds.Add(_uniqueIdMapper.Map("DLV" + order)));
         meters.AddRange(isoEnumeratedMeters);
     }
     return meters;
 }
Пример #6
0
        public void GivenEnumeratedDlvWhenMapThenEnumerateMeterHasId()
        {
            const int ddiValue = 131;
            var dlv = new DLV { A = ddiValue.ToString("x4") };
            _tim.Items = new List<DLV> { dlv }.ToArray();

            var expected = new ISOEnumeratedMeter { TriggerId = 8675309 };
            var meterCreator = new Mock<IEnumeratedMeterCreator>();
            meterCreator.Setup(m => m.CreateMeters(It.IsAny<IEnumerable<ISOSpatialRow>>())).Returns(new List<ISOEnumeratedMeter> {expected});

            _enumeratorMeterFactoryMock.Setup(m => m.GetMeterCreator(ddiValue)).Returns(meterCreator.Object);
            var uniqueId = new UniqueId();
            _uniqueIdMapperMock.Setup(x => x.Map("DLV0")).Returns(uniqueId);

            var result = MapSingle();

            Assert.AreSame(expected, result);
            Assert.Contains(uniqueId, result.Id.UniqueIds);
        }
Пример #7
0
        public DLV Map(WorkingData meter)
        {
            var representation = _representationMapper.Map(meter.Representation);

            var dlv = new DLV();
            if (representation == null)
            {
                dlv.A = null;
            }
            else
            {
                if (meter.Representation != null && meter.Representation.Code == "dtRecordingStatus" && meter.DeviceElementUseId != 0)
                    dlv.A = "161";
                else
                    dlv.A = representation.ToString();
            }

            return dlv;
        }
Пример #8
0
        public void GivenBinaryWhenReadThenResolutionIsApplied()
        {
            var dlv1 = new DLV { A = "0A" };
            var dlv2 = new DLV { A = "0B" };

            _tim.Items = new List<DLV> { dlv1, dlv2 }.ToArray();

            _numberOfDlvs = 2;
            _bytes.Add(_numberOfDlvs);

            const int value = 20000;

            _bytes.Add(0);
            _bytes.AddRange(BitConverter.GetBytes(value));
            _bytes.Add(1);
            _bytes.AddRange(BitConverter.GetBytes(value));

            var result = ReadSingle();

            Assert.AreEqual(_numberOfDlvs, result.SpatialValues.Count);
            Assert.AreEqual(20000, result.SpatialValues[0].Value);
            Assert.AreEqual(20, result.SpatialValues[1].Value);
        }
Пример #9
0
        public void GivenTimeHeaderWhenReadThenDlvsIsSet()
        {
            var dlv1 = new DLV {A = "6"};
            var dlv2 = new DLV {A = "7"};
            var dlv3 = new DLV {A = "8"};
            var dlv4 = new DLV {A = "9"};
            var dlv5 = new DLV {A = "10"};

            _tim.Items = new List<DLV> {dlv1, dlv2, dlv3, dlv4, dlv5}.ToArray();

            _numberOfDlvs = 5;
            _bytes.Add(_numberOfDlvs);

            var valueList = new List<int>();

            for (int i = 0; i < _numberOfDlvs; i++)
            {
                var order = (byte)i;
                var value = i + 123;

                valueList.Add(value);

                _bytes.Add(order);
                _bytes.AddRange(BitConverter.GetBytes(value));
            }

            var result = ReadSingle();

            Assert.AreEqual(_numberOfDlvs, result.SpatialValues.Count);
            for (int i = 0; i < _numberOfDlvs; i++)
            {
                Assert.AreEqual(valueList[i], result.SpatialValues[i].Value);
            }
        }
Пример #10
0
        public void GivenTimHeaderWithDlvWhenMapThenUnitOfMeasureIsMapped()
        {
            var dlv = new DLV {A = "1"};
            _tim.Items = new List<DLV> { dlv }.ToArray();

            _representationMapperMock.Setup(r => r.GetUnitForDdi(1)).Returns(UnitSystemManager.GetUnitOfMeasure("m"));

            var result = (NumericWorkingData)MapSingle();

            Assert.AreEqual("m", result.UnitOfMeasure.Code);
        }
Пример #11
0
        public void GivenTimeHeaderAndSectionIdWhenMapThenSectionIdSetOnMeter()
        {
            var dlv = new DLV { A = "1"};
            _tim.Items = new List<DLV> {dlv}.ToArray();

            var result = MapSingle(-45);

            Assert.AreEqual(-45, result.DeviceElementUseId);
        }
Пример #12
0
        public void GivenTimHeaderWhenWriteThenDlvHasAttributes()
        {
            var dlv = new DLV
            {
                A = "123",
                B = 456,
                C = "DLV-1",
                D = 2,
                E = new byte(),
                F = new byte()
            };

            var timHeader = new TIM
            {
                Items = new List<DLV> { dlv }.ToArray()
            };
            var xdoc = _xmlReader.WriteTlgXmlData(_dataPath, _fileName, timHeader);
            var actualDlv = xdoc.Element("TIM").Elements("DLV").First();

            var expected = "007B";
            Assert.AreEqual(expected, actualDlv.Attribute("A").Value);
            Assert.AreEqual(dlv.B.Value.ToString(), actualDlv.Attribute("B").Value);
            Assert.AreEqual(dlv.C, actualDlv.Attribute("C").Value);
            Assert.AreEqual(dlv.D.Value.ToString(), actualDlv.Attribute("D").Value);
            Assert.AreEqual(dlv.E.Value.ToString(), actualDlv.Attribute("E").Value);
            Assert.AreEqual(dlv.F.Value.ToString(), actualDlv.Attribute("F").Value);
        }
Пример #13
0
        public void GivenNullProcessDataValueWhenWriteThenAttributeIsNull()
        {
            var dlv = new DLV
            {
                A = "123",
                B = null,
                C = "DLV-1",
                D = 2,
                E = new byte(),
                F = new byte()
            };

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

            var xdoc = _xmlReader.WriteTlgXmlData(_dataPath, _fileName, tim);
            var expectedDlv = xdoc.Element("TIM").Elements("DLV").First();

            Assert.IsNull(expectedDlv.Attribute("B"));
        }