Exemple #1
0
        public void StreamTypeMismatch()
        {
            string randomPath = RandomPath.GetRandomPath();

            using (var writeStream = new FileStream(randomPath, FileMode.Create, FileAccess.Write))
            {
                Assert.Throws <CompressionException>(delegate
                {
                    // ReSharper disable once AccessToDisposedClosure
                    using (new BlockGZipStream(writeStream, CompressionMode.Decompress))
                    {
                    }
                });
            }

            using (var readStream = FileUtilities.GetReadStream(randomPath))
            {
                Assert.Throws <CompressionException>(delegate
                {
                    // ReSharper disable once AccessToDisposedClosure
                    using (new BlockGZipStream(readStream, CompressionMode.Compress))
                    {
                    }
                });
            }
        }
        public void CleanOutput_AsExpected()
        {
            var tempDir = RandomPath.GetRandomPath();

            Directory.CreateDirectory(tempDir);

            File.Create(Path.Combine(tempDir, "json1" + NirvanaHelper.JsonSuffix)).Close();
            File.Create(Path.Combine(tempDir, "json2" + NirvanaHelper.JsonSuffix)).Close();
            File.Create(Path.Combine(tempDir, "jsonIndex1" + NirvanaHelper.JsonIndexSuffix)).Close();
            File.Create(Path.Combine(tempDir, "jsonIndex2" + NirvanaHelper.JsonIndexSuffix)).Close();

            var otherFiles = new[] { "other1.31415926", "other2" }.Select(x => Path.Combine(tempDir, x)).ToArray();

            Array.Sort(otherFiles);
            File.Create(otherFiles[0]).Close();
            File.Create(otherFiles[1]).Close();

            NirvanaHelper.CleanOutput(tempDir);

            var remainFiles = Directory.GetFiles(tempDir).ToArray();

            Array.Sort(remainFiles);

            Assert.Equal(otherFiles.Length, remainFiles.Length);
            for (var i = 0; i < otherFiles.Length; i++)
            {
                Assert.Equal(otherFiles[i], remainFiles[i]);
            }
        }
Exemple #3
0
        public void CanReadWriteSeek()
        {
            string randomPath = RandomPath.GetRandomPath();

            using (var writeStream = new FileStream(randomPath, FileMode.Create, FileAccess.Write))
                using (var blockStream = new BlockStream(Zstd, writeStream, CompressionMode.Compress))
                {
                    Assert.False(blockStream.CanRead);
                    Assert.True(blockStream.CanWrite);
                    Assert.True(blockStream.CanSeek);
                }
        }
        public void CheckInputFilenameExists_MissingFiles_FileNotFoundExitCode()
        {
            string randomPath = RandomPath.GetRandomPath() + ".anavrin";

            var ops = new OptionSet {
                { "id=", "id", v => { } }
            };

            var exitCode = Execute(new ConsoleAppBuilder(new[] { "--if", randomPath }, ops)
                                   .Parse()
                                   .CheckInputFilenameExists(randomPath, "test", "--if"));

            Assert.Equal(ExitCodes.FileNotFound, exitCode);
        }
        public void CheckInputFilenameExists_FileExists_SuccessExitCode()
        {
            string randomPath = RandomPath.GetRandomPath();

            File.Create(randomPath);

            var ops = new OptionSet {
                { "if=", "if", v => { } }
            };

            var exitCode = Execute(new ConsoleAppBuilder(new[] { "--if", randomPath }, ops)
                                   .Parse()
                                   .CheckInputFilenameExists(randomPath, "test", "--if"));

            Assert.Equal(ExitCodes.Success, exitCode);
        }
Exemple #6
0
        public void FileIO()
        {
            var    observedDecompressedBuffer = new byte[_expectedDecompressedBuffer.Length];
            string randomPath = RandomPath.GetRandomPath();

            // compress the data
            long observedPosition;

            using (var writer = new BlockGZipStream(FileUtilities.GetCreateStream(randomPath), CompressionMode.Compress))
            {
                writer.Write(_expectedDecompressedBuffer, 0, _expectedDecompressedBuffer.Length);
                observedPosition = writer.Position;

                var exception = Record.Exception(() =>
                {
                    var buffer = new byte[10];
                    // ReSharper disable once AccessToDisposedClosure
                    writer.Read(buffer, 0, 1);
                });

                Assert.NotNull(exception);
                Assert.IsType <CompressionException>(exception);
            }

            const long expectedPosition = 979042574;

            Assert.Equal(expectedPosition, observedPosition);

            // decompress the data
            using (var reader = new BlockGZipStream(FileUtilities.GetReadStream(randomPath), CompressionMode.Decompress))
            {
                reader.Read(observedDecompressedBuffer, 0, _expectedDecompressedBuffer.Length);

                var exception = Record.Exception(() =>
                {
                    var buffer = new byte[10];
                    // ReSharper disable once AccessToDisposedClosure
                    reader.Write(buffer, 0, 1);
                });

                Assert.NotNull(exception);
                Assert.IsType <CompressionException>(exception);
            }

            Assert.Equal(_expectedDecompressedBuffer, observedDecompressedBuffer);
        }
Exemple #7
0
        public void GetAppropriateReadStream_Handle_BlockGZipFile()
        {
            string randomPath = RandomPath.GetRandomPath();

            using (var writer = GZipUtilities.GetStreamWriter(randomPath))
            {
                writer.WriteLine(ExpectedString);
            }

            string observedString;

            using (var reader = GZipUtilities.GetAppropriateStreamReader(randomPath))
            {
                observedString = reader.ReadLine();
            }

            Assert.Equal(ExpectedString, observedString);
        }
Exemple #8
0
        public void GetAppropriateReadStream_Handle_GZipFile()
        {
            string randomPath = RandomPath.GetRandomPath();

            using (var writer = new StreamWriter(new GZipStream(FileUtilities.GetCreateStream(randomPath), CompressionMode.Compress)))
            {
                writer.WriteLine(ExpectedString);
            }

            string observedString;

            using (var reader = GZipUtilities.GetAppropriateStreamReader(randomPath))
            {
                observedString = reader.ReadLine();
            }

            Assert.Equal(ExpectedString, observedString);
        }
Exemple #9
0
        public void GetReadStream_GetCreateStream_Loopback()
        {
            string       random         = RandomPath.GetRandomPath();
            const string expectedString = "charlie";

            using (var writer = new StreamWriter(FileUtilities.GetCreateStream(random)))
            {
                writer.WriteLine(expectedString);
            }

            string observedString;

            using (var reader = FileUtilities.GetStreamReader(FileUtilities.GetReadStream(random)))
            {
                observedString = reader.ReadLine();
            }

            Assert.Equal(expectedString, observedString);
        }