添加项目文件。
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
<RootNamespace />
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.0" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.0" />
|
||||
<PackageReference Include="NSubstitute" Version="5.1.0" />
|
||||
<PackageReference Include="Shouldly" Version="4.2.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Hua.Cli\Hua.Cli.csproj" />
|
||||
<ProjectReference Include="..\..\src\Hua.Cli.Core\Hua.Cli.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,55 @@
|
||||
using Shouldly;
|
||||
using Volo.Abp.Cli.Args;
|
||||
using Xunit;
|
||||
|
||||
namespace Hua.Cli.Args;
|
||||
|
||||
public class CommandLineArgumentParserTests
|
||||
{
|
||||
private readonly CommandLineArgumentParser _parser;
|
||||
|
||||
public CommandLineArgumentParserTests()
|
||||
{
|
||||
_parser = new CommandLineArgumentParser();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_EmptyArgs_ReturnsEmpty()
|
||||
{
|
||||
var result = _parser.Parse(new string[0]);
|
||||
result.Command.ShouldBeNull();
|
||||
result.Target.ShouldBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_OnlyCommand_ReturnsCommand()
|
||||
{
|
||||
var result = _parser.Parse(new[] { "new" });
|
||||
result.Command.ShouldBe("new");
|
||||
result.Target.ShouldBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_CommandAndTarget_ReturnsBoth()
|
||||
{
|
||||
var result = _parser.Parse(new[] { "new", "MyProject" });
|
||||
result.Command.ShouldBe("new");
|
||||
result.Target.ShouldBe("MyProject");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_CommandAndShortOption_ReturnsOptions()
|
||||
{
|
||||
var result = _parser.Parse(new[] { "new", "MyProject", "-t", "app" });
|
||||
result.Command.ShouldBe("new");
|
||||
result.Target.ShouldBe("MyProject");
|
||||
result.Options.GetOrNull("t").ShouldBe("app");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_CommandAndLongOption_ReturnsOptions()
|
||||
{
|
||||
var result = _parser.Parse(new[] { "new", "MyProject", "--template", "app" });
|
||||
result.Options.GetOrNull("template").ShouldBe("app");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
using Microsoft.Extensions.Options;
|
||||
using Shouldly;
|
||||
using Volo.Abp.Cli;
|
||||
using Volo.Abp.Cli.Args;
|
||||
using Volo.Abp.Cli.Commands;
|
||||
using Xunit;
|
||||
|
||||
namespace Hua.Cli.Commands;
|
||||
|
||||
public class CommandSelectorTests
|
||||
{
|
||||
[Fact]
|
||||
public void Select_NullCommand_ReturnsHelpCommand()
|
||||
{
|
||||
var options = CreateOptions();
|
||||
var selector = new CommandSelector(Options.Create(options));
|
||||
var result = selector.Select(new CommandLineArgs());
|
||||
result.ShouldBe(typeof(HelpCommand));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Select_NewCommand_ReturnsNewCommand()
|
||||
{
|
||||
var options = CreateOptions();
|
||||
options.Commands["new"] = typeof(NewCommand);
|
||||
var selector = new CommandSelector(Options.Create(options));
|
||||
var result = selector.Select(new CommandLineArgs("new"));
|
||||
result.ShouldBe(typeof(NewCommand));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Select_UnknownCommand_ReturnsHelpCommand()
|
||||
{
|
||||
var options = CreateOptions();
|
||||
var selector = new CommandSelector(Options.Create(options));
|
||||
var result = selector.Select(new CommandLineArgs("unknown"));
|
||||
result.ShouldBe(typeof(HelpCommand));
|
||||
}
|
||||
|
||||
private HuaCliOptions CreateOptions()
|
||||
{
|
||||
var options = new HuaCliOptions();
|
||||
options.Commands["help"] = typeof(HelpCommand);
|
||||
return options;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user