Exemple #1
0
        public void OutofMemory()
        {
            var exception        = new OutOfMemoryException();
            var observedExitCode = ExitCodeUtilities.ShowException(exception);

            Assert.Equal((int)ExitCodes.OutofMemory, observedExitCode);
        }
Exemple #2
0
        public void InvalidData()
        {
            var exception        = new InvalidDataException();
            var observedExitCode = ExitCodeUtilities.ShowException(exception);

            Assert.Equal((int)ExitCodes.InvalidData, observedExitCode);
        }
Exemple #3
0
        public void CallNotImplemented()
        {
            var exception        = new NotImplementedException();
            var observedExitCode = ExitCodeUtilities.ShowException(exception);

            Assert.Equal((int)ExitCodes.CallNotImplemented, observedExitCode);
        }
Exemple #4
0
        public void FileNotFound()
        {
            var exception        = new FileNotFoundException();
            var observedExitCode = ExitCodeUtilities.ShowException(exception);

            Assert.Equal((int)ExitCodes.FileNotFound, observedExitCode);
        }
Exemple #5
0
        public void BadArguments()
        {
            var exception        = new ArgumentNullException();
            var observedExitCode = ExitCodeUtilities.ShowException(exception);

            Assert.Equal((int)ExitCodes.BadArguments, observedExitCode);
        }
Exemple #6
0
        public void BadFormat()
        {
            var exception        = new FormatException();
            var observedExitCode = ExitCodeUtilities.ShowException(exception);

            Assert.Equal((int)ExitCodes.BadFormat, observedExitCode);
        }
Exemple #7
0
        public void UserError()
        {
            var exception        = new UserErrorException("user error");
            var observedExitCode = ExitCodeUtilities.ShowException(exception);

            Assert.Equal((int)ExitCodes.UserError, observedExitCode);
        }
Exemple #8
0
        public void SharingViolation()
        {
            var exception        = new ProcessLockedFileException("locked file");
            var observedExitCode = ExitCodeUtilities.ShowException(exception);

            Assert.Equal((int)ExitCodes.SharingViolation, observedExitCode);
        }
Exemple #9
0
        public void AccessDenied()
        {
            var exception        = new UnauthorizedAccessException();
            var observedExitCode = ExitCodeUtilities.ShowException(exception);

            Assert.Equal((int)ExitCodes.AccessDenied, observedExitCode);
        }
Exemple #10
0
        public void InvalidFileFormat()
        {
            var exception        = new InvalidFileFormatException("invalid format");
            var observedExitCode = ExitCodeUtilities.ShowException(exception);

            Assert.Equal((int)ExitCodes.InvalidFileFormat, observedExitCode);
        }
Exemple #11
0
        public void FileNotSorted()
        {
            var exception        = new FileNotSortedException("not sorted");
            var observedExitCode = ExitCodeUtilities.ShowException(exception);

            Assert.Equal((int)ExitCodes.FileNotSorted, observedExitCode);
        }
Exemple #12
0
        public void MissingCompressionLibrary()
        {
            var exception        = new MissingCompressionLibraryException("compression file");
            var observedExitCode = ExitCodeUtilities.ShowException(exception);

            Assert.Equal((int)ExitCodes.MissingCompressionLibrary, observedExitCode);
        }
Exemple #13
0
        public void ShowException_UnknownException_ExitCode_ShouldBeOne()
        {
            var unknownException = new AbandonedMutexException();
            var exitCode         = ExitCodeUtilities.ShowException(unknownException);

            Assert.Equal(ExitCodes.InvalidFunction, exitCode);
        }
