Handle .NET core tool error differences on Linux
This commit is contained in:
Родитель
15deb27023
Коммит
af3802fbb3
|
@ -194,6 +194,16 @@ namespace Steeltoe.NetCoreToolService.Controllers
|
|||
return NotFound($"Template '{template}' not found.");
|
||||
}
|
||||
|
||||
const string invalidOptionError = "Invalid option(s)";
|
||||
if (newCommand.Error.Contains(invalidOptionError))
|
||||
{
|
||||
var start = newCommand.Error.IndexOf(invalidOptionError, StringComparison.Ordinal) +
|
||||
invalidOptionError.Length;
|
||||
start = newCommand.Error.IndexOf("--", start, StringComparison.Ordinal) + "--".Length;
|
||||
var end = newCommand.Error.IndexOf('\n', start);
|
||||
return NotFound($"Switch '{newCommand.Error[start..end]}' not found.");
|
||||
}
|
||||
|
||||
const string invalidSwitchError = "Invalid input switch:";
|
||||
if (newCommand.Error.Contains(invalidSwitchError))
|
||||
{
|
||||
|
|
|
@ -413,7 +413,7 @@ No templates found matching: 'nosuchtemplate'.
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetTemplateProject_UnknownSwitch_Should_Return_NotFound()
|
||||
public async Task GetTemplateProject_UnknownSwitch1_Should_Return_NotFound()
|
||||
{
|
||||
// Arrange
|
||||
var executor = new Mock<ICommandExecutor>();
|
||||
|
@ -440,6 +440,34 @@ For a list of valid options, run 'dotnet new webapi --help'.
|
|||
notFound.Value.Should().Be("Switch 'unknown-switch' not found.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetTemplateProject_UnknownSwitch2_Should_Return_NotFound()
|
||||
{
|
||||
// Arrange
|
||||
var executor = new Mock<ICommandExecutor>();
|
||||
executor.Setup(c =>
|
||||
c.ExecuteAsync($"{NetCoreTool.Command} new mytemplate --output=Sample --unknown-switch",
|
||||
It.IsAny<string>(), -1))
|
||||
.ReturnsAsync(new CommandResult
|
||||
{
|
||||
ExitCode = 5,
|
||||
Error = @"
|
||||
Error: Invalid option(s):
|
||||
--unknown-switch
|
||||
'--unknown-switch' is not a valid option
|
||||
",
|
||||
}
|
||||
);
|
||||
var controller = new NewController(executor.Object);
|
||||
|
||||
// Act
|
||||
var result = await controller.GetTemplateProject("mytemplate", "unknown-switch");
|
||||
|
||||
// Assert
|
||||
var notFound = Assert.IsType<NotFoundObjectResult>(result);
|
||||
notFound.Value.Should().Be("Switch 'unknown-switch' not found.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetTemplateProject_UnknownParameter_Should_Return_NotFound()
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче