Пример #1
0
        public void ShouldAskForRequiredInputData(string[] args)
        {
            if (args.Length == 0)
            {
                _mockInputOutput.Setup(x => x.ReadLine(MessageConstants.EnterCompressionMethodMessage))
                .Returns("compress").Verifiable();
            }

            if (args.Length < 2)
            {
                _mockInputOutput.Setup(x => x.ReadLine(MessageConstants.EnterSourceMessage))
                .Returns("file.txt").Verifiable();
            }

            if (args.Length < 3)
            {
                _mockInputOutput.Setup(x => x.ReadLine(MessageConstants.EnterTargetMessage))
                .Returns("file.gzip").Verifiable();
            }

            var inputReader = new GzipperUserInputReader(_mockInputOutput.Object);

            inputReader.ParseUserInputData(args);

            _mockInputOutput.Verify();
        }
        private void UnsafeExecute(string[] args)
        {
            _logger.Info("Starting Gzipper application");

            var input = _inputReader.ParseUserInputData(args);

            _logger.Info($"Method: '{input.Action}' | Source file: '{input.SourceFilePath}' | Target file: '{input.TargetFilePath}' \n");

            // new c# features :)
            ICommand processor = input.Action switch
            {
                UserAction.Compress => new CompressCommand(_streamFactory, _logger, _settings),
                UserAction.Decompress => new DecompressCommand(_streamFactory, _settings, _logger),
                _ => throw new IndexOutOfRangeException()
            };

            processor.StartSync(input);

            _logger.Info("Successfully completed");
        }
    }