Пример #1
0
        public void TestByteArray()
        {
            byte[] expectedValues = new byte[byte.MaxValue - 1];
            byte[] expectedBytes  = new byte[buffer.Size];

            expectedBytes[0] = (byte)expectedValues.Length;
            for (int i = 0; i < expectedValues.Length; i++)
            {
                expectedValues[i] = (byte)r.Next(byte.MaxValue);
                expectedBytes[i + sizeof(byte)] = expectedValues[i];
            }

            buffer.WriteByteArray(expectedValues);

            Assert.IsFalse(buffer.IsFull);
            Assert.AreEqual(byte.MaxValue, buffer.Count);

            for (int i = 0; i < buffer.Size; i++)
            {
                Assert.AreEqual(expectedBytes[i], buffer.Data[i]);
            }

            buffer.Reset();
            Assert.AreEqual(0, buffer.Position);

            byte[] actualBytes = buffer.ReadByteArray();

            Assert.AreEqual(expectedValues.Length, actualBytes.Length);

            for (int i = 0; i < expectedValues.Length; i++)
            {
                Assert.AreEqual(expectedValues[i], actualBytes[i]);
            }

            buffer.Wipe();
            Assert.AreEqual(0, buffer.Count);
        }