public void Should_Return_IntMin_When_Parser_Returns_Null() { // arange A.CallTo(() => _argumentsParser.Parse(A <string[]> ._)) .Returns(null); var expected = int.MinValue; var actual = _sut.Run(new[] { "sum" }); Assert.AreEqual(expected, actual); }
public int Run(string[] args) { Tuple <Operation, int[]> parseResult = _argumentsParser.Parse(args); if (parseResult == null) { return(int.MinValue); } try { return(_calculator.Calculate(parseResult.Item1, parseResult.Item2)); } catch (ArgumentOutOfRangeException) { return(int.MinValue); } }
public void Run(string[] args) { logger.LogInformation($"Application started with {string.Join(",", args)}"); var validationResult = commandLineValidator.Validate(args); if (!validationResult.IsValid) { logger.LogInformation( $"invalid command line arguments {string.Join(Environment.NewLine, validationResult.Errors)}"); PrintHelp(); return; } var jobDescription = argumentsParser.Parse(args); jobBatchOrchestrator.StartProcess(jobDescription); logger.LogInformation(jobContext.Result == ExecutionResult.Failure ? $"Failed to process file due to an error: {jobContext.Error} reported by {jobContext.ReportedBy}" : $"Completed file in {jobContext.ElapsedTimeMilliseconds} ms"); void PrintHelp() => logger.LogInformation(Constants.Help); }
public async Task ExecuteCommand(Dictionary <string, object> context) { var token = GetCancellationToken(context); var options = GetOptions(context); var operands = GetOperands(context); token.ThrowIfCancellationRequested(); using (var scope = _services.CreateScope()) { var services = new ArgumentsServiceProvider(scope.ServiceProvider, token); var command = _commandResolver.Resolve(context, _appModel.Commands); var arguments = _argumentsParser.Parse(command.Arguments, options, operands, services); token.ThrowIfCancellationRequested(); await _commandExecutor.ExecuteAsync( command, arguments, services, token) .ConfigureAwait(false); } }
public static void Main(string[] args) { Activator.Initialise(); IArgumentsParser parser = ServiceLocator.Current.GetInstance <IArgumentsParser>(); parser.Parse(args); using (TextWriter writer = new StreamWriter(Console.OpenStandardOutput())) { if (!parser.AreValid || parser.IsHelpPageRequested) { ShowHelp(writer); Console.ReadLine(); return; } ProcessGraph(parser, writer); } Console.ReadLine(); }
public void Should_Return_Null_For_Null_Arguments() { var actual = _sut.Parse(null); Assert.That(actual, Is.Null); }