예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        public static void GetHashCode_NotSupported()
        {
            NonCryptographicHashAlgorithm hash = new CountingAlgorithm();

            Assert.Throws <NotSupportedException>(() => hash.GetHashCode());
        }