Skip to content

Commit 813e84d

Browse files
committed
Added tests for new functionality
1 parent c35d2ca commit 813e84d

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

Utility.CommandLine.Arguments.Tests/Arguments.cs

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,55 @@ public void PopulateOperands()
684684
#endregion Public Methods
685685
}
686686

687+
/// <summary>
688+
/// Unit tests for the <see cref="CommandLine.Arguments"/> class.
689+
/// </summary>
690+
/// <remarks>Used to facilitate testing of a class with an array property.</remarks>
691+
[Collection("Arguments")]
692+
public class TestClassWithArrayProperty
693+
{
694+
#region Private Properties
695+
696+
[CommandLine.Argument('a', "array")]
697+
private static string[] Array { get; set; }
698+
699+
#endregion Private Properties
700+
701+
#region Public Methods
702+
703+
/// <summary>
704+
/// Tests the <see cref="Utility.CommandLine.Arguments.Populate(Type, string)"/> method with an explicit string
705+
/// containing multiple instances of the same argument.
706+
/// </summary>
707+
[Fact]
708+
public void Populate()
709+
{
710+
Exception ex = Record.Exception(() => CommandLine.Arguments.Populate(GetType(), "-a one -a two -a three"));
711+
712+
Assert.Null(ex);
713+
Assert.Equal(3, Array.Length);
714+
Assert.Equal("one", Array[0]);
715+
Assert.Equal("two", Array[1]);
716+
Assert.Equal("three", Array[2]);
717+
}
718+
719+
/// <summary>
720+
/// Tests the <see cref="Utility.CommandLine.Arguments.Populate(Type, string)"/> method with an explicit string
721+
/// containing a single a single instance of an array-backed argument.
722+
/// </summary>
723+
[Fact]
724+
public void PopulateSingle()
725+
{
726+
Exception ex = Record.Exception(() => CommandLine.Arguments.Populate(GetType(), "-a one"));
727+
728+
Assert.Null(ex);
729+
Assert.Equal(1, Array.Length);
730+
Assert.Equal("one", Array[0]);
731+
}
732+
733+
#endregion Public Methods
734+
}
735+
687736
/// <summary>
688737
/// Unit tests for the <see cref="CommandLine.Arguments"/> class.
689738
/// </summary>
@@ -722,6 +771,55 @@ public void PopulateOperands()
722771
#endregion Public Methods
723772
}
724773

774+
/// <summary>
775+
/// Unit tests for the <see cref="CommandLine.Arguments"/> class.
776+
/// </summary>
777+
/// <remarks>Used to facilitate testing of a class with a List{T} property.</remarks>
778+
[Collection("Arguments")]
779+
public class TestClassWithListProperty
780+
{
781+
#region Private Properties
782+
783+
[CommandLine.Argument('l', "list")]
784+
private static List<string> List { get; set; }
785+
786+
#endregion Private Properties
787+
788+
#region Public Methods
789+
790+
/// <summary>
791+
/// Tests the <see cref="Utility.CommandLine.Arguments.Populate(Type, string)"/> method with an explicit string
792+
/// containing multiple instances of a list-backed argument.
793+
/// </summary>
794+
[Fact]
795+
public void Populate()
796+
{
797+
Exception ex = Record.Exception(() => CommandLine.Arguments.Populate(GetType(), "-l one -l two -l three"));
798+
799+
Assert.Null(ex);
800+
Assert.Equal(3, List.Count);
801+
Assert.Equal("one", List[0]);
802+
Assert.Equal("two", List[1]);
803+
Assert.Equal("three", List[2]);
804+
}
805+
806+
/// <summary>
807+
/// Tests the <see cref="Utility.CommandLine.Arguments.Populate(Type, string)"/> method with an explicit string
808+
/// containing a single a single instance of a list-backed argument.
809+
/// </summary>
810+
[Fact]
811+
public void PopulateSingle()
812+
{
813+
Exception ex = Record.Exception(() => CommandLine.Arguments.Populate(GetType(), "-l one"));
814+
815+
Assert.Null(ex);
816+
Assert.Equal(1, List.Count);
817+
Assert.Equal("one", List[0]);
818+
}
819+
820+
#endregion Public Methods
821+
}
822+
725823
/// <summary>
726824
/// Unit tests for the <see cref="CommandLine.Arguments"/> class.
727825
/// </summary>

0 commit comments

Comments
 (0)