public static async Task AppendStreamAsyncSanityTest(int streamSize) { NonCryptographicHashAlgorithm hash = new CountingAlgorithm(); using (PositionValueStream stream = new PositionValueStream(streamSize)) { await hash.AppendAsync(stream); } byte[] val = new byte[sizeof(int)]; hash.GetHashAndReset(val); int res = BinaryPrimitives.ReadInt32LittleEndian(val); Assert.Equal(streamSize, res); }
public static void AppendStreamSanityTest(int streamSize) { NonCryptographicHashAlgorithm hash = new CountingAlgorithm(); using (PositionValueStream stream = new PositionValueStream(streamSize)) { hash.Append(stream); } Span <byte> val = stackalloc byte[sizeof(int)]; hash.GetHashAndReset(val); int res = BinaryPrimitives.ReadInt32LittleEndian(val); Assert.Equal(streamSize, res); }
public static void AppendStreamAsyncSupportsCancellation() { NonCryptographicHashAlgorithm hash = new CountingAlgorithm(); using (PositionValueStream stream = new PositionValueStream(21)) using (CancellationTokenSource cts = new CancellationTokenSource()) { cts.Cancel(); Task task = hash.AppendAsync(stream, cts.Token); Assert.True(task.IsCompleted); Assert.True(task.IsCanceled); } byte[] val = new byte[sizeof(int)]; hash.GetHashAndReset(val); int res = BinaryPrimitives.ReadInt32LittleEndian(val); Assert.Equal(0, res); }
public static void GetHashCode_NotSupported() { NonCryptographicHashAlgorithm hash = new CountingAlgorithm(); Assert.Throws <NotSupportedException>(() => hash.GetHashCode()); }