Skip to content

Commit

Permalink
Added multi value tests for arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilal Fazlani committed Jan 9, 2018
1 parent 338bdc5 commit 5f22ba0
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 2 deletions.
102 changes: 102 additions & 0 deletions CommandDotNet.Tests/MultiValueArgumentsTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using System;
using System.Collections.Generic;
using CommandDotNet.Attributes;
using FluentAssertions;
using Xunit;
using Xunit.Abstractions;

namespace CommandDotNet.Tests
{
public class MultiValueArgumentsTest : TestBase
{
public MultiValueArgumentsTest(ITestOutputHelper testOutputHelper) : base(testOutputHelper)
{

}

[Theory]
[InlineData("stringList", "john", "doe")]
[InlineData("intList", "3", "5")]
[InlineData("doubleList", "4.5", "2.3")]
[InlineData("enumList", "Thursday", "Tuesday")]
[InlineData("charList", "d", "y")]
[InlineData("longList", "123123", "456456534")]
public void CanRecogniseListWhenPassedInWithMultipleArguments(
string commandName, string option1Value, string option2Value)
{
AppRunner<MultiValueArgumentApp> appRunner = new AppRunner<MultiValueArgumentApp>();
int exitCode = appRunner.Run(new[] {commandName, option1Value, option2Value });
exitCode.Should().Be(2, "length of parameters passed is 2");
}
}

public class MultiValueArgumentApp
{
public int stringList(List<string> values)
{
foreach (var value in values)
{
Console.WriteLine(value);
}

values.Should().HaveCount(2);
values[0].Should().NotBe(values[1]);
return values.Count;
}

public int intList(List<int> values)
{
foreach (var value in values)
{
Console.WriteLine(value);
}
values.Should().HaveCount(2);
values[0].Should().NotBe(values[1]);
return values.Count;
}

public int doubleList(List<double> values)
{
foreach (var value in values)
{
Console.WriteLine(value);
}
values.Should().HaveCount(2);
values[0].Should().NotBe(values[1]);
return values.Count;
}

public int longList(List<long> values)
{
foreach (var value in values)
{
Console.WriteLine(value);
}
values.Should().HaveCount(2);
values[0].Should().NotBe(values[1]);
return values.Count;
}

public int enumList(List<DayOfWeek> values)
{
foreach (var value in values)
{
Console.WriteLine(value);
}
values.Should().HaveCount(2);
values[0].Should().NotBe(values[1]);
return values.Count;
}

public int charList(List<char> values)
{
foreach (var value in values)
{
Console.WriteLine(value);
}
values.Should().HaveCount(2);
values[0].Should().NotBe(values[1]);
return values.Count;
}
}
}
4 changes: 2 additions & 2 deletions CommandDotNet.Tests/MultiValueOptionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ public MultiValueOptionsTest(ITestOutputHelper testOutputHelper) : base(testOutp
public void CanRecogniseListWhenPassedInWithMultipleArguments(
string commandName, string optionName, string option1Value, string option2Value)
{
AppRunner<MultiValueApp> appRunner = new AppRunner<MultiValueApp>();
AppRunner<MultiValueOptionsApp> appRunner = new AppRunner<MultiValueOptionsApp>();
int exitCode = appRunner.Run(new[] {commandName, optionName, option1Value,
optionName, option2Value });
exitCode.Should().Be(2, "length of parameters passed is 2");
}
}

public class MultiValueApp
public class MultiValueOptionsApp
{
public int stringList([Option(ShortName = "v")] List<string> values)
{
Expand Down

0 comments on commit 5f22ba0

Please sign in to comment.