1+ using System ;
2+ using System . Collections . Generic ;
3+ using NUnit . Framework ;
4+ using Xtensive . Reflection ;
5+
6+ namespace Xtensive . Orm . Tests . Core . Reflection
7+ {
8+ [ TestFixture ]
9+ public class TypeHelperGetGenericTypeTests
10+ {
11+ private class ListInt : List < int >
12+ { }
13+
14+ private class ListIntLvl1 : ListInt
15+ { }
16+
17+ private class GenericList < T > : List < T >
18+ { }
19+
20+ private class GenericListLvl1 < T > : GenericList < T >
21+ { }
22+
23+ private class GenericListLvl1Int : GenericListLvl1 < int >
24+ { }
25+
26+ private class GenericListInt : GenericList < int >
27+ { }
28+
29+ private class GenericListIntLvl1 : GenericListInt
30+ { }
31+
32+ [ Test ]
33+ public void ParameterizedGenericTypeIsDiscoverable_ByItself ( ) =>
34+ Assert . AreSame ( typeof ( List < int > ) . GetGenericType ( typeof ( List < > ) ) , typeof ( List < int > ) ) ;
35+
36+ [ Test ]
37+ public void ParameterizedGenericTypeIsDiscoverable_ByItsDirectNonGenericAncestor ( ) =>
38+ Assert . AreSame ( typeof ( ListInt ) . GetGenericType ( typeof ( List < > ) ) , typeof ( List < int > ) ) ;
39+
40+ [ Test ]
41+ public void ParameterizedGenericTypeIsDiscoverable_ByItsIndirectNonGenericAncestor ( ) =>
42+ Assert . AreSame ( typeof ( ListIntLvl1 ) . GetGenericType ( typeof ( List < > ) ) , typeof ( List < int > ) ) ;
43+
44+ [ Test ]
45+ public void ParameterizedGenericTypeIsDiscoverable_ByItsDirectGenericAncestor ( ) =>
46+ Assert . AreSame ( typeof ( GenericList < int > ) . GetGenericType ( typeof ( List < > ) ) , typeof ( List < int > ) ) ;
47+
48+ [ Test ]
49+ public void ParameterizedGenericTypeIsDiscoverable_ByItsIndirectGenericAncestor ( ) =>
50+ Assert . AreSame ( typeof ( GenericListLvl1 < int > ) . GetGenericType ( typeof ( List < > ) ) , typeof ( List < int > ) ) ;
51+
52+ [ Test ]
53+ public void ParameterizedGenericTypeIsDiscoverable_ByAnAncestorOfItsDirectGenericAncestor ( ) =>
54+ Assert . AreSame ( typeof ( GenericListIntLvl1 ) . GetGenericType ( typeof ( List < > ) ) , typeof ( List < int > ) ) ;
55+
56+ [ Test ]
57+ public void ParameterizedGenericTypeIsDiscoverable_ByAnAncestorOfItsIndirectGenericAncestor ( ) =>
58+ Assert . AreSame ( typeof ( GenericListLvl1Int ) . GetGenericType ( typeof ( List < > ) ) , typeof ( List < int > ) ) ;
59+
60+ [ Test ]
61+ public void ParameterizedGenericInterfaceIsDiscoverable_ByItself ( ) =>
62+ Assert . AreSame ( typeof ( IList < int > ) . GetGenericType ( typeof ( IList < > ) ) , typeof ( IList < int > ) ) ;
63+
64+ [ Test ]
65+ public void ParameterizedGenericInterfaceIsNotDiscoverable_ByItsImplementation ( ) =>
66+ Assert . IsNull ( typeof ( List < int > ) . GetGenericType ( typeof ( IList < > ) ) ) ;
67+
68+ [ Test ]
69+ public void NullIsReturnedIfNoMatchFound ( ) =>
70+ Assert . IsNull ( typeof ( Stack < int > ) . GetGenericType ( typeof ( List < > ) ) ) ;
71+
72+ [ Test ]
73+ public void NullIsAcceptedAsFirstParameter ( ) =>
74+ Assert . IsNull ( TypeHelper . GetGenericType ( null , typeof ( List < > ) ) ) ;
75+ }
76+ }
0 commit comments