public static void OverriddenGetHashAndReset_TooBig_Succeeds() { Span <byte> buf = stackalloc byte[16]; var hash = new FlexibleAlgorithmOverride(buf.Length / 2); int i = 0; while (buf.Length > hash.HashLengthInBytes) { Assert.Equal(0, hash.GetCurrentHashCoreCallCount); Assert.Equal(i, hash.GetHashAndResetCoreCallCount); hash.Append(buf); Assert.False(hash.IsReset); Assert.True(hash.TryGetHashAndReset(buf, out int written)); Assert.Equal(hash.HashLengthInBytes, written); Assert.True(hash.IsReset); buf = buf.Slice(1); i++; } Assert.Equal(0, hash.GetCurrentHashCoreCallCount); Assert.Equal(i, hash.GetHashAndResetCoreCallCount); Assert.True(hash.IsReset); }
public static void OverriddenTryGetHashAndReset_TooSmall() { Span <byte> buf = stackalloc byte[7]; var hash = new FlexibleAlgorithmOverride(buf.Length + 1); Assert.True(hash.IsReset); hash.Append(buf); Assert.False(hash.IsReset); while (true) { Assert.False(hash.TryGetHashAndReset(buf, out int written)); Assert.Equal(0, written); if (buf.IsEmpty) { break; } buf = buf.Slice(1); } Assert.Equal(0, hash.GetCurrentHashCoreCallCount); Assert.Equal(0, hash.GetHashAndResetCoreCallCount); Assert.False(hash.IsReset); }