Пример #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 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);
        }