Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
64b6f60
Update test
Matthiee Dec 17, 2018
0df818d
Rename to description
Matthiee Dec 19, 2018
cee860e
Fix codefactor issues in tests, renaming.
Matthiee Dec 19, 2018
06db974
Codefactor fixes
Matthiee Dec 19, 2018
7231239
Sort usings
Matthiee Dec 19, 2018
39850a1
Better error message
Matthiee Dec 20, 2018
7217ed0
Change command to only have a name instead of both short and long name.
Matthiee Dec 21, 2018
b1a1a1d
SMall refactor of arg manager.
Matthiee Dec 21, 2018
b002485
Add convention options
Matthiee Dec 21, 2018
06de0c5
Update command
Matthiee Dec 23, 2018
2c508e5
Generic command builder exposed wrong return type.
Matthiee Dec 23, 2018
afbe0e0
Add subcommand test
Matthiee Dec 25, 2018
f8ef25a
Add subcommands
Matthiee Dec 25, 2018
4cb462d
Subcommands fire
Matthiee Dec 26, 2018
c9e555f
Improve usage system
Matthiee Dec 27, 2018
760654e
Imrpove subcommand tests
Matthiee Dec 27, 2018
09cab39
Update sample app.
Matthiee Dec 27, 2018
56f0870
Improved command system to use correct configure.
Matthiee Dec 28, 2018
b1f883e
Fix codefactor issues.
Matthiee Dec 28, 2018
f2441f5
Improve dotnet publish output path.
Matthiee Dec 28, 2018
9c159bb
Add codecoverage (#21)
Matthiee Dec 28, 2018
2898f14
Update test
Matthiee Dec 17, 2018
b8e92bd
Rename to description
Matthiee Dec 19, 2018
7a0e625
Fix codefactor issues in tests, renaming.
Matthiee Dec 19, 2018
45c363e
Codefactor fixes
Matthiee Dec 19, 2018
43572b3
Sort usings
Matthiee Dec 19, 2018
93384e8
Better error message
Matthiee Dec 20, 2018
b986749
Change command to only have a name instead of both short and long name.
Matthiee Dec 21, 2018
a1f71b4
SMall refactor of arg manager.
Matthiee Dec 21, 2018
144476a
Add convention options
Matthiee Dec 21, 2018
f646c5b
Update command
Matthiee Dec 23, 2018
3d69e40
Generic command builder exposed wrong return type.
Matthiee Dec 23, 2018
9f7ccf6
Add subcommand test
Matthiee Dec 25, 2018
28525f9
Add subcommands
Matthiee Dec 25, 2018
c3c67eb
Subcommands fire
Matthiee Dec 26, 2018
0134a3c
Improve usage system
Matthiee Dec 27, 2018
d2ab847
Imrpove subcommand tests
Matthiee Dec 27, 2018
9d7a3eb
Update sample app.
Matthiee Dec 27, 2018
a03c23e
Improved command system to use correct configure.
Matthiee Dec 28, 2018
3ad8ced
Fix codefactor issues.
Matthiee Dec 28, 2018
36a0291
Add comments
Matthiee Dec 28, 2018
26643ae
Rebase onto master
Matthiee Dec 28, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions CommandLineParser.Tests/Command/CommandTests.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using System.Linq;

using MatthiWare.CommandLine;
using MatthiWare.CommandLine.Abstractions;
using MatthiWare.CommandLine.Abstractions.Command;

using Xunit;

namespace MatthiWare.CommandLineParser.Tests.Command
{
public class CommandTests
{

[Fact]
public void ConfiguringCommandsIncreasesTotalCommandInParser()
{
Expand All @@ -19,8 +19,8 @@ public void ConfiguringCommandsIncreasesTotalCommandInParser()

Assert.Equal(2, parser.Commands.Count);

Assert.NotNull(parser.Commands.First(cmd => cmd.ShortName.Equals("x")));
Assert.NotNull(parser.Commands.First(cmd => cmd.ShortName.Equals("y")));
Assert.NotNull(parser.Commands.First(cmd => cmd.Name.Equals("x")));
Assert.NotNull(parser.Commands.First(cmd => cmd.Name.Equals("y")));
}

[Fact]
Expand All @@ -33,8 +33,8 @@ public void AddOptionLessCommand()

Assert.Equal(2, parser.Commands.Count);

Assert.NotNull(parser.Commands.First(cmd => cmd.ShortName.Equals("x")));
Assert.NotNull(parser.Commands.First(cmd => cmd.ShortName.Equals("y")));
Assert.NotNull(parser.Commands.First(cmd => cmd.Name.Equals("x")));
Assert.NotNull(parser.Commands.First(cmd => cmd.Name.Equals("y")));
}

[Fact]
Expand All @@ -46,7 +46,7 @@ public void AddCommandType()

Assert.Equal(1, parser.Commands.Count);

Assert.NotNull(parser.Commands.First(cmd => cmd.ShortName.Equals("-bla")));
Assert.NotNull(parser.Commands.First(cmd => cmd.Name.Equals("bla")));
}

[Fact]
Expand All @@ -58,7 +58,7 @@ public void AddCommandTypeWithGenericOption()

Assert.Equal(1, parser.Commands.Count);

Assert.NotNull(parser.Commands.First(cmd => cmd.ShortName.Equals("-bla")));
Assert.NotNull(parser.Commands.First(cmd => cmd.Name.Equals("bla")));
}

