2
2
using System . Collections . Generic ;
3
3
using System . Linq ;
4
4
using System . Reflection ;
5
- using System . Text ;
6
- using System . Threading . Tasks ;
7
5
using Xunit ;
8
6
9
7
namespace LogicBuilder . Expressions . Utils . Tests
@@ -13,6 +11,7 @@ public class TypeExtensionsTests
13
11
[ Theory ]
14
12
[ InlineData ( nameof ( DerivedThing . Id ) , typeof ( DerivedThing ) ) ]
15
13
[ InlineData ( nameof ( DerivedThing . Name ) , typeof ( BaseThing ) ) ]
14
+ [ InlineData ( nameof ( DerivedThing . DataInBytes ) , typeof ( BaseThing ) ) ]
16
15
[ InlineData ( nameof ( DerivedThing . Description ) , typeof ( DerivedThing ) ) ]
17
16
public void MemberInfoReflectedTypeMustMatchTheDeclaringType ( string propertyName , Type reflectedType )
18
17
{
@@ -26,30 +25,71 @@ public void MemberInfoReflectedTypeMustMatchTheDeclaringType(string propertyName
26
25
[ Theory ]
27
26
[ InlineData ( nameof ( DerivedThing . Id ) , typeof ( DerivedThing ) ) ]
28
27
[ InlineData ( nameof ( DerivedThing . Name ) , typeof ( BaseThing ) ) ]
28
+ [ InlineData ( nameof ( DerivedThing . DataInBytes ) , typeof ( BaseThing ) ) ]
29
29
[ InlineData ( nameof ( DerivedThing . Description ) , typeof ( DerivedThing ) ) ]
30
- public void MemberInfoReflectedTypeMustMatchTheDeclaringTypeForGetSelectedMembers ( string propertyName , Type reflectedType )
30
+ public void MemberInfoReflectedTypeMustMatchTheDeclaringTypeForGetSelectedMembers ( string propertyName ,
31
+ Type reflectedType )
31
32
{
32
33
//act
33
- MemberInfo memberInfo = typeof ( DerivedThing ) . GetSelectedMembers ( new List < string > ( ) ) . FirstOrDefault ( m => m . Name == propertyName ) ;
34
+ MemberInfo memberInfo = typeof ( DerivedThing ) . GetSelectedMembers ( new List < string > ( ) )
35
+ . FirstOrDefault ( m => m . Name == propertyName ) ;
34
36
35
37
//assert
36
38
Assert . Equal ( reflectedType . FullName , memberInfo . ReflectedType . FullName ) ;
37
39
}
38
40
39
- public abstract class BaseThing
41
+ [ Theory ]
42
+ [ InlineData ( typeof ( DerivedThing ) ) ]
43
+ [ InlineData ( typeof ( BaseThing ) ) ]
44
+ public void GetSelectedMembers_WhenSelectIsEmpty_MustReturnAllLiteralMembers ( Type reflectedType )
45
+ {
46
+ // Act
47
+ var memberInfos = reflectedType . GetSelectedMembers ( Enumerable . Empty < string > ( ) . ToList ( ) ) ;
48
+
49
+ // Assert
50
+ Assert . Multiple ( ( ) =>
51
+ {
52
+ var names = memberInfos . Select ( mi => mi . Name ) . ToList ( ) ;
53
+
54
+ Assert . DoesNotContain ( memberInfos , name => name . Name == nameof ( BaseThing . Objects ) ) ;
55
+
56
+ Assert . Contains ( names , name => name == nameof ( BaseThing . ParametersArray ) ) ;
57
+ Assert . Contains ( names , name => name == nameof ( BaseThing . ParametersList ) ) ;
58
+ Assert . Contains ( names , name => name == nameof ( BaseThing . Ints ) ) ;
59
+ Assert . Contains ( names , name => name == nameof ( BaseThing . Strings ) ) ;
60
+ Assert . Contains ( names , name => name == nameof ( BaseThing . Booleans ) ) ;
61
+ Assert . Contains ( names , name => name == nameof ( BaseThing . DateTimes ) ) ;
62
+ Assert . Contains ( names , name => name == nameof ( BaseThing . Dates ) ) ;
63
+ Assert . Contains ( names , name => name == nameof ( BaseThing . Guides ) ) ;
64
+ Assert . Contains ( names , name => name == nameof ( BaseThing . UnsignedInts ) ) ;
65
+ } ) ;
66
+ }
67
+
68
+ private abstract class BaseThing
40
69
{
41
70
public string Name { get ; set ; }
71
+ public byte [ ] DataInBytes { get ; set ; }
72
+ public string [ ] ParametersArray { get ; set ; }
73
+ public ICollection < string > Strings { get ; set ; }
74
+ public List < string > ParametersList { get ; set ; }
75
+ public List < bool > Booleans { get ; set ; }
76
+ public ISet < DateTime > DateTimes { get ; set ; }
77
+ public ISet < DateOnly > Dates { get ; set ; }
78
+ public HashSet < Guid > Guides { get ; set ; }
79
+ public uint [ ] UnsignedInts { get ; set ; }
80
+ public IEnumerable < int > Ints { get ; set ; }
81
+ public List < object > Objects { get ; set ; }
42
82
}
43
83
44
- public class DerivedThing : BaseThing , IDerivedThing
84
+ private class DerivedThing : BaseThing , IDerivedThing
45
85
{
46
86
public Guid Id { get ; set ; }
47
87
public string Description { get ; set ; }
48
88
}
49
89
50
- public interface IDerivedThing
90
+ private interface IDerivedThing
51
91
{
52
92
public string Description { get ; set ; }
53
93
}
54
94
}
55
- }
95
+ }
0 commit comments