Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
akamsteeg committed Sep 18, 2019
2 parents b3934ee + bf0ff68 commit d775a89
Show file tree
Hide file tree
Showing 27 changed files with 506 additions and 147 deletions.
17 changes: 7 additions & 10 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
root = true

[*.cs]
indent_size = 2
indent_style = space
trim_trailing_whitespace = true
# Enable "this."
dotnet_style_qualification_for_field = true:warning
dotnet_style_qualification_for_property = true:warning
dotnet_style_qualification_for_method = true:warning
dotnet_style_qualification_for_method = true:warning

# use predefined type ("int") instead of framework names ("Int32")
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
dotnet_style_predefined_type_for_member_access = true:suggestion

# Access modifiers
dotnet_style_require_accessibility_modifiers = always:warning

#

[*.cs]
indent_size = 2
indent_style = space
trim_trailing_whitespace = true
dotnet_style_require_accessibility_modifiers = always:error
# Prefer "var"
csharp_style_var_for_built_in_types = true:suggestion
csharp_style_var_when_type_is_apparent = true:suggestion
Expand All @@ -28,3 +23,5 @@ csharp_style_pattern_matching_over_is_with_cast_check = true:warning
csharp_style_pattern_matching_over_as_with_null_check = true:warning
# Inline out variable
csharp_style_inlined_variable_declaration = true:warning
# Throw expressions
csharp_style_throw_expression = true:error
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ AtleX.CommandLineArguments is a helper library to facilitate parsing command lin
and customisable validators and the library can automatically generate help for the user.

Supported .NET frameworks:
* .NET 4.5
* NETSTANDARD 1.5
* .NET 4.6.1
* NETSTANDARD 2.0

# Installation

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp2.0;net46</TargetFrameworks>
<TargetFrameworks>netcoreapp2.0;net472</TargetFrameworks>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>

Expand All @@ -13,7 +13,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.10.14" />
<PackageReference Include="BenchmarkDotNet" Version="0.11.5" />
<Reference Include="System.ComponentModel.DataAnnotations" />
</ItemGroup>

Expand Down
14 changes: 7 additions & 7 deletions src/AtleX.CommandLineArguments.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using System;
using AtleX.CommandLineArguments.Benchmarks.Benches;
using AtleX.CommandLineArguments.Benchmarks.Benches;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Toolchains.CsProj;
using System;

