-
Notifications
You must be signed in to change notification settings - Fork 24
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
9 changed files
with
327 additions
and
2 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
49 changes: 49 additions & 0 deletions
49
src/shell/dotnet/tests/Shell.Tests/CommandLineParserAttributedPropertyTests.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 Shell.Utilities; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShellTests | ||
{ | ||
public class CommandLineParserAttributedPropertyTests | ||
{ | ||
public class AttributedOptions | ||
{ | ||
[Display(Name = "opt", Description = "Option with overwritten name")] | ||
public string RenamedOption { get; set; } | ||
|
||
[Display(Description = "Just a description")] | ||
public string Option { get; set; } | ||
} | ||
|
||
[Fact] | ||
public void TestParsingRenamedOption() | ||
{ | ||
var testValue = Guid.NewGuid().ToString(); | ||
var options = CommandLineParser.Parse<AttributedOptions>(new[] { "--opt", testValue }); | ||
Assert.NotNull(options); | ||
Assert.Equal(testValue.ToString(), options.RenamedOption); | ||
} | ||
|
||
[Fact] | ||
public void TestParsingRenamedOptionWithOriginalName() | ||
{ | ||
var testValue = Guid.NewGuid().ToString(); | ||
var options = CommandLineParser.Parse<AttributedOptions>(new[] { "--renamedOption", testValue }); | ||
Assert.NotNull(options); | ||
Assert.Null(options.RenamedOption); | ||
} | ||
|
||
[Fact] | ||
public void TestParsingOptionWithDescription() | ||
{ | ||
var testValue = Guid.NewGuid().ToString(); | ||
var options = CommandLineParser.Parse<AttributedOptions>(new[] { "--option", testValue }); | ||
Assert.NotNull(options); | ||
Assert.Equal(testValue.ToString(), options.Option); | ||
} | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
src/shell/dotnet/tests/Shell.Tests/CommandLineParserCustomPropertyDoubleTests.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,71 @@ | ||
using Shell.Utilities; | ||
|
||
namespace ShellTests | ||
{ | ||
public class CommandLineParserCustomPropertyDoubleTests | ||
{ | ||
private static readonly Random Random = new Random(); | ||
private static readonly double Default = Random.NextDouble(); | ||
|
||
/// <summary> | ||
/// Get a test value that's different from the default value | ||
/// </summary> | ||
/// <returns></returns> | ||
private static double GetTestValue() | ||
{ | ||
var x = Random.NextDouble(); | ||
while (x == Default) { x = Random.NextDouble(); } | ||
return x; | ||
} | ||
|
||
public class CustomPropertyDoubleOptions | ||
{ | ||
private double _option = Default; | ||
public double? Option | ||
{ | ||
get { return _option; } | ||
set { _option = value ?? Default; } | ||
} | ||
} | ||
|
||
[Fact] | ||
public void TestParseCustomPropertyDoubleWithEmptyParameterList() | ||
{ | ||
var options = CommandLineParser.Parse<CustomPropertyDoubleOptions>(new string[0]); | ||
Assert.NotNull(options); | ||
Assert.Equal(Default, options.Option); | ||
} | ||
|
||
[Fact] | ||
public void TestParseCustomPropertyDoubleWithValueProvided() | ||
{ | ||
var testValue = GetTestValue(); | ||
var options = CommandLineParser.Parse<CustomPropertyDoubleOptions>(new[] { "--option", testValue.ToString() }); | ||
Assert.NotNull(options); | ||
Assert.Equal(testValue, options.Option); | ||
} | ||
|
||
[Fact] | ||
public void TestParseCustomPropertyDoubleWithoutValue() | ||
{ | ||
Assert.Throws<InvalidOperationException>(() => CommandLineParser.Parse<CustomPropertyDoubleOptions>(new[] { "--option" })); | ||
} | ||
|
||
[Fact] | ||
public void TestParseCustomPropertyDoubleWithOnlyDifferentParameter() | ||
{ | ||
var options = CommandLineParser.Parse<CustomPropertyDoubleOptions>(new[] { "--stuff", GetTestValue().ToString() }); | ||
Assert.NotNull(options); | ||
Assert.Equal(Default, options.Option); | ||
} | ||
|
||
[Fact] | ||
public void TestParseCustomPropertyDoubleWithOtherParameters() | ||
{ | ||
var testValue = GetTestValue(); | ||
var options = CommandLineParser.Parse<CustomPropertyDoubleOptions>(new[] { "--firstParam", GetTestValue().ToString(), "--option", testValue.ToString(), "--lastParam", GetTestValue().ToString() }); | ||
Assert.NotNull(options); | ||
Assert.Equal(testValue, options.Option); | ||
} | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
src/shell/dotnet/tests/Shell.Tests/CommandLineParserCustomPropertyStringTests.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,59 @@ | ||
using Shell.Utilities; | ||
|
||
namespace ShellTests | ||
{ | ||
public class CommandLineParserCustomPropertyStringTests | ||
{ | ||
private const string Default = "default"; | ||
public class CustomPropertyStringOptions | ||
{ | ||
private string? _option = null; | ||
public string? Option | ||
{ | ||
get { return _option ?? Default; } | ||
set { _option = value; } | ||
} | ||
} | ||
|
||
[Fact] | ||
public void TestParseSimpleStringWithEmptyParameterList() | ||
{ | ||
var options = CommandLineParser.Parse<CustomPropertyStringOptions>(new string[0]); | ||
Assert.NotNull(options); | ||
Assert.Equal(Default, options.Option); | ||
} | ||
|
||
[Fact] | ||
public void TestParseSimpleStringWithValueProvided() | ||
{ | ||
var testValue = Guid.NewGuid(); | ||
var options = CommandLineParser.Parse<CustomPropertyStringOptions>(new[] { "--option", testValue.ToString() }); | ||
Assert.NotNull(options); | ||
Assert.Equal(testValue.ToString(), options.Option); | ||
} | ||
|
||
[Fact] | ||
public void TestParseSimpleStringWithoutValue() | ||
{ | ||
var testValue = Guid.NewGuid(); | ||
Assert.Throws<InvalidOperationException>(() => CommandLineParser.Parse<CustomPropertyStringOptions>(new[] { "--option" })); | ||
} | ||
|
||
[Fact] | ||
public void TestParseSimpleStringWithOnlyDifferentParameter() | ||
{ | ||
var options = CommandLineParser.Parse<CustomPropertyStringOptions>(new[] { "--stuff", "irrelevant" }); | ||
Assert.NotNull(options); | ||
Assert.Equal(Default, options.Option); | ||
} | ||
|
||
[Fact] | ||
public void TestParseSimpleStringWithOtherParameters() | ||
{ | ||
var testValue = Guid.NewGuid(); | ||
var options = CommandLineParser.Parse<CustomPropertyStringOptions>(new[] { "--firstParam", "irrelevant", "--option", testValue.ToString(), "--lastParam", "irrelevant" }); | ||
Assert.NotNull(options); | ||
Assert.Equal(testValue.ToString(), options.Option); | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/shell/dotnet/tests/Shell.Tests/CommandLineParserSimpleDoubleTests.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,55 @@ | ||
using Shell.Utilities; | ||
using System.Globalization; | ||
|
||
namespace ShellTests | ||
{ | ||
public class CommandLineParserSimpleDoubleTests | ||
{ | ||
private static readonly Random Random = new Random(); | ||
|
||
public class SimpleDoubleOptions | ||
{ | ||
public double? Option { get; set; } | ||
} | ||
|
||
[Fact] | ||
public void TestParseSimpleDoubleWithEmptyParameterList() | ||
{ | ||
var options = CommandLineParser.Parse<SimpleDoubleOptions>(new string[0]); | ||
Assert.NotNull(options); | ||
Assert.Null(options.Option); | ||
} | ||
|
||
[Fact] | ||
public void TestParseSimpleDoubleWithValueProvided() | ||
{ | ||
var testValue = Random.NextDouble(); | ||
var options = CommandLineParser.Parse<SimpleDoubleOptions>(new[] { "--option", testValue.ToString() }); | ||
Assert.NotNull(options); | ||
Assert.Equal(testValue, options.Option); | ||
} | ||
|
||
[Fact] | ||
public void TestParseSimpleDoubleWithoutValue() | ||
{ | ||
Assert.Throws<InvalidOperationException>(() => CommandLineParser.Parse<SimpleDoubleOptions>(new[] { "--option" })); | ||
} | ||
|
||
[Fact] | ||
public void TestParseSimpleDoubleWithOnlyDifferentParameter() | ||
{ | ||
var options = CommandLineParser.Parse<SimpleDoubleOptions>(new[] { "--stuff", Random.NextDouble().ToString() }); | ||
Assert.NotNull(options); | ||
Assert.Null(options.Option); | ||
} | ||
|
||
[Fact] | ||
public void TestParseSimpleDoubleWithOtherParameters() | ||
{ | ||
var testValue = Random.NextDouble(); | ||
var options = CommandLineParser.Parse<SimpleDoubleOptions>(new[] { "--firstParam", Random.NextDouble().ToString(), "--option", testValue.ToString(), "--lastParam", Random.NextDouble().ToString() }); | ||
Assert.NotNull(options); | ||
Assert.Equal(testValue, options.Option); | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/shell/dotnet/tests/Shell.Tests/CommandLineParserSimpleStringTests.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,53 @@ | ||
using Shell.Utilities; | ||
|
||
namespace ShellTests | ||
{ | ||
public class CommandLineParserSimpleStringTests | ||
{ | ||
public class SimpleStringOptions | ||
{ | ||
public string? Option { get; set; } | ||
} | ||
|
||
[Fact] | ||
public void TestParseSimpleStringWithEmptyParameterList() | ||
{ | ||
var options = CommandLineParser.Parse<SimpleStringOptions>(new string[0]); | ||
Assert.NotNull(options); | ||
Assert.Null(options.Option); | ||
} | ||
|
||
[Fact] | ||
public void TestParseSimpleStringWithValueProvided() | ||
{ | ||
var testValue = Guid.NewGuid(); | ||
var options = CommandLineParser.Parse<SimpleStringOptions>(new[] { "--option", testValue.ToString() }); | ||
Assert.NotNull(options); | ||
Assert.Equal(testValue.ToString(), options.Option); | ||
} | ||
|
||
[Fact] | ||
public void TestParseSimpleStringWithoutValue() | ||
{ | ||
var testValue = Guid.NewGuid(); | ||
Assert.Throws<InvalidOperationException>(() => CommandLineParser.Parse<SimpleStringOptions>(new[] { "--option" })); | ||
} | ||
|
||
[Fact] | ||
public void TestParseSimpleStringWithOnlyDifferentParameter() | ||
{ | ||
var options = CommandLineParser.Parse<SimpleStringOptions>(new[] { "--stuff", "irrelevant" }); | ||
Assert.NotNull(options); | ||
Assert.Null(options.Option); | ||
} | ||
|
||
[Fact] | ||
public void TestParseSimpleStringWithOtherParameters() | ||
{ | ||
var testValue = Guid.NewGuid(); | ||
var options = CommandLineParser.Parse<SimpleStringOptions>(new[] { "--firstParam", "irrelevant", "--option", testValue.ToString(), "--lastParam", "irrelevant" }); | ||
Assert.NotNull(options); | ||
Assert.Equal(testValue.ToString(), options.Option); | ||
} | ||
} | ||
} |
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,28 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0-windows</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" /> | ||
<PackageReference Include="xunit" Version="2.4.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.1.2"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\Shell\Shell.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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 @@ | ||
global using Xunit; |