|
1 | 1 | // ReSharper disable InconsistentNaming |
2 | 2 |
|
3 | 3 | using System; |
| 4 | +using System.Collections.Generic; |
4 | 5 | using Microsoft.AspNetCore.Mvc; |
5 | 6 | using SharpGrip.FluentValidation.AutoValidation.Mvc.Attributes; |
6 | 7 | using SharpGrip.FluentValidation.AutoValidation.Shared.Extensions; |
@@ -42,6 +43,87 @@ public void Test_IsCustomType() |
42 | 43 | Assert.False(typeof(Uri).IsCustomType()); |
43 | 44 | } |
44 | 45 |
|
| 46 | + [Fact] |
| 47 | + public void Test_IsCustomType_Collections() |
| 48 | + { |
| 49 | + Assert.True(typeof(ICollection<TestModelClass>).IsCustomType()); |
| 50 | + Assert.True(typeof(ICollection<TestModelRecord>).IsCustomType()); |
| 51 | + Assert.True(typeof(ICollection<TestModelStruct>).IsCustomType()); |
| 52 | + Assert.False(typeof(ICollection<TestModelEnum>).IsCustomType()); |
| 53 | + Assert.False(typeof(ICollection<Enum>).IsCustomType()); |
| 54 | + Assert.False(typeof(ICollection<string>).IsCustomType()); |
| 55 | + |
| 56 | + Assert.True(typeof(IList<TestModelClass>).IsCustomType()); |
| 57 | + Assert.True(typeof(IList<TestModelRecord>).IsCustomType()); |
| 58 | + Assert.True(typeof(IList<TestModelStruct>).IsCustomType()); |
| 59 | + Assert.False(typeof(IList<TestModelEnum>).IsCustomType()); |
| 60 | + Assert.False(typeof(IList<Enum>).IsCustomType()); |
| 61 | + Assert.False(typeof(IList<string>).IsCustomType()); |
| 62 | + |
| 63 | + Assert.True(typeof(List<TestModelClass>).IsCustomType()); |
| 64 | + Assert.True(typeof(List<TestModelRecord>).IsCustomType()); |
| 65 | + Assert.True(typeof(List<TestModelStruct>).IsCustomType()); |
| 66 | + Assert.False(typeof(List<TestModelEnum>).IsCustomType()); |
| 67 | + Assert.False(typeof(List<Enum>).IsCustomType()); |
| 68 | + Assert.False(typeof(List<string>).IsCustomType()); |
| 69 | + |
| 70 | + Assert.True(typeof(TestModelClass[]).IsCustomType()); |
| 71 | + Assert.True(typeof(TestModelRecord[]).IsCustomType()); |
| 72 | + Assert.True(typeof(TestModelStruct[]).IsCustomType()); |
| 73 | + Assert.False(typeof(TestModelEnum[]).IsCustomType()); |
| 74 | + Assert.False(typeof(Enum[]).IsCustomType()); |
| 75 | + Assert.False(typeof(string[]).IsCustomType()); |
| 76 | + |
| 77 | + Assert.True(typeof(Dictionary<string, TestModelClass>).IsCustomType()); |
| 78 | + Assert.True(typeof(Dictionary<string, TestModelRecord>).IsCustomType()); |
| 79 | + Assert.True(typeof(Dictionary<string, TestModelStruct>).IsCustomType()); |
| 80 | + Assert.False(typeof(Dictionary<string, TestModelEnum>).IsCustomType()); |
| 81 | + Assert.False(typeof(Dictionary<string, Enum>).IsCustomType()); |
| 82 | + Assert.False(typeof(Dictionary<string, string>).IsCustomType()); |
| 83 | + |
| 84 | + Assert.True(typeof(HashSet<TestModelClass>).IsCustomType()); |
| 85 | + Assert.True(typeof(HashSet<TestModelRecord>).IsCustomType()); |
| 86 | + Assert.True(typeof(HashSet<TestModelStruct>).IsCustomType()); |
| 87 | + Assert.False(typeof(HashSet<TestModelEnum>).IsCustomType()); |
| 88 | + Assert.False(typeof(HashSet<Enum>).IsCustomType()); |
| 89 | + Assert.False(typeof(HashSet<string>).IsCustomType()); |
| 90 | + |
| 91 | + Assert.True(typeof(IEnumerable<TestModelClass>).IsCustomType()); |
| 92 | + Assert.True(typeof(IEnumerable<TestModelRecord>).IsCustomType()); |
| 93 | + Assert.True(typeof(IEnumerable<TestModelStruct>).IsCustomType()); |
| 94 | + Assert.False(typeof(IEnumerable<TestModelEnum>).IsCustomType()); |
| 95 | + Assert.False(typeof(IEnumerable<Enum>).IsCustomType()); |
| 96 | + Assert.False(typeof(IEnumerable<string>).IsCustomType()); |
| 97 | + |
| 98 | + Assert.True(typeof(IReadOnlyList<TestModelClass>).IsCustomType()); |
| 99 | + Assert.True(typeof(IReadOnlyList<TestModelRecord>).IsCustomType()); |
| 100 | + Assert.True(typeof(IReadOnlyList<TestModelStruct>).IsCustomType()); |
| 101 | + Assert.False(typeof(IReadOnlyList<TestModelEnum>).IsCustomType()); |
| 102 | + Assert.False(typeof(IReadOnlyList<Enum>).IsCustomType()); |
| 103 | + Assert.False(typeof(IReadOnlyList<string>).IsCustomType()); |
| 104 | + |
| 105 | + Assert.True(typeof(IReadOnlyCollection<TestModelClass>).IsCustomType()); |
| 106 | + Assert.True(typeof(IReadOnlyCollection<TestModelRecord>).IsCustomType()); |
| 107 | + Assert.True(typeof(IReadOnlyCollection<TestModelStruct>).IsCustomType()); |
| 108 | + Assert.False(typeof(IReadOnlyCollection<TestModelEnum>).IsCustomType()); |
| 109 | + Assert.False(typeof(IReadOnlyCollection<Enum>).IsCustomType()); |
| 110 | + Assert.False(typeof(IReadOnlyCollection<string>).IsCustomType()); |
| 111 | + |
| 112 | + Assert.True(typeof(ISet<TestModelClass>).IsCustomType()); |
| 113 | + Assert.True(typeof(ISet<TestModelRecord>).IsCustomType()); |
| 114 | + Assert.True(typeof(ISet<TestModelStruct>).IsCustomType()); |
| 115 | + Assert.False(typeof(ISet<TestModelEnum>).IsCustomType()); |
| 116 | + Assert.False(typeof(ISet<Enum>).IsCustomType()); |
| 117 | + Assert.False(typeof(ISet<string>).IsCustomType()); |
| 118 | + |
| 119 | + Assert.False(typeof(IAsyncEnumerable<TestModelClass>).IsCustomType()); |
| 120 | + Assert.False(typeof(IAsyncEnumerable<TestModelRecord>).IsCustomType()); |
| 121 | + Assert.False(typeof(IAsyncEnumerable<TestModelStruct>).IsCustomType()); |
| 122 | + Assert.False(typeof(IAsyncEnumerable<TestModelEnum>).IsCustomType()); |
| 123 | + Assert.False(typeof(IAsyncEnumerable<Enum>).IsCustomType()); |
| 124 | + Assert.False(typeof(IAsyncEnumerable<string>).IsCustomType()); |
| 125 | + } |
| 126 | + |
45 | 127 | [Fact] |
46 | 128 | public void Test_HasCustomAttribute() |
47 | 129 | { |
|
0 commit comments