Skip to content

Commit

Permalink
Merge pull request #78 from zadykian/fix/param-without-value-error
Browse files Browse the repository at this point in the history
error 'Index was outside the bounds of the array'
  • Loading branch information
neuecc committed Jul 25, 2022
2 parents 5c3eb63 + 7817814 commit 39e6758
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/ConsoleAppFramework/ConsoleAppEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,11 @@ bool TryGetInvokeArguments(ParameterInfo[] parameters, string?[] args, int argsO
}
else
{
if (args.Length <= i)
{
throw new ArgumentException($@"Value for parameter ""{key}"" is not provided.");
}

var value = args[i];
dict.Add(key, new OptionParameter { Value = value });
i++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,15 @@ public void OptionalBoolAndRequiredOtherOption_NoArgs_1()
console.Output.Should().Contain("Hello Cysharp");
}

[Fact]
public void Attempt_To_Call_Without_Parameter_Value()
{
using var console = new CaptureConsoleOutput();
var args = new[] { "--name" };
Host.CreateDefaultBuilder().RunConsoleAppFrameworkAsync<CommandTests_Single_OptionalBoolAndRequiredOtherOption_NoArgs>(args);
console.Output.Should().Contain(@"Value for parameter ""name"" is not provided.");
}

public class CommandTests_Single_OptionalBoolAndRequiredOtherOption_NoArgs : ConsoleAppBase
{
public void Hello(string name, bool hello = false) => Console.WriteLine($"{(hello ? "Hello" : "Konnichiwa")} {name}");
Expand Down

0 comments on commit 39e6758

Please sign in to comment.