private void ArrayHash(byte[] array, int offset, int count) { byte[] result; using (HashAlgorithm hash = new Length32Hash()) { result = hash.ComputeHash(array, offset, count); } AssertCorrectAnswer((uint)count, result); }
public void HashFullArrayInvalidArguments() { using (HashAlgorithm hash = new Length32Hash()) { Assert.Throws <ArgumentNullException>(() => hash.ComputeHash((byte[])null)); hash.Dispose(); Assert.Throws <ObjectDisposedException>(() => hash.ComputeHash(s_tenBytes)); } }
private void StreamHashHelper(int byteCount) { byte[] result; using (var stream = new PositionValueStream(byteCount)) using (HashAlgorithm hash = new Length32Hash()) { result = hash.ComputeHash(stream); } AssertCorrectAnswer((uint)byteCount, result); }
public void ClearIsDispose() { using (var stream = new PositionValueStream(0)) using (HashAlgorithm hash = new Length32Hash()) { Assert.Throws <NullReferenceException>(() => hash.ComputeHash((Stream)null)); hash.Clear(); Assert.Throws <ObjectDisposedException>(() => hash.ComputeHash(stream)); } }
private void ArrayHash(byte[] array) { // Do not call ArrayHash(byte[], int, int). // Here we're verifying ComputeHash(byte[]). byte[] result; using (HashAlgorithm hash = new Length32Hash()) { result = hash.ComputeHash(array); } AssertCorrectAnswer((uint)array.Length, result); }
public void HashPartialArrayInvalidArguments() { using (HashAlgorithm hash = new Length32Hash()) { Assert.Throws <ArgumentNullException>(() => hash.ComputeHash((byte[])null, 0, 0)); Assert.Throws <ArgumentOutOfRangeException>(() => hash.ComputeHash(s_tenBytes, -1, 0)); AssertExtensions.Throws <ArgumentException>(null, () => hash.ComputeHash(s_tenBytes, 0, -1)); AssertExtensions.Throws <ArgumentException>(null, () => hash.ComputeHash(s_tenBytes, 0, 11)); AssertExtensions.Throws <ArgumentException>(null, () => hash.ComputeHash(s_tenBytes, 9, 2)); hash.Dispose(); Assert.Throws <ObjectDisposedException>(() => hash.ComputeHash(s_tenBytes, 0, 10)); } }