Skip to content

Commit a5df819

Browse files
committed
Add default verb parameter handling
Introduces new unit tests to verify that the console application correctly handles parameters when the default verb is invoked, both with and without explicitly specifying the default verb name. This ensures robust command-line argument parsing for default operations.
1 parent d28be57 commit a5df819

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

Neolution.DotNet.Console.UnitTests/DotNetConsoleGrammarTests.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,48 @@ public async Task GivenBuiltConsoleApp_WhenCallingVerbWithScalarOption_ThenShoul
118118
options.Repeat.ShouldBe(2);
119119
}
120120

121+
/// <summary>
122+
/// When calling the console app with parameters but without specifying the default verb, it should run the default command with those parameters.
123+
/// </summary>
124+
/// <returns>The <see cref="Task"/>.</returns>
125+
[Fact]
126+
public async Task GivenBuiltConsoleApp_WhenCallingDefaultVerbWithParametersWithoutVerb_ThenShouldRunDefaultVerbWithParameters()
127+
{
128+
// Arrange
129+
const string args = "--option=Queue --tenantId=1234";
130+
var logger = new UnitTestLogger();
131+
var console = CreateConsoleAppWithLogger(args, logger);
132+
133+
// Act
134+
await console.RunAsync();
135+
136+
// Assert
137+
var options = (DefaultOptions)logger.LoggedObjects["options"];
138+
options.Option.ShouldBe("Queue");
139+
options.TenantId.ShouldBe("1234");
140+
}
141+
142+
/// <summary>
143+
/// When calling the console app with parameters and explicitly specifying the default verb, it should run the default command with those parameters.
144+
/// </summary>
145+
/// <returns>The <see cref="Task"/>.</returns>
146+
[Fact]
147+
public async Task GivenBuiltConsoleApp_WhenCallingDefaultVerbWithParametersWithVerb_ThenShouldRunDefaultVerbWithParameters()
148+
{
149+
// Arrange
150+
const string args = "default --option=Queue --tenantId=1234";
151+
var logger = new UnitTestLogger();
152+
var console = CreateConsoleAppWithLogger(args, logger);
153+
154+
// Act
155+
await console.RunAsync();
156+
157+
// Assert
158+
var options = (DefaultOptions)logger.LoggedObjects["options"];
159+
options.Option.ShouldBe("Queue");
160+
options.TenantId.ShouldBe("1234");
161+
}
162+
121163
/// <summary>
122164
/// Creates the console application with logger.
123165
/// </summary>

Neolution.DotNet.Console.UnitTests/Fakes/DefaultOptions.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,16 @@
88
[Verb("default", isDefault: true)]
99
public class DefaultOptions
1010
{
11+
/// <summary>
12+
/// Gets or sets the option.
13+
/// </summary>
14+
[Option("option")]
15+
public string? Option { get; set; }
16+
17+
/// <summary>
18+
/// Gets or sets the tenant identifier.
19+
/// </summary>
20+
[Option("tenantId")]
21+
public string? TenantId { get; set; }
1122
}
1223
}

0 commit comments

Comments
 (0)