1- using CodingFlow . FluentValidation . Validators ;
1+ using System . ComponentModel . DataAnnotations ;
2+ using System . Numerics ;
3+ using CodingFlow . FluentValidation . Validators ;
24using FluentAssertions ;
35using static CodingFlow . FluentValidation . Validations ;
46
57namespace CodingFlow . FluentValidation . UnitTests ;
68
79public class BetweenInclusiveValidatorTests
810{
9- [ TestCase ( 4 ) ]
10- [ TestCase ( 5 ) ]
11- [ TestCase ( 6 ) ]
12- public void BetweenInclusive_Integer_Valid ( int input )
13- {
14- var result = RuleFor ( input )
15- . BetweenInclusive ( 4 , 6 )
16- . Result ( ) ;
11+ private static readonly object [ ] BetweenInclusive_Valid_Cases = [
12+ new short [ ] { 5 , 4 , 6 } ,
13+ new short [ ] { 4 , 4 , 6 } ,
14+ new short [ ] { 6 , 4 , 6 } ,
1715
18- result . Should ( ) . BeEquivalentTo ( new ValidationResult
19- {
20- IsValid = true ,
21- Errors = [ ]
22- } ) ;
23- }
16+ new ushort [ ] { 5 , 4 , 6 } ,
17+ new ushort [ ] { 4 , 4 , 6 } ,
18+ new ushort [ ] { 6 , 4 , 6 } ,
19+
20+ new sbyte [ ] { 5 , 4 , 6 } ,
21+ new sbyte [ ] { 4 , 4 , 6 } ,
22+ new sbyte [ ] { 6 , 4 , 6 } ,
23+
24+ new byte [ ] { 5 , 4 , 6 } ,
25+ new byte [ ] { 4 , 4 , 6 } ,
26+ new byte [ ] { 6 , 4 , 6 } ,
2427
25- [ TestCase ( 4f ) ]
26- [ TestCase ( 5f ) ]
27- [ TestCase ( 6f ) ]
28- public void BetweenInclusive_Float_Valid ( float input )
28+ new decimal [ ] { 5.5m , 5.4m , 5.6m } ,
29+ new decimal [ ] { 5.4m , 5.4m , 5.6m } ,
30+ new decimal [ ] { 5.6m , 5.4m , 5.6m } ,
31+ ] ;
32+
33+ [ TestCase ( 5 , 4 , 6 ) ] [ TestCase ( 4 , 4 , 6 ) ] [ TestCase ( 6 , 4 , 6 ) ]
34+ [ TestCase ( 5u , 4u , 6u ) ] [ TestCase ( 4u , 4u , 6u ) ] [ TestCase ( 6u , 4u , 6u ) ]
35+ [ TestCase ( 5L , 4L , 6L ) ] [ TestCase ( 4L , 4L , 6L ) ] [ TestCase ( 6L , 4L , 6L ) ]
36+ [ TestCase ( 5ul , 4ul , 6ul ) ] [ TestCase ( 4ul , 4ul , 6ul ) ] [ TestCase ( 6ul , 4ul , 6ul ) ]
37+ [ TestCase ( 5.5f , 5.4f , 5.6f ) ] [ TestCase ( 5.4f , 5.4f , 5.6f ) ] [ TestCase ( 5.6f , 5.4f , 5.6f ) ]
38+ [ TestCase ( 5.5d , 5.4d , 5.6d ) ] [ TestCase ( 5.4d , 5.4d , 5.6d ) ] [ TestCase ( 5.6d , 5.4d , 5.6d ) ]
39+ [ TestCaseSource ( nameof ( BetweenInclusive_Valid_Cases ) ) ]
40+ public void BetweenInclusive_Valid < T > ( T input , T minimum , T maximum )
41+ where T : INumber < T >
2942 {
3043 var result = RuleFor ( input )
31- . BetweenInclusive ( 4f , 6f )
44+ . BetweenInclusive ( minimum , maximum )
3245 . Result ( ) ;
3346
3447 result . Should ( ) . BeEquivalentTo ( new ValidationResult
@@ -38,28 +51,32 @@ public void BetweenInclusive_Float_Valid(float input)
3851 } ) ;
3952 }
4053
41- [ TestCase ( 3 , 4 , 6 ) ]
42- [ TestCase ( 7 , 4 , 6 ) ]
43- [ TestCase ( - 1 , 4 , 6 ) ]
44- public void BetweenInclusive_Integer_Invalid ( int input , int minimum , int maximum )
45- {
46- var result = RuleFor ( input )
47- . BetweenInclusive ( minimum , maximum )
48- . Result ( ) ;
54+ private static readonly object [ ] BetweenInclusive_Invalid_Cases = [
55+ new short [ ] { 3 , 4 , 6 } ,
56+ new short [ ] { 7 , 4 , 6 } ,
4957
50- result . Should ( ) . BeEquivalentTo ( new ValidationResult
51- {
52- IsValid = false ,
53- Errors = [
54- new ( ) { Message = $ "Value '{ input } ' of type System.Int32 is not equal to or between { minimum } and { maximum } ."}
55- ]
56- } ) ;
57- }
58+ new ushort [ ] { 3 , 4 , 6 } ,
59+ new ushort [ ] { 7 , 4 , 6 } ,
60+
61+ new sbyte [ ] { 3 , 4 , 6 } ,
62+ new sbyte [ ] { 7 , 4 , 6 } ,
63+
64+ new byte [ ] { 3 , 4 , 6 } ,
65+ new byte [ ] { 7 , 4 , 6 } ,
66+
67+ new decimal [ ] { 5.39m , 5.4m , 5.6m } ,
68+ new decimal [ ] { 5.61m , 5.4m , 5.6m } ,
69+ ] ;
5870
59- [ TestCase ( 3f , 4f , 6f ) ]
60- [ TestCase ( 7f , 4f , 6f ) ]
61- [ TestCase ( - 1f , 4f , 6f ) ]
62- public void BetweenInclusive_Float_Invalid ( float input , float minimum , float maximum )
71+ [ TestCase ( 3 , 4 , 6 ) ] [ TestCase ( 7 , 4 , 6 ) ]
72+ [ TestCase ( 3u , 4u , 6u ) ] [ TestCase ( 7u , 4u , 6u ) ]
73+ [ TestCase ( 3L , 4L , 6L ) ] [ TestCase ( 7L , 4L , 6L ) ]
74+ [ TestCase ( 3ul , 4ul , 6ul ) ] [ TestCase ( 7ul , 4ul , 6ul ) ]
75+ [ TestCase ( 5.39f , 5.4f , 5.6f ) ] [ TestCase ( 5.61f , 5.4f , 5.6f ) ]
76+ [ TestCase ( 5.39d , 5.4d , 5.6d ) ] [ TestCase ( 5.61d , 5.4d , 5.6d ) ]
77+ [ TestCaseSource ( nameof ( BetweenInclusive_Invalid_Cases ) ) ]
78+ public void BetweenInclusive_Invalid < T > ( T input , T minimum , T maximum )
79+ where T : INumber < T >
6380 {
6481 var result = RuleFor ( input )
6582 . BetweenInclusive ( minimum , maximum )
@@ -69,7 +86,7 @@ public void BetweenInclusive_Float_Invalid(float input, float minimum, float max
6986 {
7087 IsValid = false ,
7188 Errors = [
72- new ( ) { Message = $ "Value '{ input } ' of type System.Single is not equal to or between { minimum } and { maximum } ."}
89+ new ( ) { Message = $ "Value '{ input } ' of type { typeof ( T ) } is not equal to or between { minimum } and { maximum } ."}
7390 ]
7491 } ) ;
7592 }
0 commit comments