namespace AtleX.CommandLineArguments.Benchmarks
{
class Program
internal class Program
{
static void Main(string[] args)
private static void Main(string[] args)
{
var config = GetConfig();
var benchmarks = GetBenchmarks();
Expand Down Expand Up @@ -40,9 +40,9 @@ private static IConfig GetConfig()

config.Add(MemoryDiagnoser.Default);

config.Add(Job.Default.With(CsProjCoreToolchain.NetCoreApp20));
config.Add(Job.Default.With(CsProjCoreToolchain.NetCoreApp21));
config.Add(Job.Default.With(CsProjClassicNetToolchain.Net462));
config.Add(Job.Default.With(CsProjCoreToolchain.NetCoreApp20).AsBaseline());
config.Add(Job.Default.With(CsProjCoreToolchain.NetCoreApp30));
config.Add(Job.Default.With(CsProjClassicNetToolchain.Net472));

return config;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net452;netcoreapp2.0;</TargetFrameworks>
<TargetFrameworks>net461;netcoreapp2.0;</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<None Remove="coverage.json" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="2.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="coverlet.msbuild" Version="2.6.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.analyzers " Version="0.9.0" />
<PackageReference Include="xunit.extensibility.execution" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<PackageReference Include="xunit.extensibility.execution" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<Reference Include="System.ComponentModel.DataAnnotations" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\AtleX.CommandLineArguments\AtleX.CommandLineArguments.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="xunit.analyzers" Version="0.10.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,27 +1,122 @@
using System;
using System.Collections.Generic;
using System.Linq;
using AtleX.CommandLineArguments.Configuration;
using AtleX.CommandLineArguments.Parsers.TypeParsers;
using AtleX.CommandLineArguments.Tests.Mocks;
using AtleX.CommandLineArguments.Validators;
using Xunit;

namespace AtleX.CommandLineArguments.Tests.Configuration
{
public class CommandLineArgumentsConfigurationTests
{
[Fact]
public void Ctor_WithNullIArgumentValidator_Throws()
{
Assert.Throws<ArgumentNullException>(() => new CommandLineArgumentsConfiguration((IArgumentValidator)null));
}

[Fact]
public void Ctor_WithIArgumentValidator_Succeeds()
{
var c = new CommandLineArgumentsConfiguration(new MockArgumentValidator());

Assert.Contains(c.Validators, v => v.GetType() == typeof(MockArgumentValidator));
}

[Fact]
public void Ctor_WithIArgumentValidators_Succeeds()
{
var c = new CommandLineArgumentsConfiguration(new[] { new MockArgumentValidator() });

Assert.Contains(c.Validators, v => v.GetType() == typeof(MockArgumentValidator));
}

[Fact]
public void Ctor_WithNullIArgumentValidators_Throws()
{
Assert.Throws<ArgumentNullException>(() => new CommandLineArgumentsConfiguration((IEnumerable<IArgumentValidator>)null));
}

[Fact]
public void Ctor_WithNullITypeParser_Throws()
{
Assert.Throws<ArgumentNullException>(() => new CommandLineArgumentsConfiguration((ITypeParser)null));
}

[Fact]
public void Ctor_WithITypeParser_Succeeds()
{
var c = new CommandLineArgumentsConfiguration(new MockTypeParser());

Assert.Contains(c.TypeParsers, p => p.GetType() == typeof(MockTypeParser));
}

[Fact]
public void Ctor_WithITypeParsers_Succeeds()
{
var c = new CommandLineArgumentsConfiguration(new[] { new MockTypeParser() });

Assert.Contains(c.TypeParsers, p => p.GetType() == typeof(MockTypeParser));
}

[Fact]
public void Ctor_WithNullITypeParsers_Throws()
{
Assert.Throws<ArgumentNullException>(() => new CommandLineArgumentsConfiguration((IEnumerable<ITypeParser>)null));
}

[Fact]
public void Add_ArgumentValidator_WithNull_Throws()
{
var config = new CommandLineArgumentsConfiguration();

Assert.Throws<ArgumentNullException>(() => config.Add((IArgumentValidator)null));
}

[Fact]
public void Add_TypeParser_WithNull_Throws()
{
var config = new CommandLineArgumentsConfiguration();

Assert.Throws<ArgumentNullException>(() => config.Add((TypeParser)null));
Assert.Throws<ArgumentNullException>(() => config.Add((ITypeParser)null));
}

[Fact]
public void Add_ArgumentValidator_WithNull_Throws()
public void AddRange_ArgumentValidators_WithNull_Throws()
{
var config = new CommandLineArgumentsConfiguration();

Assert.Throws<ArgumentNullException>(() => config.AddRange((IEnumerable<IArgumentValidator>)null));
}

[Fact]
public void AddRange_ArgumentValidators_WithValidValidator_Succeeds()
{
var config = new CommandLineArgumentsConfiguration();

config.AddRange(new[] { new MockArgumentValidator() });

Assert.Contains(config.Validators, v => v.GetType() == typeof(MockArgumentValidator));
}

[Fact]
public void AddRange_TypeParsers_WithNull_Throws()
{
var config = new CommandLineArgumentsConfiguration();

Assert.Throws<ArgumentNullException>(() => config.AddRange((IEnumerable<ITypeParser>)null));
}

[Fact]
public void AddRange_TypeParsers_WithValidParser_Succeeds()
{
var config = new CommandLineArgumentsConfiguration();

Assert.Throws<ArgumentNullException>(() => config.Add((ArgumentValidator)null));
config.AddRange(new[] { new MockTypeParser() });

Assert.Contains(config.TypeParsers, p => p.GetType() == typeof(MockTypeParser));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using AtleX.CommandLineArguments.Validators;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace AtleX.CommandLineArguments.Tests.Mocks
{
public class MockArgumentValidator
: IArgumentValidator
{
public bool TryValidate(PropertyInfo argumentPropertyInfo, bool isSpecified, string originalValue, out ValidationError validationError)
{
validationError = null;
return true;
}
}
}
2 changes: 1 addition & 1 deletion src/AtleX.CommandLineArguments.Tests/Mocks/MockParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace AtleX.CommandLineArguments.Tests.Mocks
public sealed class MockParser
: ICommandLineArgumentsParser
{
public ParseResult<T> Parse<T>(string[] arguments, IEnumerable<ArgumentValidator> validators, IEnumerable<TypeParser> typeParsers) where T : Arguments, new()
public ParseResult<T> Parse<T>(string[] arguments, IEnumerable<IArgumentValidator> validators, IEnumerable<ITypeParser> typeParsers) where T : Arguments, new()
{
throw new NotImplementedException();
}
Expand Down
22 changes: 22 additions & 0 deletions src/AtleX.CommandLineArguments.Tests/Mocks/MockTypeParser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using AtleX.CommandLineArguments.Parsers.TypeParsers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtleX.CommandLineArguments.Tests.Mocks
{
public class MockTypeParser
: ITypeParser
{
public Type Type => typeof(string);

public bool TryParse(string value, out object parseResult)
{
parseResult = value;

return true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using AtleX.CommandLineArguments.Parsers;
using AtleX.CommandLineArguments.Validators;
using System.Linq;
using Xunit;

namespace AtleX.CommandLineArguments.Tests.Parsers
{

[Collection("NotInParallel")]
public class PrefixedKeyParserTests
: CommandLineArgumentsParserTests
{
public PrefixedKeyParserTests()
: base(new PrefixedKeyParser("--"), Enumerable.Empty<ArgumentValidator>())
{
}

protected override string[] CreateValidArguments()
{
var result = new string[]
{
"--Byte", PrimitiveTypeTestValues.Byte.ToString(),
"--Short", PrimitiveTypeTestValues.Short.ToString(),
"--Int", PrimitiveTypeTestValues.Int.ToString(),
"--Long", PrimitiveTypeTestValues.Long.ToString(),

"--Float", PrimitiveTypeTestValues.Float.ToString(),
"--Double", PrimitiveTypeTestValues.Double.ToString(),

"--Decimal", PrimitiveTypeTestValues.Decimal.ToString(),

"--Bool", PrimitiveTypeTestValues.Bool.ToString(),

"--DateTime", PrimitiveTypeTestValues.DateTime.ToString(),

"--Char", PrimitiveTypeTestValues.Char.ToString(),
"--String", PrimitiveTypeTestValues.String.ToString(),

"--Toggle" /* No value after this one! */,

"--Required", PrimitiveTypeTestValues.Bool.ToString(),
"--RequiredToggle",
"--RequiredString", PrimitiveTypeTestValues.String.ToString(),
};

return result;
}
}
}
Loading

0 comments on commit d775a89

Please sign in to comment.