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); }
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); }
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); }
public void GivenEnumeratedDlvWhenMapThenEnumerateMeterIsMapped() { const int ddiValue = 131; var dlv = new DLV { A = ddiValue.ToString("x4") }; _tim.Items = new List <DLV> { dlv }.ToArray(); var expected = new ISOEnumeratedMeter { DeviceElementUseId = 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 result = MapSingle(); Assert.AreSame(expected, result); }
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); }
public void GivenDlvWithDdiWhenMapThenCallsRepresentationMapper() { var dlv = new DLV { A = "7" }; _tim.Items = new List <DLV> { dlv }.ToArray(); MapSingle(); _representationMapperMock.Verify(x => x.Map(7)); }
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); }
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); }
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); }
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); } }
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); }
public void GivenNullDataLogPGNWhenWriteThenDIsNull() { var dlv = new DLV { A = "123", B = null, C = "DLV-1", D = null, 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("D")); }
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); }