private class MyComand : Command<object, object>
Expand All @@ -67,14 +67,13 @@ public override void OnConfigure(ICommandConfigurationBuilder builder)
{
base.OnConfigure(builder);

builder.Name("-bla").Required();
builder.Name("bla").Required();
}

public override void OnExecute(object options, object commandOptions)
{
base.OnExecute(options, commandOptions);
}
}

}
}
121 changes: 121 additions & 0 deletions CommandLineParser.Tests/Command/SubCommandTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
using System;
using System.Threading;
using MatthiWare.CommandLine;
using MatthiWare.CommandLine.Abstractions;
using MatthiWare.CommandLine.Abstractions.Command;
using MatthiWare.CommandLine.Core.Attributes;
using Xunit;

namespace MatthiWare.CommandLineParser.Tests.Command
{
public class SubCommandTests
{
[Fact]
public void TestSubCommandWorksCorrectly()
{
var lock1 = new ManualResetEventSlim();
var lock2 = new ManualResetEventSlim();

var containerResolver = new CustomInstantiator(lock1, lock2);

var parser = new CommandLineParser<MainModel>(containerResolver);

var result = parser.Parse(new[] { "main", "-b", "something", "sub", "-i", "15", "-n", "-1" });

Assert.False(result.HasErrors);

Assert.True(lock1.Wait(1000), "MainCommand didn't execute in time.");
Assert.True(lock2.Wait(1000), "SubCommand didn't execute in time.");
}

private class CustomInstantiator : IContainerResolver
{
private readonly ManualResetEventSlim lock1;
private readonly ManualResetEventSlim lock2;

public CustomInstantiator(ManualResetEventSlim lock1, ManualResetEventSlim lock2)
{
this.lock1 = lock1;
this.lock2 = lock2;
}

public T Resolve<T>()
{
if (typeof(T) == typeof(MainCommand))
return (T)Activator.CreateInstance(typeof(T), lock1);
else if (typeof(T) == typeof(SubCommand))
return (T)Activator.CreateInstance(typeof(T), lock2);
else
return default;
}
}
}

public class MainCommand : Command<MainModel, SubModel>
{
private readonly ManualResetEventSlim locker;

public MainCommand(ManualResetEventSlim locker)
{
this.locker = locker;
}

public override void OnConfigure(ICommandConfigurationBuilder<SubModel> builder)
{
builder
.Name("main")
.Required();
}

public override void OnExecute(MainModel options, SubModel commandOptions)
{
base.OnExecute(options, commandOptions);

locker.Set();
}
}

public class SubCommand : Command<MainModel, SubSubModel>
{
private readonly ManualResetEventSlim locker;

public SubCommand(ManualResetEventSlim locker)
{
this.locker = locker;
}

public override void OnConfigure(ICommandConfigurationBuilder<SubSubModel> builder)
{
builder
.Name("sub")
.Required();
}

public override void OnExecute(MainModel options, SubSubModel commandOptions)
{
base.OnExecute(options, commandOptions);

locker.Set();
}
}

public class MainModel
{
[Required, Name("b")]
public string Bla { get; set; }
public MainCommand MainCommand { get; set; }
}

public class SubModel
{
[Required, Name("i")]
public int Item { get; set; }
public SubCommand SubCommand { get; set; }
}

public class SubSubModel
{
[Required, Name("n")]
public int Nothing { get; set; }
}
}
9 changes: 5 additions & 4 deletions CommandLineParser.Tests/CommandLineModelTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using MatthiWare.CommandLine;
using MatthiWare.CommandLine.Core.Attributes;

using Xunit;

namespace MatthiWare.CommandLineParser.Tests
Expand All @@ -25,7 +26,7 @@ public void TestBasicModel()
Assert.True(message.HasDefault);
Assert.True(message.IsRequired);

Assert.Equal("Help", message.HelpText);
Assert.Equal("Help", message.Description);
}

[Fact]
Expand All @@ -35,7 +36,7 @@ public void TestBasicModelWithOverwritingUsingFluentApi()

parser.Configure(_ => _.Message)
.Required(false)
.HelpText("Different");
.Description("Different");

Assert.Equal(1, parser.Options.Count);

Expand All @@ -51,12 +52,12 @@ public void TestBasicModelWithOverwritingUsingFluentApi()
Assert.True(message.HasDefault);
Assert.False(message.IsRequired);

Assert.Equal("Different", message.HelpText);
Assert.Equal("Different", message.Description);
}

private class Model
{
[Required, Name("-m", "--message"), DefaultValue("not found"), HelpText("Help")]
[Required, Name("m", "message"), DefaultValue("not found"), Description("Help")]
public string Message { get; set; }
}
}
Expand Down
4 changes: 4 additions & 0 deletions CommandLineParser.Tests/CommandLineParser.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="2.5.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="Moq" Version="4.10.0" />
<PackageReference Include="xunit" Version="2.4.0" />
Expand Down
Loading