Exemple #14
0
        protected void ParseCommandLine(string[] args)
        {
            try
            {
                _commandLineOps["version"] = new TopLevelOption("displays the version", null);

                string command = null;
                Func <string, string[], int> commandMethod = null;
                string unsupportedOp = null;

                if (args == null || args.Length == 0)
                {
                    SetExitCode(ExitCodes.MissingCommandLineOption);
                    _showHelpMenu = true;
                }
                else
                {
                    command = args[0].ToLower();
                    if (command == "version")
                    {
                        _showVersion = true;
                    }

                    commandMethod = GetCommandMethod(command);
                    if (commandMethod == null)
                    {
                        unsupportedOp = command;
                    }
                }

                if (_showVersion)
                {
                    Console.WriteLine("{0} {1}", _versionProvider.GetProgramVersion(), _versionProvider.GetDataVersion());
                    SetExitCode(ExitCodes.Success);
                }
                else
                {
                    if (_showHelpMenu)
                    {
                        CommandLineUtilities.DisplayBanner(_programAuthors);
                        ShowHelpMenu(unsupportedOp);
                    }
                    else
                    {
                        if (FoundParsingErrors())
                        {
                            return;
                        }
                        if (commandMethod != null)
                        {
                            ExitCode = commandMethod(command, args.Skip(1).ToArray());
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ExitCode = ExitCodeUtilities.ShowException(e);
            }
        }
 public void ShowException_CompressionException_CheckExitCode()
 {
     var compressionException = new CompressionException("test");
     compressionException.Data[ExitCodeUtilities.VcfLine] = "chr1\t100\tA\tC";
     var exitCode = ExitCodeUtilities.ShowException(compressionException);
     Assert.Equal(ExitCodes.Compression, exitCode);
 }
Exemple #16
0
        public void ShowException_AggregateException_ExitCode_ShouldBeOne()
        {
            // TODO: It would be great to verify which exception was shown
            var refNullException   = new NullReferenceException();
            var aggregateException = new AggregateException(refNullException);
            var exitCode           = ExitCodeUtilities.ShowException(aggregateException);

            Assert.Equal(ExitCodes.InvalidFunction, exitCode);
        }
Exemple #17
0
        public void InvalidFunction()
        {
            var exception        = new GeneralException("");
            var observedExitCode = ExitCodeUtilities.ShowException(exception);

            Assert.Equal((int)ExitCodes.InvalidFunction, observedExitCode);

            var exception2 = new Exception();

            observedExitCode = ExitCodeUtilities.ShowException(exception2);

            Assert.Equal((int)ExitCodes.InvalidFunction, observedExitCode);

            var exception3 = new InvalidOperationException();

            observedExitCode = ExitCodeUtilities.ShowException(exception3);

            Assert.Equal((int)ExitCodes.InvalidFunction, observedExitCode);
        }
        /// <summary>
        /// executes the command-line workflow
        /// </summary>
        public void Execute(string[] args)
        {
            var bench = new Benchmark();

            try
            {
                List <string> unsupportedOps = null;

                if (args == null || args.Length == 0)
                {
                    SetExitCode(ExitCodes.MissingCommandLineOption);
                    _showHelpMenu = true;
                }
                else
                {
                    try
                    {
                        unsupportedOps = _commandLineOps.Parse(args);

                        if (unsupportedOps.Count > 0)
                        {
                            SetExitCode(ExitCodes.UnknownCommandLineOption);
                            _showHelpMenu = true;
                        }
                    }
                    catch (OptionException oe)
                    {
                        _errorBuilder.AppendFormat("{0}ERROR: {1}\n", _errorSpacer, oe.Message);
                        SetExitCode(ExitCodes.UnknownCommandLineOption);
                        _showHelpMenu = true;
                    }
                }

                if (_showVersion)
                {
                    Console.WriteLine("{0} {1}", _versionProvider.GetProgramVersion(), _versionProvider.GetDataVersion());
                    SetExitCode(ExitCodes.Success);
                }
                else
                {
                    if (!Console.IsOutputRedirected)
                    {
                        CommandLineUtilities.DisplayBanner(_programAuthors);
                    }

                    if (_showHelpMenu)
                    {
                        Help.Show(_commandLineOps, _commandLineExample, _programDescription);

                        CommandLineUtilities.ShowUnsupportedOptions(unsupportedOps);

                        Console.WriteLine();
                        Console.WriteLine(_versionProvider.GetDataVersion());
                        Console.WriteLine();

                        // print the errors if any were found
                        if (FoundParsingErrors())
                        {
                            return;
                        }
                    }
                    else
                    {
                        ValidateCommandLine();

                        // print the errors if any were found
                        if (FoundParsingErrors())
                        {
                            return;
                        }

                        ProgramExecution();
                    }
                }
            }
            catch (Exception e)
            {
                ExitCode = ExitCodeUtilities.ShowException(e);
            }

            _peakMemoryUsageBytes = MemoryUtilities.GetPeakMemoryUsage();
            _wallTimeSpan         = bench.GetElapsedTime();

            if (!_showVersion && !_showHelpMenu && !Console.IsOutputRedirected)
            {
                Console.WriteLine();
                if (_peakMemoryUsageBytes > 0)
                {
                    Console.WriteLine("Peak memory usage: {0}", MemoryUtilities.ToHumanReadable(_peakMemoryUsageBytes));
                }
                Console.WriteLine("Time: {0}", Benchmark.ToHumanReadable(_wallTimeSpan));
            }
        }
Exemple #19
0
        public void Check_ExceptionToExitCode_Mapping(Exception ex, ExitCodes expectedExitCode)
        {
            ExitCodes observedExitCode = ExitCodeUtilities.GetExitCode(ex.GetType());

            Assert.Equal(expectedExitCode, observedExitCode);
        }