public void DeflateCodec_CompressionDecompressionRoundTrip() { var codec = new DeflateCodec(); using (var memoryStream = new MemoryStream()) using (var compressedStream = codec.GetCompressedStreamOver(memoryStream)) { Assert.IsTrue(compressedStream.CanRead); Assert.IsTrue(compressedStream.CanWrite); Assert.IsTrue(compressedStream.CanSeek); Assert.AreEqual(0, compressedStream.Position); var expected = Utilities.GetRandom<byte[]>(false); compressedStream.Write(expected, 0, expected.Length); compressedStream.Flush(); compressedStream.Seek(0, SeekOrigin.Begin); using (var decompressedStream = codec.GetDecompressedStreamOver(compressedStream)) { var actual = new byte[expected.Length]; decompressedStream.Read(actual, 0, actual.Length); Assert.IsTrue(expected.SequenceEqual(actual)); Assert.IsTrue(decompressedStream.CanRead); Assert.IsFalse(decompressedStream.CanWrite); //TODO CanSeek should be 'false' however it is 'true' now although an exception is thrown when Seek() is called //Assert.IsFalse(decompressedStream.CanSeek); Utilities.ShouldThrow<NotSupportedException>(() => { var result = decompressedStream.Position; }); Utilities.ShouldThrow<NotSupportedException>(() => { var result = decompressedStream.Length; }); Utilities.ShouldThrow<NotSupportedException>(() => { decompressedStream.Seek(0, SeekOrigin.Begin); }); Utilities.ShouldThrow<NotSupportedException>(() => { decompressedStream.SetLength(0); }); Utilities.ShouldThrow<NotSupportedException>(() => { decompressedStream.Position = 0; }); Utilities.ShouldThrow<NotSupportedException>(() => { decompressedStream.Write(expected, 0, expected.Length); }); compressedStream.Flush(); } } }
public void DeflateCodec_GetDecompressedStreamOver() { var codec = new DeflateCodec(); codec.GetDecompressedStreamOver(null); }