예제 #1
0
        public void Ctor_Buffer_Success()
        {
            // Arrange
            var input = new byte[] { 0x20, 0x30, 0x40 };

            // Act
            var secret = new Secret(input);
            input[1] = 0xFF; // mutate original array - secret shouldn't be modified

            // Assert - length
            Assert.Equal(3, secret.Length);

            // Assert - managed buffer
            var outputSegment = new ArraySegment<byte>(new byte[7], 2, 3);
            secret.WriteSecretIntoBuffer(outputSegment);
            Assert.Equal(new byte[] { 0x20, 0x30, 0x40 }, outputSegment.AsStandaloneArray());

            // Assert - unmanaged buffer
            var outputBuffer = new byte[3];
            fixed (byte* pOutputBuffer = outputBuffer)
            {
                secret.WriteSecretIntoBuffer(pOutputBuffer, 3);
            }
            Assert.Equal(new byte[] { 0x20, 0x30, 0x40 }, outputBuffer);
        }
예제 #2
0
        public void Ctor_Buffer_ZeroLength_Success()
        {
            // Act
            var secret = new Secret(new byte[0]);

            // Assert - none of these methods should throw
            Assert.Equal(0, secret.Length);
            secret.WriteSecretIntoBuffer(new ArraySegment<byte>(new byte[0]));
            byte dummy;
            secret.WriteSecretIntoBuffer(&dummy, 0);
        }