Skip to content

Commit 13e976e

Browse files
authored
Version 0.2.1 (#26)
Bugfixes for 0.2.1
1 parent f846598 commit 13e976e

33 files changed

+1716
-467
lines changed

CommandLineParser.Tests/Command/CommandTests.cs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
using Xunit;
77

8-
namespace MatthiWare.CommandLineParser.Tests.Command
8+
namespace MatthiWare.CommandLine.Tests.Command
99
{
1010
public class CommandTests
1111
{
@@ -49,6 +49,18 @@ public void AddCommandType()
4949
Assert.NotNull(parser.Commands.First(cmd => cmd.Name.Equals("bla")));
5050
}
5151

52+
[Fact]
53+
public void AddOtherCommandType()
54+
{
55+
var parser = new CommandLineParser<object>();
56+
57+
parser.RegisterCommand<OtherCommand>();
58+
59+
Assert.Equal(1, parser.Commands.Count);
60+
61+
Assert.NotNull(parser.Commands.First(cmd => cmd.Name.Equals("other")));
62+
}
63+
5264
[Fact]
5365
public void AddCommandTypeWithGenericOption()
5466
{
@@ -63,17 +75,28 @@ public void AddCommandTypeWithGenericOption()
6375

6476
private class MyComand : Command<object, object>
6577
{
66-
public override void OnConfigure(ICommandConfigurationBuilder builder)
78+
public override void OnConfigure(ICommandConfigurationBuilder<object> builder)
6779
{
68-
base.OnConfigure(builder);
80+
builder.Name("bla");
81+
}
6982

70-
builder.Name("bla").Required();
83+
public override void OnConfigure(ICommandConfigurationBuilder builder)
84+
{
85+
builder.Name("bla");
7186
}
7287

7388
public override void OnExecute(object options, object commandOptions)
7489
{
7590
base.OnExecute(options, commandOptions);
7691
}
7792
}
93+
94+
private class OtherCommand : Command<object>
95+
{
96+
public override void OnConfigure(ICommandConfigurationBuilder builder)
97+
{
98+
builder.Name("other");
99+
}
100+
}
78101
}
79102
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using MatthiWare.CommandLine;
2+
using MatthiWare.CommandLine.Core.Attributes;
3+
using Xunit;
4+
5+
namespace MatthiWare.CommandLine.Tests.Command
6+
{
7+
public class MultipleCommandTests
8+
{
9+
[Theory]
10+
[InlineData(new string[] { "cmd1", "-x", "8" }, false)]
11+
[InlineData(new string[] { "cmd2", "-x", "8" }, false)]
12+
[InlineData(new string[] { }, false)]
13+
public void NonRequiredCommandShouldNotSetResultInErrorStateWhenRequiredOptionsAreMissing(string[] args, bool hasErrors)
14+
{
15+
var parser = new CommandLineParser<object>();
16+
17+
parser.AddCommand<MultipleCOmmandTestsOptions>()
18+
.Name("cmd1")
19+
.Required(false)
20+
.Description("cmd1");
21+
22+
parser.AddCommand<MultipleCOmmandTestsOptions>()
23+
.Name("cmd2")
24+
.Required(false)
25+
.Description("cmd2");
26+
27+
var result = parser.Parse(args);
28+
29+
Assert.False(result.HasErrors);
30+
}
31+
32+
private class MultipleCOmmandTestsOptions
33+
{
34+
[Required, Name("x", "bla"), Description("some description")]
35+
public int Option { get; set; }
36+
}
37+
}
38+
}

CommandLineParser.Tests/Command/SubCommandTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using MatthiWare.CommandLine.Core.Attributes;
77
using Xunit;
88

9-
namespace MatthiWare.CommandLineParser.Tests.Command
9+
namespace MatthiWare.CommandLine.Tests.Command
1010
{
1111
public class SubCommandTests
1212
{

CommandLineParser.Tests/CommandLineModelTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
using Xunit;
55

6-
namespace MatthiWare.CommandLineParser.Tests
6+
namespace MatthiWare.CommandLine.Tests
77
{
88
public class CommandLineModelTests
99
{

CommandLineParser.Tests/CommandLineParser.Tests.csproj

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>netcoreapp2.1</TargetFramework>
@@ -7,7 +7,7 @@
77

88
<RootNamespace>MatthiWare.CommandLineParser.Tests</RootNamespace>
99

10-
<LangVersion>7.1</LangVersion>
10+
<LangVersion>7.3</LangVersion>
1111
</PropertyGroup>
1212

1313
<ItemGroup>
@@ -24,6 +24,11 @@
2424
</PackageReference>
2525
</ItemGroup>
2626

27+
<ItemGroup>
28+
<DotNetCliToolReference Include="StrykerMutator.DotNetCoreCli" Version="*" />
29+
<PackageReference Include="StrykerMutator.DotNetCoreCli" Version="*" />
30+
</ItemGroup>
31+
2732
<ItemGroup>
2833
<ProjectReference Include="..\CommandLineParser\CommandLineParser.csproj" />
2934
</ItemGroup>

CommandLineParser.Tests/CommandLineParserTests.cs

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
using Xunit;
1313

14-
namespace MatthiWare.CommandLineParser.Tests
14+
namespace MatthiWare.CommandLine.Tests
1515
{
1616
public class CommandLineParserTests
1717
{
@@ -21,13 +21,31 @@ public override void OnConfigure(ICommandConfigurationBuilder builder)
2121
{
2222
builder.Name("my");
2323
}
24+
25+
public override void OnConfigure(ICommandConfigurationBuilder<object> builder)
26+
{
27+
builder.Name("my");
28+
}
29+
}
30+
31+
[Fact]
32+
public void CommandLineParserUsesCorrectOptions()
33+
{
34+
var opt = new CommandLineParserOptions();
35+
36+
var parser = new CommandLineParser(opt);
37+
38+
Assert.Equal(opt, parser.ParserOptions);
2439
}
2540

2641
[Fact]
2742
public void CommandLineParserUsesContainerCorrectly()
2843
{
2944
var commandMock = new Mock<MyCommand>();
30-
//commandMock.Setup(c => c.OnConfigure(It.IsAny<ICommandConfigurationBuilder>())).Verifiable("OnConfigure not called");
45+
commandMock.Setup(
46+
c => c.OnConfigure(It.IsAny<ICommandConfigurationBuilder<object>>()))
47+
.CallBase().Verifiable("OnConfigure not called");
48+
3149
commandMock.Setup(c => c.OnExecute(It.IsAny<object>(), It.IsAny<object>())).Verifiable("OnExecute not called");
3250

3351
var containerMock = new Mock<IContainerResolver>();
@@ -45,6 +63,52 @@ public void CommandLineParserUsesContainerCorrectly()
4563
containerMock.VerifyAll();
4664
}
4765

66+
[Fact]
67+
public void CommandLinerParserPassesContainerCorreclty()
68+
{
69+
var containerResolver = new Mock<IContainerResolver>();
70+
var options = new CommandLineParserOptions();
71+
var parser = new CommandLineParser(containerResolver.Object);
72+
73+
Assert.Equal(containerResolver.Object, parser.ContainerResolver);
74+
75+
parser = new CommandLineParser(options, containerResolver.Object);
76+
77+
Assert.Equal(containerResolver.Object, parser.ContainerResolver);
78+
Assert.Equal(options, parser.ParserOptions);
79+
}
80+
81+
[Fact]
82+
public void CommandLinerParserPassesResolverCorreclty()
83+
{
84+
var resolverMock = new Mock<IArgumentResolverFactory>();
85+
var options = new CommandLineParserOptions();
86+
var parser = new CommandLineParser(resolverMock.Object);
87+
88+
Assert.Equal(resolverMock.Object, parser.ArgumentResolverFactory);
89+
90+
parser = new CommandLineParser(options, resolverMock.Object);
91+
92+
Assert.Equal(resolverMock.Object, parser.ArgumentResolverFactory);
93+
Assert.Equal(options, parser.ParserOptions);
94+
}
95+
96+
[Fact]
97+
public void CommandLinerParserPassesResolverAndContainerCorreclty()
98+
{
99+
var resolverMock = new Mock<IArgumentResolverFactory>();
100+
101+
var containerMock = new Mock<IContainerResolver>();
102+
103+
var options = new CommandLineParserOptions();
104+
105+
var parser = new CommandLineParser(options, resolverMock.Object, containerMock.Object);
106+
107+
Assert.Equal(resolverMock.Object, parser.ArgumentResolverFactory);
108+
Assert.Equal(containerMock.Object, parser.ContainerResolver);
109+
Assert.Equal(options, parser.ParserOptions);
110+
}
111+
48112
[Fact]
49113
public void CommandLineParserUsesArgumentFactoryCorrectly()
50114
{

CommandLineParser.Tests/CustomerReportedTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
using Xunit;
44

5-
namespace MatthiWare.CommandLineParser.Tests
5+
namespace MatthiWare.CommandLine.Tests
66
{
77
public class CustomerReportedTests
88
{

CommandLineParser.Tests/OptionBuilderTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
using Xunit;
1010

11-
namespace MatthiWare.CommandLineParser.Tests
11+
namespace MatthiWare.CommandLine.Tests
1212
{
1313
public class OptionBuilderTest
1414
{

CommandLineParser.Tests/Parsing/ParserResultTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
using Xunit;
1010

11-
namespace MatthiWare.CommandLineParser.Tests.Parsing
11+
namespace MatthiWare.CommandLine.Tests.Parsing
1212
{
1313
public class ParserResultTest
1414
{

CommandLineParser.Tests/Parsing/ResolverFactoryTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
using Xunit;
1111

12-
namespace MatthiWare.CommandLineParser.Tests.Parsing
12+
namespace MatthiWare.CommandLine.Tests.Parsing
1313
{
1414
public class ResolverFactoryTest
1515
{

0 commit comments

Comments
 (0)