Skip to content

Commit d775a89

Browse files
committed
Merge branch 'development'
2 parents b3934ee + bf0ff68 commit d775a89

27 files changed

+506
-147
lines changed

.editorconfig

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
11
root = true
22

3+
[*.cs]
4+
indent_size = 2
5+
indent_style = space
6+
trim_trailing_whitespace = true
37
# Enable "this."
48
dotnet_style_qualification_for_field = true:warning
59
dotnet_style_qualification_for_property = true:warning
610
dotnet_style_qualification_for_method = true:warning
711
dotnet_style_qualification_for_method = true:warning
8-
912
# use predefined type ("int") instead of framework names ("Int32")
1013
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
1114
dotnet_style_predefined_type_for_member_access = true:suggestion
12-
1315
# Access modifiers
14-
dotnet_style_require_accessibility_modifiers = always:warning
15-
16-
#
17-
18-
[*.cs]
19-
indent_size = 2
20-
indent_style = space
21-
trim_trailing_whitespace = true
16+
dotnet_style_require_accessibility_modifiers = always:error
2217
# Prefer "var"
2318
csharp_style_var_for_built_in_types = true:suggestion
2419
csharp_style_var_when_type_is_apparent = true:suggestion
@@ -28,3 +23,5 @@ csharp_style_pattern_matching_over_is_with_cast_check = true:warning
2823
csharp_style_pattern_matching_over_as_with_null_check = true:warning
2924
# Inline out variable
3025
csharp_style_inlined_variable_declaration = true:warning
26+
# Throw expressions
27+
csharp_style_throw_expression = true:error

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ AtleX.CommandLineArguments is a helper library to facilitate parsing command lin
44
and customisable validators and the library can automatically generate help for the user.
55

66
Supported .NET frameworks:
7-
* .NET 4.5
8-
* NETSTANDARD 1.5
7+
* .NET 4.6.1
8+
* NETSTANDARD 2.0
99

1010
# Installation
1111

src/AtleX.CommandLineArguments.Benchmarks/AtleX.CommandLineArguments.Benchmarks.csproj

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

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFrameworks>netcoreapp2.0;net46</TargetFrameworks>
5+
<TargetFrameworks>netcoreapp2.0;net472</TargetFrameworks>
66
<PlatformTarget>AnyCPU</PlatformTarget>
77
</PropertyGroup>
88

@@ -13,7 +13,7 @@
1313
</ItemGroup>
1414

1515
<ItemGroup>
16-
<PackageReference Include="BenchmarkDotNet" Version="0.10.14" />
16+
<PackageReference Include="BenchmarkDotNet" Version="0.11.5" />
1717
<Reference Include="System.ComponentModel.DataAnnotations" />
1818
</ItemGroup>
1919

src/AtleX.CommandLineArguments.Benchmarks/Program.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
using System;
2-
using AtleX.CommandLineArguments.Benchmarks.Benches;
1+
using AtleX.CommandLineArguments.Benchmarks.Benches;
32
using BenchmarkDotNet.Configs;
43
using BenchmarkDotNet.Diagnosers;
54
using BenchmarkDotNet.Jobs;
65
using BenchmarkDotNet.Running;
76
using BenchmarkDotNet.Toolchains.CsProj;
7+
using System;
88

