1
+ using System . Collections . Generic ;
2
+ using System . Linq ;
3
+ using System . Security . Cryptography . X509Certificates ;
4
+ using NSubstitute ;
5
+ using NUnit . Framework ;
6
+
7
+ namespace AutofacContrib . NSubstitute . Tests
8
+ {
9
+ [ TestFixture ]
10
+ public sealed class AutoSubstituteCollectionFixture
11
+ {
12
+ #region stubs
13
+
14
+ public interface IServiceItem
15
+ {
16
+ }
17
+
18
+ public class ServiceItemA : IServiceItem
19
+ {
20
+ }
21
+
22
+ public class ServiceItemB : IServiceItem
23
+ {
24
+ }
25
+
26
+ public sealed class TestIEnumerableComponent
27
+ {
28
+ public readonly IEnumerable < IServiceItem > ServiceItems ;
29
+
30
+ public TestIEnumerableComponent ( IEnumerable < IServiceItem > serviceItems )
31
+ {
32
+ ServiceItems = serviceItems ;
33
+ }
34
+ }
35
+
36
+ public sealed class TestIListComponent
37
+ {
38
+ public readonly IList < IServiceItem > ServiceItems ;
39
+
40
+ public TestIListComponent ( IList < IServiceItem > serviceItems )
41
+ {
42
+ ServiceItems = serviceItems ;
43
+ }
44
+ }
45
+
46
+ public sealed class TestIReadOnlyCollectionComponent
47
+ {
48
+ public readonly IReadOnlyCollection < IServiceItem > ServiceItems ;
49
+
50
+ public TestIReadOnlyCollectionComponent ( IReadOnlyCollection < IServiceItem > serviceItems )
51
+ {
52
+ ServiceItems = serviceItems ;
53
+ }
54
+ }
55
+
56
+ public sealed class TestICollectionComponent
57
+ {
58
+ public readonly ICollection < IServiceItem > ServiceItems ;
59
+
60
+ public TestICollectionComponent ( ICollection < IServiceItem > serviceItems )
61
+ {
62
+ ServiceItems = serviceItems ;
63
+ }
64
+ }
65
+
66
+ public sealed class TestIReadOnlyListComponent
67
+ {
68
+ public readonly IReadOnlyList < IServiceItem > ServiceItems ;
69
+
70
+ public TestIReadOnlyListComponent ( IReadOnlyList < IServiceItem > serviceItems )
71
+ {
72
+ ServiceItems = serviceItems ;
73
+ }
74
+ }
75
+
76
+ #endregion
77
+
78
+ [ Test ]
79
+ public void TestIEnumerableCorrectlyResolves ( )
80
+ {
81
+ using ( var autosub = new AutoSubstitute ( ) )
82
+ {
83
+ var mockA = autosub . Provide < IServiceItem , ServiceItemA > ( ) ;
84
+ var mockB = autosub . Provide < IServiceItem , ServiceItemB > ( ) ;
85
+ var component = autosub . Resolve < TestIEnumerableComponent > ( ) ;
86
+
87
+ Assert . That ( component . ServiceItems , Is . Not . Empty ) ;
88
+ Assert . That ( component . ServiceItems . Contains ( mockA ) , Is . True ) ;
89
+ Assert . That ( component . ServiceItems . Contains ( mockB ) , Is . True ) ;
90
+ }
91
+ }
92
+
93
+ [ Test ]
94
+ public void TestIListCorrectlyResolves ( )
95
+ {
96
+ using ( var autosub = new AutoSubstitute ( ) )
97
+ {
98
+ var mockA = autosub . Provide < IServiceItem , ServiceItemA > ( ) ;
99
+ var mockB = autosub . Provide < IServiceItem , ServiceItemB > ( ) ;
100
+ var component = autosub . Resolve < TestIListComponent > ( ) ;
101
+
102
+ Assert . That ( component . ServiceItems , Is . Not . Empty ) ;
103
+ Assert . That ( component . ServiceItems . Contains ( mockA ) , Is . True ) ;
104
+ Assert . That ( component . ServiceItems . Contains ( mockB ) , Is . True ) ;
105
+ }
106
+ }
107
+
108
+ [ Test ]
109
+ public void TestIReadOnlyCollectionCorrectlyResolves ( )
110
+ {
111
+ using ( var autosub = new AutoSubstitute ( ) )
112
+ {
113
+ var mockA = autosub . Provide < IServiceItem , ServiceItemA > ( ) ;
114
+ var mockB = autosub . Provide < IServiceItem , ServiceItemB > ( ) ;
115
+ var component = autosub . Resolve < TestIReadOnlyCollectionComponent > ( ) ;
116
+
117
+ Assert . That ( component . ServiceItems , Is . Not . Empty ) ;
118
+ Assert . That ( component . ServiceItems . Contains ( mockA ) , Is . True ) ;
119
+ Assert . That ( component . ServiceItems . Contains ( mockB ) , Is . True ) ;
120
+ }
121
+ }
122
+
123
+ [ Test ]
124
+ public void TestICollectionCorrectlyResolves ( )
125
+ {
126
+ using ( var autosub = new AutoSubstitute ( ) )
127
+ {
128
+ var mockA = autosub . Provide < IServiceItem , ServiceItemA > ( ) ;
129
+ var mockB = autosub . Provide < IServiceItem , ServiceItemB > ( ) ;
130
+ var component = autosub . Resolve < TestICollectionComponent > ( ) ;
131
+
132
+ Assert . That ( component . ServiceItems , Is . Not . Empty ) ;
133
+ Assert . That ( component . ServiceItems . Contains ( mockA ) , Is . True ) ;
134
+ Assert . That ( component . ServiceItems . Contains ( mockB ) , Is . True ) ;
135
+ }
136
+ }
137
+
138
+ [ Test ]
139
+ public void TestIReadOnlyListCorrectlyResolves ( )
140
+ {
141
+ using ( var autosub = new AutoSubstitute ( ) )
142
+ {
143
+ var mockA = autosub . Provide < IServiceItem , ServiceItemA > ( ) ;
144
+ var mockB = autosub . Provide < IServiceItem , ServiceItemB > ( ) ;
145
+ var component = autosub . Resolve < TestIReadOnlyListComponent > ( ) ;
146
+
147
+ Assert . That ( component . ServiceItems , Is . Not . Empty ) ;
148
+ Assert . That ( component . ServiceItems . Contains ( mockA ) , Is . True ) ;
149
+ Assert . That ( component . ServiceItems . Contains ( mockB ) , Is . True ) ;
150
+ }
151
+ }
152
+ }
153
+ }
0 commit comments