Esempio n. 1
0
        public void Random_ZeroLength_Success()
        {
            // Act
            var secret = Secret.Random(0);

            // Assert
            Assert.Equal(0, secret.Length);
        }
Esempio n. 2
0
        public void WriteSecretIntoBuffer_Pointer_NullBuffer_Throws()
        {
            // Arrange
            var secret = Secret.Random(16);

            // Act & assert
            ExceptionAssert2.ThrowsArgumentNull(
                testCode: () => secret.WriteSecretIntoBuffer(null, 100),
                paramName: "buffer");
        }
Esempio n. 3
0
        public void WriteSecretIntoBuffer_ArraySegment_Disposed_Throws()
        {
            // Arrange
            var secret = Secret.Random(16);

            secret.Dispose();

            // Act & assert
            Assert.Throws <ObjectDisposedException>(
                testCode: () => secret.WriteSecretIntoBuffer(new ArraySegment <byte>(new byte[16])));
        }
Esempio n. 4
0
        public void WriteSecretIntoBuffer_ArraySegment_IncorrectlySizedBuffer_Throws()
        {
            // Arrange
            var secret = Secret.Random(16);

            // Act & assert
            ExceptionAssert.ThrowsArgument(
                testCode: () => secret.WriteSecretIntoBuffer(new ArraySegment <byte>(new byte[100])),
                paramName: "buffer",
                exceptionMessage: Resources.FormatCommon_BufferIncorrectlySized(100, 16));
        }
Esempio n. 5
0
        public void Random_LengthIsMultipleOf16_Success()
        {
            // Act
            var secret = Secret.Random(32);

            // Assert
            Assert.Equal(32, secret.Length);
            Guid *pGuids = stackalloc Guid[2];

            secret.WriteSecretIntoBuffer((byte *)pGuids, 32);
            Assert.NotEqual(Guid.Empty, pGuids[0]);
            Assert.NotEqual(Guid.Empty, pGuids[1]);
            Assert.NotEqual(pGuids[0], pGuids[1]);
        }
Esempio n. 6
0
        public void WriteSecretIntoBuffer_Pointer_Disposed_Throws()
        {
            // Arrange
            var secret = Secret.Random(16);

            secret.Dispose();

            // Act & assert
            Assert.Throws <ObjectDisposedException>(
                testCode: () =>
            {
                byte *pBuffer = stackalloc byte[16];
                secret.WriteSecretIntoBuffer(pBuffer, 16);
            });
        }
Esempio n. 7
0
        public void WriteSecretIntoBuffer_Pointer_IncorrectlySizedBuffer_Throws()
        {
            // Arrange
            var secret = Secret.Random(16);

            // Act & assert
            ExceptionAssert.ThrowsArgument(
                testCode: () =>
            {
                byte *pBuffer = stackalloc byte[100];
                secret.WriteSecretIntoBuffer(pBuffer, 100);
            },
                paramName: "bufferLength",
                exceptionMessage: Resources.FormatCommon_BufferIncorrectlySized(100, 16));
        }
Esempio n. 8
0
        public void Random_LengthIsNotMultipleOf16_Success()
        {
            // Act
            var secret = Secret.Random(31);

            // Assert
            Assert.Equal(31, secret.Length);
            Guid *pGuids = stackalloc Guid[2];

            secret.WriteSecretIntoBuffer((byte *)pGuids, 31);
            Assert.NotEqual(Guid.Empty, pGuids[0]);
            Assert.NotEqual(Guid.Empty, pGuids[1]);
            Assert.NotEqual(pGuids[0], pGuids[1]);
            Assert.Equal(0, ((byte *)pGuids)[31]); // last byte shouldn't have been overwritten
        }