public void Random_ZeroLength_Success() { // Act var secret = Secret.Random(0); // Assert Assert.Equal(0, secret.Length); }
public void WriteSecretIntoBuffer_Pointer_NullBuffer_Throws() { // Arrange var secret = Secret.Random(16); // Act & assert ExceptionAssert.ThrowsArgumentNull( testCode: () => secret.WriteSecretIntoBuffer(null, 100), paramName: "buffer"); }
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]))); }
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)); }
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]); }
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); }); }
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)); }
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 }