Beispiel #1
0
        public void SourceMustBeCorrectPath()
        {
            var validator = new CommandLineArgumentsValidator(new LoggerMock());
            var result    = validator.Validate(new[] { "compress", "incorrect:file^name", Destination });

            Assert.Equal(ValidationError.PathIsIncorrect, result.ValidationError);
        }
Beispiel #2
0
        public static int Main(string[] args)
        {
            var logger           = new MultithreadingConsoleLogger();
            var validator        = new CommandLineArgumentsValidator(logger);
            var validationResult = validator.Validate(args);

            if (validationResult.ValidationError != ValidationError.Success)
            {
                Console.WriteLine(ValidationErrorMessageProvider.GetErrorMessage(validationResult));
                return(1);
            }

            var taskProcessor = new TaskProcessor(logger);

            try
            {
                var task = taskProcessor.Start(validationResult.TaskParameters);
                Console.CancelKeyPress += (_, cancelEventArgs) =>
                {
                    cancelEventArgs.Cancel = true;
                    task.Abort();
                };

                task.Wait();
                logger.Write("Execution finished " +
                             (task.IsErrorOccured ? "with errors or was aborted" : "successfully"));
                return(task.IsErrorOccured ? 1 : 0);
            }
            catch (Exception e)
            {
                logger.Write(e.Message);
                return(1);
            }
        }
Beispiel #3
0
        public void DestinationMustBeCorrectPath()
        {
            var validator = new CommandLineArgumentsValidator(new LoggerMock());
            var result    = validator.Validate(new[] { "compress", ExistingSource, "   " });

            Assert.Equal(ValidationError.PathIsIncorrect, result.ValidationError);
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += (o, e) =>
            {
                ExitWithError("Oops! It was unexpected.");
            };

            var validationResult = CommandLineArgumentsValidator.GetCommandLineResult(args);

            if (!validationResult.Success)
            {
                ExitWithError(validationResult.ErrorMessage);
            }

            var serviceProvider          = Startup.Configure(validationResult.InputFilePath, validationResult.OutputFilePath);
            var equationTransformManager = serviceProvider.GetService <EquationTransformManager>();

            try
            {
                equationTransformManager.CountWordsAndWrite(validationResult.IOType, validationResult.IOType).Wait();
                ExitSuccess("Done!");
            }
            catch (Exception e)
            {
                ExitWithError(e.Message);
            }
        }
Beispiel #5
0
        public void DestinationMustNotExist()
        {
            var validator = new CommandLineArgumentsValidator(new LoggerMock());

            File.Create("111.txt").Dispose();
            var result = validator.Validate(new[] { "compress", ExistingSource, "111.txt" });

            File.Delete("111.txt");
            Assert.Equal(ValidationError.PathAlreadyExists, result.ValidationError);
        }
Beispiel #6
0
        public void SourceFileMustExist()
        {
            var validator = new CommandLineArgumentsValidator(new LoggerMock());
            var result    = validator.Validate(new[] { "compress", "not-exists.txt", Destination });

            Assert.Equal(ValidationError.SourceNotExists, result.ValidationError);

            result = validator.Validate(new[] { "compress", "A:\\file.mp3", Destination });
            Assert.Equal(ValidationError.SourceNotExists, result.ValidationError);
        }
Beispiel #7
0
        public void AcceptsExactlyThreeArguments()
        {
            var validator = new CommandLineArgumentsValidator(new LoggerMock());
            var result    = validator.Validate(new[] { "compress", ExistingSource, Destination });

            Assert.Equal(ValidationError.Success, result.ValidationError);

            result = validator.Validate(new[] { "", "", "", "" });
            Assert.Equal(ValidationError.TooManyArguments, result.ValidationError);

            result = validator.Validate(new[] { "", "" });
            Assert.Equal(ValidationError.TooFewArguments, result.ValidationError);
        }
Beispiel #8
0
        public void SourceFileRelativePathConvertsToFull()
        {
            var validator = new CommandLineArgumentsValidator(new LoggerMock());
            var result    = validator.Validate(new[] { "compress", ExistingSource, Destination });

            Assert.Equal(ValidationError.Success, result.ValidationError);

            var fullPath = Path.Combine(Environment.CurrentDirectory, ExistingSource);

            Assert.Equal(fullPath, result.TaskParameters.SourceFullPath);

            result = validator.Validate(new[] { "compress", fullPath, Destination });
            Assert.Equal(fullPath, result.TaskParameters.SourceFullPath);
        }
Beispiel #9
0
        public void FirstArgIsProcessMode()
        {
            var validator = new CommandLineArgumentsValidator(new LoggerMock());
            var result    = validator.Validate(new[] { "compress", ExistingSource, Destination });

            Assert.Equal(ValidationError.Success, result.ValidationError);
            Assert.Equal(ProcessorMode.Compress, result.TaskParameters.Mode);

            result = validator.Validate(new[] { "decompress", ExistingSource, Destination });
            Assert.Equal(ValidationError.Success, result.ValidationError);
            Assert.Equal(ProcessorMode.Decompress, result.TaskParameters.Mode);

            result = validator.Validate(new[] { "random-string", ExistingSource, Destination });
            Assert.Equal(ValidationError.UnknownMode, result.ValidationError);
        }