1
1
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2
2
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
4
+ using FluentAssertions ;
4
5
using System . Collections ;
5
6
using System . Collections . Generic ;
6
7
using System . CommandLine . Utility ;
7
8
using System . IO ;
8
- using FluentAssertions ;
9
9
using System . Linq ;
10
- using Xunit ;
11
10
using System . Net ;
11
+ using Xunit ;
12
12
13
13
namespace System . CommandLine . Tests . Binding
14
14
{
@@ -230,7 +230,7 @@ public void Nullable_bool_parses_as_false_when_the_option_has_been_applied(strin
230
230
public void Nullable_bool_parses_as_null_when_the_option_has_not_been_applied ( )
231
231
{
232
232
var option = new Option < bool ? > ( "-x" ) ;
233
-
233
+
234
234
option
235
235
. Parse ( "" )
236
236
. GetValueForOption ( option )
@@ -252,7 +252,7 @@ public void Generic_option_bool_parses_when_passed_to_non_generic_GetValueForOpt
252
252
253
253
parseResult . GetValueForOption ( ( Option ) option ) . Should ( ) . Be ( true ) ;
254
254
}
255
-
255
+
256
256
[ Fact ]
257
257
public void When_exactly_one_argument_is_expected_and_none_are_provided_then_getting_value_throws ( )
258
258
{
@@ -274,7 +274,7 @@ public void When_exactly_one_argument_is_expected_and_none_are_provided_then_get
274
274
. Should ( )
275
275
. Be ( "Required argument missing for option: '-x'." ) ;
276
276
}
277
-
277
+
278
278
[ Theory ]
279
279
[ InlineData ( "c -a o c c" ) ]
280
280
[ InlineData ( "c c -a o c" ) ]
@@ -496,7 +496,7 @@ public void Values_can_be_correctly_converted_to_decimal_without_the_parser_spec
496
496
497
497
value . Should ( ) . Be ( 123.456m ) ;
498
498
}
499
-
499
+
500
500
[ Fact ]
501
501
public void Values_can_be_correctly_converted_to_nullable_decimal_without_the_parser_specifying_a_custom_converter ( )
502
502
{
@@ -506,7 +506,7 @@ public void Values_can_be_correctly_converted_to_nullable_decimal_without_the_pa
506
506
507
507
value . Should ( ) . Be ( 123.456m ) ;
508
508
}
509
-
509
+
510
510
[ Fact ]
511
511
public void Values_can_be_correctly_converted_to_double_without_the_parser_specifying_a_custom_converter ( )
512
512
{
@@ -516,7 +516,7 @@ public void Values_can_be_correctly_converted_to_double_without_the_parser_speci
516
516
517
517
value . Should ( ) . Be ( 123.456d ) ;
518
518
}
519
-
519
+
520
520
[ Fact ]
521
521
public void Values_can_be_correctly_converted_to_nullable_double_without_the_parser_specifying_a_custom_converter ( )
522
522
{
@@ -536,7 +536,7 @@ public void Values_can_be_correctly_converted_to_float_without_the_parser_specif
536
536
537
537
value . Should ( ) . Be ( 123.456f ) ;
538
538
}
539
-
539
+
540
540
[ Fact ]
541
541
public void Values_can_be_correctly_converted_to_nullable_float_without_the_parser_specifying_a_custom_converter ( )
542
542
{
@@ -557,7 +557,7 @@ public void Values_can_be_correctly_converted_to_Guid_without_the_parser_specify
557
557
558
558
value . Should ( ) . Be ( Guid . Parse ( guidString ) ) ;
559
559
}
560
-
560
+
561
561
[ Fact ]
562
562
public void Values_can_be_correctly_converted_to_nullable_Guid_without_the_parser_specifying_a_custom_converter ( )
563
563
{
@@ -689,7 +689,7 @@ public void Values_can_be_correctly_converted_to_nullable_ushort_without_the_par
689
689
690
690
value . Should ( ) . Be ( 1234 ) ;
691
691
}
692
-
692
+
693
693
[ Fact ]
694
694
public void Values_can_be_correctly_converted_to_sbyte_without_the_parser_specifying_a_custom_converter ( )
695
695
{
@@ -699,7 +699,7 @@ public void Values_can_be_correctly_converted_to_sbyte_without_the_parser_specif
699
699
700
700
value . Should ( ) . Be ( 123 ) ;
701
701
}
702
-
702
+
703
703
[ Fact ]
704
704
public void Values_can_be_correctly_converted_to_nullable_sbyte_without_the_parser_specifying_a_custom_converter ( )
705
705
{
@@ -732,6 +732,48 @@ public void Values_can_be_correctly_converted_to_ipendpoint_without_the_parser_s
732
732
}
733
733
#endif
734
734
735
+ #if NET6_0_OR_GREATER
736
+ [ Fact ]
737
+ public void Values_can_be_correctly_converted_to_dateonly_without_the_parser_specifying_a_custom_converter ( )
738
+ {
739
+ var option = new Option < DateOnly > ( "-us" ) ;
740
+
741
+ var value = option . Parse ( "-us 2022-03-02" ) . GetValueForOption ( option ) ;
742
+
743
+ value . Should ( ) . Be ( DateOnly . Parse ( "2022-03-02" ) ) ;
744
+ }
745
+
746
+ [ Fact ]
747
+ public void Values_can_be_correctly_converted_to_nullable_dateonly_without_the_parser_specifying_a_custom_converter ( )
748
+ {
749
+ var option = new Option < DateOnly ? > ( "-x" ) ;
750
+
751
+ var value = option . Parse ( "-x 2022-03-02" ) . GetValueForOption ( option ) ;
752
+
753
+ value . Should ( ) . Be ( DateOnly . Parse ( "2022-03-02" ) ) ;
754
+ }
755
+
756
+ [ Fact ]
757
+ public void Values_can_be_correctly_converted_to_timeonly_without_the_parser_specifying_a_custom_converter ( )
758
+ {
759
+ var option = new Option < TimeOnly > ( "-us" ) ;
760
+
761
+ var value = option . Parse ( "-us 12:34:56" ) . GetValueForOption ( option ) ;
762
+
763
+ value . Should ( ) . Be ( TimeOnly . Parse ( "12:34:56" ) ) ;
764
+ }
765
+
766
+ [ Fact ]
767
+ public void Values_can_be_correctly_converted_to_nullable_timeonly_without_the_parser_specifying_a_custom_converter ( )
768
+ {
769
+ var option = new Option < TimeOnly ? > ( "-x" ) ;
770
+
771
+ var value = option . Parse ( "-x 12:34:56" ) . GetValueForOption ( option ) ;
772
+
773
+ value . Should ( ) . Be ( TimeOnly . Parse ( "12:34:56" ) ) ;
774
+ }
775
+ #endif
776
+
735
777
[ Fact ]
736
778
public void Values_can_be_correctly_converted_to_byte_without_the_parser_specifying_a_custom_converter ( )
737
779
{
@@ -741,7 +783,7 @@ public void Values_can_be_correctly_converted_to_byte_without_the_parser_specify
741
783
742
784
value . Should ( ) . Be ( 123 ) ;
743
785
}
744
-
786
+
745
787
[ Fact ]
746
788
public void Values_can_be_correctly_converted_to_nullable_byte_without_the_parser_specifying_a_custom_converter ( )
747
789
{
@@ -751,7 +793,7 @@ public void Values_can_be_correctly_converted_to_nullable_byte_without_the_parse
751
793
752
794
value . Should ( ) . Be ( 123 ) ;
753
795
}
754
-
796
+
755
797
[ Fact ]
756
798
public void Values_can_be_correctly_converted_to_uint_without_the_parser_specifying_a_custom_converter ( )
757
799
{
@@ -761,7 +803,7 @@ public void Values_can_be_correctly_converted_to_uint_without_the_parser_specify
761
803
762
804
value . Should ( ) . Be ( 1234 ) ;
763
805
}
764
-
806
+
765
807
[ Fact ]
766
808
public void Values_can_be_correctly_converted_to_nullable_uint_without_the_parser_specifying_a_custom_converter ( )
767
809
{
@@ -781,7 +823,7 @@ public void Values_can_be_correctly_converted_to_array_of_int_without_the_parser
781
823
782
824
value . Should ( ) . BeEquivalentTo ( 1 , 2 , 3 ) ;
783
825
}
784
-
826
+
785
827
[ Theory ]
786
828
[ InlineData ( 0 , 100_000 , typeof ( string [ ] ) ) ]
787
829
[ InlineData ( 0 , 3 , typeof ( string [ ] ) ) ]
@@ -793,7 +835,7 @@ public void Values_can_be_correctly_converted_to_array_of_int_without_the_parser
793
835
[ InlineData ( 0 , 3 , typeof ( IList < string > ) ) ]
794
836
[ InlineData ( 0 , 100_000 , typeof ( ICollection < string > ) ) ]
795
837
[ InlineData ( 0 , 3 , typeof ( ICollection < string > ) ) ]
796
-
838
+
797
839
[ InlineData ( 1 , 100_000 , typeof ( string [ ] ) ) ]
798
840
[ InlineData ( 1 , 3 , typeof ( string [ ] ) ) ]
799
841
[ InlineData ( 1 , 100_000 , typeof ( IEnumerable < string > ) ) ]
0 commit comments