1+ using  System ; 
2+ using  JsonApiDotNetCore . Graph ; 
3+ using  JsonApiDotNetCore . Models ; 
4+ using  Xunit ; 
5+ 
6+ namespace  UnitTests . Internal 
7+ { 
8+     public  class  TypeLocator_Tests 
9+     { 
10+         [ Fact ] 
11+         public  void  GetGenericInterfaceImplementation_Gets_Implementation ( ) 
12+         { 
13+             // arrange 
14+             var  assembly  =  GetType ( ) . Assembly ; 
15+             var  openGeneric  =  typeof ( IGenericInterface < > ) ; 
16+             var  genericArg  =  typeof ( int ) ; 
17+ 
18+             var  expectedImplementation  =  typeof ( Implementation ) ; 
19+             var  expectedInterface  =  typeof ( IGenericInterface < int > ) ; 
20+ 
21+             // act 
22+             var  result  =  TypeLocator . GetGenericInterfaceImplementation ( 
23+                 assembly , 
24+                 openGeneric , 
25+                 genericArg 
26+             ) ; 
27+ 
28+             // assert 
29+             Assert . NotNull ( result ) ; 
30+             Assert . Equal ( expectedImplementation ,  result . implementation ) ; 
31+             Assert . Equal ( expectedInterface ,  result . registrationInterface ) ; 
32+         } 
33+ 
34+         [ Fact ] 
35+         public  void  GetDerivedGenericTypes_Gets_Implementation ( ) 
36+         { 
37+             // arrange 
38+             var  assembly  =  GetType ( ) . Assembly ; 
39+             var  openGeneric  =  typeof ( BaseType < > ) ; 
40+             var  genericArg  =  typeof ( int ) ; 
41+ 
42+             var  expectedImplementation  =  typeof ( DerivedType ) ; 
43+ 
44+             // act 
45+             var  results  =  TypeLocator . GetDerivedGenericTypes ( 
46+                 assembly , 
47+                 openGeneric , 
48+                 genericArg 
49+             ) ; 
50+ 
51+             // assert 
52+             Assert . NotNull ( results ) ; 
53+             var  result  =  Assert . Single ( results ) ; 
54+             Assert . Equal ( expectedImplementation ,  result ) ; 
55+         } 
56+ 
57+         [ Fact ] 
58+         public  void  GetIdType_Correctly_Identifies_JsonApiResource ( ) 
59+         { 
60+             // arrange 
61+             var  type  =  typeof ( Model ) ; 
62+             var  exextedIdType  =  typeof ( int ) ; 
63+ 
64+             // act 
65+             var  result  =  TypeLocator . GetIdType ( type ) ; 
66+ 
67+             // assert 
68+             Assert . NotNull ( result ) ; 
69+             Assert . True ( result . isJsonApiResource ) ; 
70+             Assert . Equal ( exextedIdType ,  result . idType ) ; 
71+         } 
72+ 
73+         [ Fact ] 
74+         public  void  GetIdType_Correctly_Identifies_NonJsonApiResource ( ) 
75+         { 
76+             // arrange 
77+             var  type  =  typeof ( DerivedType ) ; 
78+             Type  exextedIdType  =  null ; 
79+ 
80+             // act 
81+             var  result  =  TypeLocator . GetIdType ( type ) ; 
82+ 
83+             // assert 
84+             Assert . NotNull ( result ) ; 
85+             Assert . False ( result . isJsonApiResource ) ; 
86+             Assert . Equal ( exextedIdType ,  result . idType ) ; 
87+         } 
88+     } 
89+ 
90+     
91+     public  interface  IGenericInterface < T >  {  } 
92+     public  class  Implementation  :  IGenericInterface < int >  {  } 
93+ 
94+ 
95+     public  class  BaseType < T >  {  } 
96+     public  class  DerivedType  :  BaseType < int >  {  } 
97+ 
98+     public  class  Model  :  Identifiable  {  } 
99+ } 
0 commit comments