-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
506 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 16 additions & 6 deletions
22
src/AtleX.CommandLineArguments.Tests/AtleX.CommandLineArguments.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
101 changes: 98 additions & 3 deletions
101
src/AtleX.CommandLineArguments.Tests/Configuration/CommandLineArgumentsConfigurationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/AtleX.CommandLineArguments.Tests/Mocks/MockArgumentValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/AtleX.CommandLineArguments.Tests/Mocks/MockTypeParser.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/AtleX.CommandLineArguments.Tests/Parsers/PrefixedKeyParserTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
Oops, something went wrong.