[TestCase(new byte[] { 0 }, 1, new byte[] { 0 })] // This can be written in total. public void Check_If_Limit_Is_Respected_When_Writing(byte[] value, byte targetLength, byte[] targetData) { // Arrange var limit = (uint)2; var numericItem = new BytePlcItem(0, 0); Func <string, IPlcItem <byte[]> > flexiblePlcItemFactory = name => new BytesPlcItem(0, 1, true, new byte[0], name); var dynamicPlcItem = new DynamicPlcItem <byte[]>(numericItem, flexiblePlcItemFactory, 1, limit); // Act dynamicPlcItem.FlexiblePlcItem.Value = value; // Assert Assert.That(numericItem.Value, Is.EqualTo(targetLength)); Assert.True(targetData.SequenceEqual(dynamicPlcItem.FlexiblePlcItem.Value)); }
public void Check_If_Factor_Is_Applied_When_Writing(byte[] value) { // Arrange var factor = (byte)2; var targetLength = value.Length / factor; var numericItem = new UInt16PlcItem(0, 0); Func <string, IPlcItem <byte[]> > flexiblePlcItemFactory = name => new BytesPlcItem(0, 1, true, new byte[0], name); var dynamicPlcItem = new DynamicPlcItem <byte[]>(numericItem, flexiblePlcItemFactory, factor, null); // Act dynamicPlcItem.FlexiblePlcItem.Value = value; // Assert Assert.That(numericItem.Value, Is.EqualTo(targetLength)); Assert.That(dynamicPlcItem.FlexiblePlcItem.Value, Has.Length.EqualTo(value.Length)); }
[TestCase(DataConverter.Endianness.BigEndian, (ushort)50, (ushort)50)] // Value is smaller than limit → Value will be used. public void Check_If_Limit_Is_Respected_When_Reading(DataConverter.Endianness endianness, ushort value, ushort target) { // Arrange var limit = (uint)100; INumericPlcItem numericItem; if (endianness == DataConverter.Endianness.LittleEndian) { numericItem = new UInt16PlcItem(0, 0); } else { numericItem = new WordPlcItem(0, 0); } Func <string, IPlcItem <byte[]> > flexiblePlcItemFactory = name => new BytesPlcItem(0, 1, true, new byte[0], name); var dynamicPlcItem = new DynamicPlcItem <byte[]>(numericItem, flexiblePlcItemFactory, 1, limit); // Act numericItem.Value = value; // Assert Assert.That(numericItem.Value, Is.EqualTo(target)); Assert.That(dynamicPlcItem.FlexiblePlcItem.Value, Has.Length.EqualTo(target)); }