99
namespace AtleX.CommandLineArguments.Benchmarks
1010
{
11-
class Program
11+
internal class Program
1212
{
13-
static void Main(string[] args)
13+
private static void Main(string[] args)
1414
{
1515
var config = GetConfig();
1616
var benchmarks = GetBenchmarks();
@@ -40,9 +40,9 @@ private static IConfig GetConfig()
4040

4141
config.Add(MemoryDiagnoser.Default);
4242

43-
config.Add(Job.Default.With(CsProjCoreToolchain.NetCoreApp20));
44-
config.Add(Job.Default.With(CsProjCoreToolchain.NetCoreApp21));
45-
config.Add(Job.Default.With(CsProjClassicNetToolchain.Net462));
43+
config.Add(Job.Default.With(CsProjCoreToolchain.NetCoreApp20).AsBaseline());
44+
config.Add(Job.Default.With(CsProjCoreToolchain.NetCoreApp30));
45+
config.Add(Job.Default.With(CsProjClassicNetToolchain.Net472));
4646

4747
return config;
4848
}
Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,34 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net452;netcoreapp2.0;</TargetFrameworks>
4+
<TargetFrameworks>net461;netcoreapp2.0;</TargetFrameworks>
55
</PropertyGroup>
66

77
<ItemGroup>
88
<None Remove="coverage.json" />
99
</ItemGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="coverlet.msbuild" Version="2.1.0" />
13-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" />
14-
<PackageReference Include="xunit" Version="2.3.1" />
12+
<PackageReference Include="coverlet.msbuild" Version="2.6.3">
13+
<PrivateAssets>all</PrivateAssets>
14+
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
15+
</PackageReference>
16+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
17+
<PackageReference Include="xunit" Version="2.4.1" />
1518
<PackageReference Include="xunit.analyzers " Version="0.9.0" />
16-
<PackageReference Include="xunit.extensibility.execution" Version="2.3.1" />
17-
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
19+
<PackageReference Include="xunit.extensibility.execution" Version="2.4.1" />
20+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
21+
<PrivateAssets>all</PrivateAssets>
22+
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
23+
</PackageReference>
1824
<Reference Include="System.ComponentModel.DataAnnotations" />
1925
</ItemGroup>
2026

2127
<ItemGroup>
2228
<ProjectReference Include="..\AtleX.CommandLineArguments\AtleX.CommandLineArguments.csproj" />
2329
</ItemGroup>
30+
31+
<ItemGroup>
32+
<PackageReference Update="xunit.analyzers" Version="0.10.0" />
33+
</ItemGroup>
2434
</Project>
Lines changed: 98 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,122 @@
11
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
24
using AtleX.CommandLineArguments.Configuration;
35
using AtleX.CommandLineArguments.Parsers.TypeParsers;
6+
using AtleX.CommandLineArguments.Tests.Mocks;
47
using AtleX.CommandLineArguments.Validators;
58
using Xunit;
69

710
namespace AtleX.CommandLineArguments.Tests.Configuration
811
{
912
public class CommandLineArgumentsConfigurationTests
1013
{
14+
[Fact]
15+
public void Ctor_WithNullIArgumentValidator_Throws()
16+
{
17+
Assert.Throws<ArgumentNullException>(() => new CommandLineArgumentsConfiguration((IArgumentValidator)null));
18+
}
19+
20+
[Fact]
21+
public void Ctor_WithIArgumentValidator_Succeeds()
22+
{
23+
var c = new CommandLineArgumentsConfiguration(new MockArgumentValidator());
24+
25+
Assert.Contains(c.Validators, v => v.GetType() == typeof(MockArgumentValidator));
26+
}
27+
28+
[Fact]
29+
public void Ctor_WithIArgumentValidators_Succeeds()
30+
{
31+
var c = new CommandLineArgumentsConfiguration(new[] { new MockArgumentValidator() });
32+
33+
Assert.Contains(c.Validators, v => v.GetType() == typeof(MockArgumentValidator));
34+
}
35+
36+
[Fact]
37+
public void Ctor_WithNullIArgumentValidators_Throws()
38+
{
39+
Assert.Throws<ArgumentNullException>(() => new CommandLineArgumentsConfiguration((IEnumerable<IArgumentValidator>)null));
40+
}
41+
42+
[Fact]
43+
public void Ctor_WithNullITypeParser_Throws()
44+
{
45+
Assert.Throws<ArgumentNullException>(() => new CommandLineArgumentsConfiguration((ITypeParser)null));
46+
}
47+
48+
[Fact]
49+
public void Ctor_WithITypeParser_Succeeds()
50+
{
51+
var c = new CommandLineArgumentsConfiguration(new MockTypeParser());
52+
53+
Assert.Contains(c.TypeParsers, p => p.GetType() == typeof(MockTypeParser));
54+
}
55+
56+
[Fact]
57+
public void Ctor_WithITypeParsers_Succeeds()
58+
{
59+
var c = new CommandLineArgumentsConfiguration(new[] { new MockTypeParser() });
60+
61+
Assert.Contains(c.TypeParsers, p => p.GetType() == typeof(MockTypeParser));
62+
}
63+
64+
[Fact]
65+
public void Ctor_WithNullITypeParsers_Throws()
66+
{
67+
Assert.Throws<ArgumentNullException>(() => new CommandLineArgumentsConfiguration((IEnumerable<ITypeParser>)null));
68+
}
69+
70+
[Fact]
71+
public void Add_ArgumentValidator_WithNull_Throws()
72+
{
73+
var config = new CommandLineArgumentsConfiguration();
74+
75+
Assert.Throws<ArgumentNullException>(() => config.Add((IArgumentValidator)null));
76+
}
77+
1178
[Fact]
1279
public void Add_TypeParser_WithNull_Throws()
1380
{
1481
var config = new CommandLineArgumentsConfiguration();
1582

16-
Assert.Throws<ArgumentNullException>(() => config.Add((TypeParser)null));
83+
Assert.Throws<ArgumentNullException>(() => config.Add((ITypeParser)null));
1784
}
1885

1986
[Fact]
20-
public void Add_ArgumentValidator_WithNull_Throws()
87+
public void AddRange_ArgumentValidators_WithNull_Throws()
88+
{
89+
var config = new CommandLineArgumentsConfiguration();
90+
91+
Assert.Throws<ArgumentNullException>(() => config.AddRange((IEnumerable<IArgumentValidator>)null));
92+
}
93+
94+
[Fact]
95+
public void AddRange_ArgumentValidators_WithValidValidator_Succeeds()
96+
{
97+
var config = new CommandLineArgumentsConfiguration();
98+
99+
config.AddRange(new[] { new MockArgumentValidator() });
100+
101+
Assert.Contains(config.Validators, v => v.GetType() == typeof(MockArgumentValidator));
102+
}
103+
104+
[Fact]
105+
public void AddRange_TypeParsers_WithNull_Throws()
106+
{
107+
var config = new CommandLineArgumentsConfiguration();
108+
109+
Assert.Throws<ArgumentNullException>(() => config.AddRange((IEnumerable<ITypeParser>)null));
110+
}
111+
112+
[Fact]
113+
public void AddRange_TypeParsers_WithValidParser_Succeeds()
21114
{
22115
var config = new CommandLineArgumentsConfiguration();
23116

24-
Assert.Throws<ArgumentNullException>(() => config.Add((ArgumentValidator)null));
117+
config.AddRange(new[] { new MockTypeParser() });
118+
119+
Assert.Contains(config.TypeParsers, p => p.GetType() == typeof(MockTypeParser));
25120
}
26121
}
27122
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using AtleX.CommandLineArguments.Validators;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Reflection;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace AtleX.CommandLineArguments.Tests.Mocks
10+
{
11+
public class MockArgumentValidator
12+
: IArgumentValidator
13+
{
14+
public bool TryValidate(PropertyInfo argumentPropertyInfo, bool isSpecified, string originalValue, out ValidationError validationError)
15+
{
16+
validationError = null;
17+
return true;
18+
}
19+
}
20+
}

src/AtleX.CommandLineArguments.Tests/Mocks/MockParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace AtleX.CommandLineArguments.Tests.Mocks
99
public sealed class MockParser
1010
: ICommandLineArgumentsParser
1111
{
12-
public ParseResult<T> Parse<T>(string[] arguments, IEnumerable<ArgumentValidator> validators, IEnumerable<TypeParser> typeParsers) where T : Arguments, new()
12+
public ParseResult<T> Parse<T>(string[] arguments, IEnumerable<IArgumentValidator> validators, IEnumerable<ITypeParser> typeParsers) where T : Arguments, new()
1313
{
1414
throw new NotImplementedException();
1515
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using AtleX.CommandLineArguments.Parsers.TypeParsers;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace AtleX.CommandLineArguments.Tests.Mocks
9+
{
10+
public class MockTypeParser
11+
: ITypeParser
12+
{
13+
public Type Type => typeof(string);
14+
15+
public bool TryParse(string value, out object parseResult)
16+
{
17+
parseResult = value;
18+
19+
return true;
20+
}
21+
}
22+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using AtleX.CommandLineArguments.Parsers;
2+
using AtleX.CommandLineArguments.Validators;
3+
using System.Linq;
4+
using Xunit;
5+
6+
namespace AtleX.CommandLineArguments.Tests.Parsers
7+
{
8+
9+
[Collection("NotInParallel")]
10+
public class PrefixedKeyParserTests
11+
: CommandLineArgumentsParserTests
12+
{
13+
public PrefixedKeyParserTests()
14+
: base(new PrefixedKeyParser("--"), Enumerable.Empty<ArgumentValidator>())
15+
{
16+
}
17+
18+
protected override string[] CreateValidArguments()
19+
{
20+
var result = new string[]
21+
{
22+
"--Byte", PrimitiveTypeTestValues.Byte.ToString(),
23+
"--Short", PrimitiveTypeTestValues.Short.ToString(),
24+
"--Int", PrimitiveTypeTestValues.Int.ToString(),
25+
"--Long", PrimitiveTypeTestValues.Long.ToString(),
26+
27+
"--Float", PrimitiveTypeTestValues.Float.ToString(),
28+
"--Double", PrimitiveTypeTestValues.Double.ToString(),
29+
30+
"--Decimal", PrimitiveTypeTestValues.Decimal.ToString(),
31+
32+
"--Bool", PrimitiveTypeTestValues.Bool.ToString(),
33+
34+
"--DateTime", PrimitiveTypeTestValues.DateTime.ToString(),
35+
36+
"--Char", PrimitiveTypeTestValues.Char.ToString(),
37+
"--String", PrimitiveTypeTestValues.String.ToString(),
38+
39+
"--Toggle" /* No value after this one! */,
40+
41+
"--Required", PrimitiveTypeTestValues.Bool.ToString(),
42+
"--RequiredToggle",
43+
"--RequiredString", PrimitiveTypeTestValues.String.ToString(),
44+
};
45+
46+
return result;
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)