mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
add tests
This commit is contained in:
@@ -252,6 +252,26 @@ namespace CliFx.Tests
|
|||||||
_output.WriteLine(stdErr.GetString());
|
_output.WriteLine(stdErr.GetString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Command_parameter_custom_validator_must_implement_the_corresponding_interface()
|
||||||
|
{
|
||||||
|
var (console, _, stdErr) = VirtualConsole.CreateBuffered();
|
||||||
|
|
||||||
|
var application = new CliApplicationBuilder()
|
||||||
|
.AddCommand<InvalidCustomValidatorParameterCommand>()
|
||||||
|
.UseConsole(console)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var exitCode = await application.RunAsync(Array.Empty<string>());
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
exitCode.Should().NotBe(0);
|
||||||
|
stdErr.GetString().Should().NotBeNullOrWhiteSpace();
|
||||||
|
|
||||||
|
_output.WriteLine(stdErr.GetString());
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task Command_options_must_have_names_that_are_not_empty()
|
public async Task Command_options_must_have_names_that_are_not_empty()
|
||||||
{
|
{
|
||||||
@@ -411,5 +431,25 @@ namespace CliFx.Tests
|
|||||||
|
|
||||||
_output.WriteLine(stdErr.GetString());
|
_output.WriteLine(stdErr.GetString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Command_option_custom_validator_must_implement_the_corresponding_interface()
|
||||||
|
{
|
||||||
|
var (console, _, stdErr) = VirtualConsole.CreateBuffered();
|
||||||
|
|
||||||
|
var application = new CliApplicationBuilder()
|
||||||
|
.AddCommand<InvalidCustomValidatorOptionCommand>()
|
||||||
|
.UseConsole(console)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var exitCode = await application.RunAsync(Array.Empty<string>());
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
exitCode.Should().NotBe(0);
|
||||||
|
stdErr.GetString().Should().NotBeNullOrWhiteSpace();
|
||||||
|
|
||||||
|
_output.WriteLine(stdErr.GetString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
using CliFx.Attributes;
|
||||||
|
|
||||||
|
namespace CliFx.Tests.Commands.Invalid
|
||||||
|
{
|
||||||
|
[Command]
|
||||||
|
public class InvalidCustomValidatorOptionCommand : SelfSerializeCommandBase
|
||||||
|
{
|
||||||
|
[CommandOption('f', Validators = new[] { typeof(Validator) })]
|
||||||
|
public string? Option { get; set; }
|
||||||
|
|
||||||
|
public class Validator
|
||||||
|
{
|
||||||
|
public ValidationResult Validate(string value) => ValidationResult.Ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
using CliFx.Attributes;
|
||||||
|
|
||||||
|
namespace CliFx.Tests.Commands.Invalid
|
||||||
|
{
|
||||||
|
[Command]
|
||||||
|
public class InvalidCustomValidatorParameterCommand : SelfSerializeCommandBase
|
||||||
|
{
|
||||||
|
[CommandParameter(0, Validators = new[] { typeof(Validator) })]
|
||||||
|
public string? Param { get; set; }
|
||||||
|
|
||||||
|
public class Validator
|
||||||
|
{
|
||||||
|
public ValidationResult Validate(string value) => ValidationResult.Ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user