Пример #1
0
        public void CompressedArchiveCanBeDecompressedAndContainsExactSameData()
        {
            const string content = "aVeryNiceString";

            var loggerMock          = LoggerMockHelpers.CreateLoggerMock();
            var tempFileWithContent = new FileInfo(Path.GetTempFileName());
            var archiveFile         = new FileInfo(Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid()}.zip"));
            var decompressed        = new DirectoryInfo(Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid()}"));

            try
            {
                File.WriteAllText(tempFileWithContent.FullName, content);

                Compressor.Compress(archiveFile, new [] { tempFileWithContent }, loggerMock.Object);

                Decompress(archiveFile, decompressed);

                var decompressedFile    = decompressed.EnumerateFiles().Single();
                var decompressedContent = File.ReadAllText(decompressedFile.FullName);

                Assert.Equal(content, decompressedContent);
            }
            finally
            {
                tempFileWithContent.Delete();
                archiveFile.Delete();
                decompressed.Delete(recursive: true);
            }
        }
        public void CorrectArgumentsAreSuccesfullyParsed()
        {
            var loggerMock = LoggerMockHelpers.CreateLoggerMock();

            var result = CommandLineOptions.Parse(CorrectArguments, loggerMock.Object);

            Assert.True(result.isSuccess);

            LoggerMockHelpers.AssertNothingWasWrittenToLog(loggerMock);
        }
        public void NonExistingDirectoriesAreReportedAsErrors(string argumentName, string invalidValue)
        {
            var loggerMock = LoggerMockHelpers.CreateLoggerMock();

            var withUppercaseArgument = CorrectArguments.Select(arg => arg.StartsWith($"--{argumentName}=") ? invalidValue : arg).ToArray();

            var result = CommandLineOptions.Parse(withUppercaseArgument, loggerMock.Object);

            Assert.False(result.isSuccess);
            LoggerMockHelpers.AssertAtLeastOneErrorWasWrittenToLog(loggerMock);
        }
        public void TimoutMustBePositiveNumber(int timeout)
        {
            var loggerMock = LoggerMockHelpers.CreateLoggerMock();

            var withNonPositiveTimeout = CorrectArguments.Concat(new[] { $"--timeoutMinutes={timeout}" }).ToArray();

            var result = CommandLineOptions.Parse(withNonPositiveTimeout, loggerMock.Object);

            Assert.False(result.isSuccess);

            LoggerMockHelpers.AssertAtLeastOneErrorWasWrittenToLog(loggerMock);
        }
        public void UnknownArgumentsAreNotIgnored()
        {
            var loggerMock = LoggerMockHelpers.CreateLoggerMock();

            var withUnknownArgument = CorrectArguments.Concat(new[] { "--unknown blabla" }).ToArray();

            var result = CommandLineOptions.Parse(withUnknownArgument, loggerMock.Object);

            Assert.False(result.isSuccess);

            LoggerMockHelpers.AssertAtLeastOneErrorWasWrittenToLog(loggerMock);
        }
        public void ArgumentsAreCaseInsensitive()
        {
            var loggerMock = LoggerMockHelpers.CreateLoggerMock();

            var withUppercaseArgument = CorrectArguments.Select(arg => arg.Replace("--isPr=false", "--isPr=true")).ToArray();

            var result = CommandLineOptions.Parse(withUppercaseArgument, loggerMock.Object);

            Assert.True(result.isSuccess);
            Assert.True(result.options.IsPr);

            LoggerMockHelpers.AssertNothingWasWrittenToLog(loggerMock);
        }