public void Should_compress_file() { var inputFile = _fileToCompress; var outputFile = new FileInfo(inputFile.FullName + ".gz"); var args = new[] { "compress", inputFile.FullName, outputFile.FullName }; RunningArguments.Set(args); _sut.CompressFile(RunningArguments.Current.InputPath, RunningArguments.Current.OutputPath); outputFile = new FileInfo(outputFile.FullName); Assert.That(outputFile.Exists); Assert.That(outputFile.Length < inputFile.Length); if (outputFile.Exists) { outputFile.Delete(); } }
static void Main(string[] args) { // TODO Replace with event Console.WriteLine("Program has been started."); try { RunningArguments.Set(args); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); return; } // TODO Replace with event Console.WriteLine("Arguments have been set."); if (RunningArguments.Current.DoShowHelp) { var helpShower = new HelpShower(); helpShower.ShowHelp(); } else { var archivationSrv = new ArchivationService(); var actionDict = new Dictionary <CompressionMode, Action <string, string> >() { { CompressionMode.Decompress, (input, output) => archivationSrv.DecompressFile(input, output) }, { CompressionMode.Compress, (input, output) => archivationSrv.CompressFile(input, output) }, }; var archiverAction = actionDict[RunningArguments.Current.CompressionMode]; var watch = new Stopwatch(); watch.Start(); try { archiverAction.Invoke(RunningArguments.Current.InputPath, RunningArguments.Current.OutputPath); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); var outputFile = new FileInfo(RunningArguments.Current.OutputPath); if (outputFile.Exists) { outputFile.Delete(); } return; } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); Console.WriteLine("The unhandled exception has been thrown. Please create bug ticket on " + "https://github.com/ShefardPT/TestTask_GZipArchiver/issues"); var outputFile = new FileInfo(RunningArguments.Current.OutputPath); if (outputFile.Exists) { outputFile.Delete(); } return; } watch.Stop(); // TODO Replace with event Console.WriteLine("Done!"); Console.WriteLine($"It had taken {watch.ElapsedMilliseconds / 1000}.{watch.ElapsedMilliseconds % 1000} seconds to do job."); Console.WriteLine("Press ENTER to finish."); Console.ReadLine(); } }