33
44using Moq ;
55using System ;
6+ using System . Collections . Generic ;
67using System . Diagnostics . CodeAnalysis ;
8+ using System . Linq ;
79using Xunit ;
810
911namespace RulesEngine . UnitTest
@@ -12,33 +14,84 @@ namespace RulesEngine.UnitTest
1214 [ ExcludeFromCodeCoverage ]
1315 public class CustomTypeProviderTests : IDisposable
1416 {
15- private readonly MockRepository _mockRepository ;
16- public CustomTypeProviderTests ( )
17+ public void Dispose ( )
1718 {
18- _mockRepository = new MockRepository ( MockBehavior . Strict ) ;
1919 }
2020
21- public void Dispose ( )
21+ private CustomTypeProvider CreateProvider ( params Type [ ] customTypes )
2222 {
23- _mockRepository . VerifyAll ( ) ;
23+ return new CustomTypeProvider ( customTypes ) ;
2424 }
2525
26- private CustomTypeProvider CreateProvider ( )
26+ [ Fact ]
27+ public void GetCustomTypes_DefaultProvider_IncludesEnumerableAndObject ( )
2728 {
28- return new CustomTypeProvider ( null ) ;
29+ var provider = CreateProvider ( ) ;
30+ var allTypes = provider . GetCustomTypes ( ) ;
31+ Assert . NotEmpty ( allTypes ) ;
32+ Assert . Contains ( typeof ( System . Linq . Enumerable ) , allTypes ) ;
33+ Assert . Contains ( typeof ( object ) , allTypes ) ;
2934 }
3035
3136 [ Fact ]
32- public void GetCustomTypes_StateUnderTest_ExpectedBehavior ( )
37+ public void GetCustomTypes_WithListOfGuid_ContainsIEnumerableOfGuid ( )
3338 {
34- // Arrange
35- var unitUnderTest = CreateProvider ( ) ;
39+ var initial = new [ ] { typeof ( List < Guid > ) } ;
40+ var provider = CreateProvider ( initial ) ;
41+ var allTypes = provider . GetCustomTypes ( ) ;
42+ Assert . Contains ( typeof ( IEnumerable < Guid > ) , allTypes ) ;
43+ Assert . Contains ( typeof ( List < Guid > ) , allTypes ) ;
44+ Assert . Contains ( typeof ( System . Linq . Enumerable ) , allTypes ) ;
45+ Assert . Contains ( typeof ( object ) , allTypes ) ;
46+ }
3647
37- // Act
38- var result = unitUnderTest . GetCustomTypes ( ) ;
48+ [ Fact ]
49+ public void GetCustomTypes_ListOfListString_ContainsIEnumerableOfListString ( )
50+ {
51+ var nestedListType = typeof ( List < List < string > > ) ;
52+ var provider = CreateProvider ( nestedListType ) ;
53+ var allTypes = provider . GetCustomTypes ( ) ;
54+ Assert . Contains ( typeof ( IEnumerable < List < string > > ) , allTypes ) ;
55+ Assert . Contains ( nestedListType , allTypes ) ;
56+ Assert . Contains ( typeof ( System . Linq . Enumerable ) , allTypes ) ;
57+ Assert . Contains ( typeof ( object ) , allTypes ) ;
58+ }
3959
40- // Assert
41- Assert . NotEmpty ( result ) ;
60+ [ Fact ]
61+ public void GetCustomTypes_ArrayOfStringArrays_ContainsIEnumerableOfStringArray ( )
62+ {
63+ var arrayType = typeof ( string [ ] [ ] ) ;
64+ var provider = CreateProvider ( arrayType ) ;
65+ var allTypes = provider . GetCustomTypes ( ) ;
66+ Assert . Contains ( typeof ( IEnumerable < string [ ] > ) , allTypes ) ;
67+ Assert . Contains ( arrayType , allTypes ) ;
68+ Assert . Contains ( typeof ( System . Linq . Enumerable ) , allTypes ) ;
69+ Assert . Contains ( typeof ( object ) , allTypes ) ;
70+ }
71+
72+ [ Fact ]
73+ public void GetCustomTypes_NullableIntArray_ContainsIEnumerableOfNullableInt ( )
74+ {
75+ var nullableInt = typeof ( int ? ) ;
76+ var arrayType = typeof ( int ? [ ] ) ;
77+ var provider = CreateProvider ( arrayType ) ;
78+ var allTypes = provider . GetCustomTypes ( ) ;
79+ Assert . Contains ( typeof ( IEnumerable < int ? > ) , allTypes ) ;
80+ Assert . Contains ( arrayType , allTypes ) ;
81+ Assert . Contains ( typeof ( System . Linq . Enumerable ) , allTypes ) ;
82+ Assert . Contains ( typeof ( object ) , allTypes ) ;
83+ }
84+
85+ [ Fact ]
86+ public void GetCustomTypes_MultipleTypes_NoDuplicates ( )
87+ {
88+ var repeatedType = typeof ( List < string > ) ;
89+ var provider = CreateProvider ( repeatedType , repeatedType ) ;
90+ var allTypes = provider . GetCustomTypes ( ) ;
91+ var matches = allTypes . Where ( t => t == repeatedType ) . ToList ( ) ;
92+ Assert . Single ( matches ) ;
93+ var interfaceMatches = allTypes . Where ( t => t == typeof ( IEnumerable < string > ) ) . ToList ( ) ;
94+ Assert . Single ( interfaceMatches ) ;
4295 }
4396 }
4497}
0 commit comments