添加项目文件。

This commit is contained in:
ShaoHua
2026-07-15 10:39:27 +08:00
parent cc7a15d44c
commit e639ade569
55 changed files with 2196 additions and 0 deletions
+23
View File
@@ -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;
}
}