示例#1
0
        public void CanItemHeaderWriteRawHeaderData(SecsFormat expectedSecsFormat, int expectedItemLength, byte expectedNumberOfLengthBytes, byte expectedRawHeaderDataSize)
        {
            ItemHeader itemHeader = new ItemHeader(expectedSecsFormat, expectedItemLength);

            byte[] expectedRawHeaderData = new byte[expectedRawHeaderDataSize];
            expectedRawHeaderData[0] = (byte)((int)expectedSecsFormat | expectedNumberOfLengthBytes);

            switch (expectedNumberOfLengthBytes)
            {
            case 1:
                expectedRawHeaderData[1] = (byte)expectedItemLength;
                break;

            case 2:
                expectedRawHeaderData[1] = (byte)(expectedItemLength >> 8);
                expectedRawHeaderData[2] = (byte)expectedItemLength;
                break;

            case 3:
                expectedRawHeaderData[1] = (byte)(expectedItemLength >> 16);
                expectedRawHeaderData[2] = (byte)(expectedItemLength >> 8);
                expectedRawHeaderData[3] = (byte)expectedItemLength;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(expectedNumberOfLengthBytes), expectedNumberOfLengthBytes, "The argument must be 1, 2 or 3.");
            }

            byte[] actualRawHeaderData = new byte[expectedRawHeaderData.Length];

            itemHeader.WriteRawHeaderData(actualRawHeaderData, 0);

            CollectionAssert.AreEqual(expectedRawHeaderData, actualRawHeaderData);
        }