Fix tests with incorrect validation that were in the main branch

Tests had incorrect expectations for the parsing of branch + default command arguments
This commit is contained in:
Frank Ray 2024-10-04 16:53:06 +01:00 committed by Patrik Svensson
parent edf7f23957
commit c81bc5fe1d

View File

@ -62,10 +62,8 @@ public sealed partial class CommandAppTests
}); });
} }
[SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1515:SingleLineCommentMustBePrecededByBlankLine", Justification = "Helps to illustrate the expected behaviour of this unit test.")]
[SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1005:SingleLineCommentsMustBeginWithSingleSpace", Justification = "Helps to illustrate the expected behaviour of this unit test.")]
[Fact] [Fact]
public void Should_Be_Unable_To_Parse_Default_Command_Arguments_Relaxed_Parsing() public void Should_Parse_Branch_And_Default_Command_Arguments_Relaxed_Parsing()
{ {
// Given // Given
var app = new CommandAppTester(); var app = new CommandAppTester();
@ -81,25 +79,27 @@ public sealed partial class CommandAppTests
// When // When
var result = app.Run(new[] var result = app.Run(new[]
{ {
// The CommandTreeParser should be unable to determine which command line // The CommandTreeParser should determine which command line arguments
// arguments belong to the branch and which belong to the branch's // belong to the branch and which belong to the branch's default command.
// default command (once inserted). "animal", "4", "-a", "false", "--name", "Kitty", "--agility", "four", "--nick-name", "Felix"
"animal", "4", "--name", "Kitty",
}); });
// Then // Then
result.ExitCode.ShouldBe(0); result.ExitCode.ShouldBe(0);
result.Settings.ShouldBeOfType<CatSettings>().And(cat => result.Settings.ShouldBeOfType<CatSettings>().And(cat =>
{ {
cat.IsAlive.ShouldBeFalse();
cat.Legs.ShouldBe(4); cat.Legs.ShouldBe(4);
//cat.Name.ShouldBe("Kitty"); //<-- Should normally be correct, but instead name will be added to the remaining arguments (see below). cat.Name.ShouldBe("Kitty");
cat.Agility.ShouldBe(4);
}); });
result.Context.Remaining.Parsed.Count.ShouldBe(1); result.Context.Remaining.Parsed.Count.ShouldBe(1);
result.Context.ShouldHaveRemainingArgument("--name", values: new[] { "Kitty", }); result.Context.ShouldHaveRemainingArgument("--nick-name", values: new[] { "Felix" });
result.Context.Remaining.Raw.Count.ShouldBe(0);
} }
[Fact] [Fact]
public void Should_Be_Unable_To_Parse_Default_Command_Arguments_Strict_Parsing() public void Should_Parse_Branch_And_Default_Command_Arguments_Strict_Parsing()
{ {
// Given // Given
var app = new CommandAppTester(); var app = new CommandAppTester();
@ -114,22 +114,25 @@ public sealed partial class CommandAppTests
}); });
// When // When
var result = Record.Exception(() => var result = app.Run(new[]
{ {
app.Run(new[] // The CommandTreeParser should determine which command line arguments
{ // belong to the branch and which belong to the branch's default command.
// The CommandTreeParser should be unable to determine which command line "animal", "4", "-a", "false", "--name", "Kitty", "--agility", "four", "--", "--nick-name", "Felix"
// arguments belong to the branch and which belong to the branch's
// default command (once inserted).
"animal", "4", "--name", "Kitty",
});
}); });
// Then // Then
result.ShouldBeOfType<CommandParseException>().And(ex => result.ExitCode.ShouldBe(0);
result.Settings.ShouldBeOfType<CatSettings>().And(cat =>
{ {
ex.Message.ShouldBe("Unknown option 'name'."); cat.IsAlive.ShouldBeFalse();
cat.Legs.ShouldBe(4);
cat.Name.ShouldBe("Kitty");
cat.Agility.ShouldBe(4);
}); });
result.Context.Remaining.Parsed.Count.ShouldBe(1);
result.Context.ShouldHaveRemainingArgument("--nick-name", values: new[] { "Felix" });
result.Context.Remaining.Raw.Count.ShouldBe(2);
} }
[Theory] [Theory]