Пример #1
0
        public async Task OverlappingFlushAsync_DuringReadAsync()
        {
            byte[] buffer       = new byte[32];
            string testFilePath = gzTestFile("GZTestDocument.pdf.gz");

            using (var readStream = await ManualSyncMemoryStream.GetStreamFromFileAsync(testFilePath, false, StripHeaders))
                using (var unzip = CreateStream(readStream, CompressionMode.Decompress, true))
                {
                    Task task = null;
                    try
                    {
                        readStream.manualResetEvent.Reset();
                        readStream.ReadHit = false;
                        task = ReadAsync(unzip, buffer, 0, 32);
                        Assert.True(readStream.ReadHit);
                        Assert.Throws <InvalidOperationException>(() => { unzip.FlushAsync(); }); // "overlapping read"
                    }
                    finally
                    {
                        // Unblock Async operations
                        readStream.manualResetEvent.Set();
                        // The original ReadAsync should be able to complete
                        Assert.True(task.Wait(100 * 500));
                    }
                }
        }
Пример #2
0
        public async Task OverlappingFlushAsync_DuringWriteAsync()
        {
            byte[] buffer       = null;
            string testFilePath = gzTestFile("GZTestDocument.pdf");

            using (var origStream = await LocalMemoryStream.readAppFileAsync(testFilePath))
            {
                buffer = origStream.ToArray();
            }

            using (var writeStream = new ManualSyncMemoryStream(false))
                using (var zip = CreateStream(writeStream, CompressionMode.Compress))
                {
                    Task task = null;
                    try
                    {
                        task = WriteAsync(zip, buffer, 0, buffer.Length);
                        Assert.True(writeStream.WriteHit);
                        Assert.Throws <InvalidOperationException>(() => { zip.FlushAsync(); }); // "overlapping flushes"
                    }
                    finally
                    {
                        // Unblock Async operations
                        writeStream.manualResetEvent.Set();
                        // The original WriteAsync should be able to complete
                        Assert.True(task.Wait(100 * 500));
                    }
                }
        }
Пример #3
0
        public static async Task OverlappingFlushAsync_DuringWriteAsync()
        {
            byte[] buffer = null;
            string testFilePath = gzTestFile("GZTestDocument.pdf");
            using (var origStream = await LocalMemoryStream.readAppFileAsync(testFilePath))
            {
                buffer = origStream.ToArray();
            }

            using (var writeStream = new ManualSyncMemoryStream(false))
            using (var zip = new DeflateStream(writeStream, CompressionMode.Compress))
            {
                Task task = null;
                try
                {
                    task = zip.WriteAsync(buffer, 0, buffer.Length);
                    Assert.True(writeStream.WriteHit);
                    Assert.Throws<InvalidOperationException>(() => { zip.FlushAsync(); }); // "overlapping flushes"
                }
                finally
                {
                    // Unblock Async operations
                    writeStream.manualResetEvent.Set();
                    // The original WriteAsync should be able to complete
                    Assert.True(task.Wait(100 * 500));
                }
            }
        }
Пример #4
0
        public bool WriteHit = false; // methods of the underlying stream. This bool acts as a toggle to check that they're being used.

        public static async Task <ManualSyncMemoryStream> GetStreamFromFileAsync(string testFile, bool sync = false, bool strip = false)
        {
            var baseStream = await StreamHelpers.CreateTempCopyStream(testFile);

            if (strip)
            {
                baseStream = StripHeaderAndFooter.Strip(baseStream);
            }

            var ms = new ManualSyncMemoryStream(sync);
            await baseStream.CopyToAsync(ms);

            ms.Position = 0;
            return(ms);
        }
Пример #5
0
        public bool WriteHit = false; // methods of the underlying stream. This bool acts as a toggle to check that they're being used.

        public static async Task<ManualSyncMemoryStream> GetStreamFromFileAsync(string testFile, bool sync = false, bool strip = false)
        {
            var baseStream = await StreamHelpers.CreateTempCopyStream(testFile);
            if (strip)
            {
                baseStream = StripHeaderAndFooter.Strip(baseStream);
            }

            var ms = new ManualSyncMemoryStream(sync);
            await baseStream.CopyToAsync(ms);

            ms.Position = 0;
            return ms;
        }