1
1
using System . Collections . Generic ;
2
2
using System . Linq ;
3
3
using System . Security . Cryptography . X509Certificates ;
4
+ using Autofac ;
4
5
using NSubstitute ;
5
6
using NUnit . Framework ;
6
7
@@ -78,76 +79,76 @@ public TestIReadOnlyListComponent(IReadOnlyList<IServiceItem> serviceItems)
78
79
[ Test ]
79
80
public void TestIEnumerableCorrectlyResolves ( )
80
81
{
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 > ( ) ;
82
+ using var autosub = AutoSubstitute . Configure ( )
83
+ . Provide < IServiceItem , ServiceItemA > ( out var mockA )
84
+ . Provide < IServiceItem , ServiceItemB > ( out var mockB )
85
+ . Build ( ) ;
86
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
- }
87
+ var component = autosub . Resolve < TestIEnumerableComponent > ( ) ;
88
+
89
+ Assert . That ( component . ServiceItems , Is . Not . Empty ) ;
90
+ Assert . That ( component . ServiceItems . Contains ( mockA . Value ) , Is . True ) ;
91
+ Assert . That ( component . ServiceItems . Contains ( mockB . Value ) , Is . True ) ;
91
92
}
92
93
93
94
[ Test ]
94
95
public void TestIListCorrectlyResolves ( )
95
96
{
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 > ( ) ;
97
+ using var autosub = AutoSubstitute . Configure ( )
98
+ . Provide < IServiceItem , ServiceItemA > ( out var mockA )
99
+ . Provide < IServiceItem , ServiceItemB > ( out var mockB )
100
+ . Build ( ) ;
101
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
- }
102
+ var component = autosub . Resolve < TestIListComponent > ( ) ;
103
+
104
+ Assert . That ( component . ServiceItems , Is . Not . Empty ) ;
105
+ Assert . That ( component . ServiceItems . Contains ( mockA . Value ) , Is . True ) ;
106
+ Assert . That ( component . ServiceItems . Contains ( mockB . Value ) , Is . True ) ;
106
107
}
107
108
108
109
[ Test ]
109
110
public void TestIReadOnlyCollectionCorrectlyResolves ( )
110
111
{
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 > ( ) ;
112
+ using var autosub = AutoSubstitute . Configure ( )
113
+ . Provide < IServiceItem , ServiceItemA > ( out var mockA )
114
+ . Provide < IServiceItem , ServiceItemB > ( out var mockB )
115
+ . Build ( ) ;
116
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
- }
117
+ var component = autosub . Resolve < TestIReadOnlyCollectionComponent > ( ) ;
118
+
119
+ Assert . That ( component . ServiceItems , Is . Not . Empty ) ;
120
+ Assert . That ( component . ServiceItems . Contains ( mockA . Value ) , Is . True ) ;
121
+ Assert . That ( component . ServiceItems . Contains ( mockB . Value ) , Is . True ) ;
121
122
}
122
123
123
124
[ Test ]
124
125
public void TestICollectionCorrectlyResolves ( )
125
126
{
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 > ( ) ;
127
+ using var autosub = AutoSubstitute . Configure ( )
128
+ . Provide < IServiceItem , ServiceItemA > ( out var mockA )
129
+ . Provide < IServiceItem , ServiceItemB > ( out var mockB )
130
+ . Build ( ) ;
131
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
- }
132
+ var component = autosub . Resolve < TestICollectionComponent > ( ) ;
133
+
134
+ Assert . That ( component . ServiceItems , Is . Not . Empty ) ;
135
+ Assert . That ( component . ServiceItems . Contains ( mockA . Value ) , Is . True ) ;
136
+ Assert . That ( component . ServiceItems . Contains ( mockB . Value ) , Is . True ) ;
136
137
}
137
138
138
139
[ Test ]
139
140
public void TestIReadOnlyListCorrectlyResolves ( )
140
141
{
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 > ( ) ;
142
+ using var autosub = AutoSubstitute . Configure ( )
143
+ . Provide < IServiceItem , ServiceItemA > ( out var mockA )
144
+ . Provide < IServiceItem , ServiceItemB > ( out var mockB )
145
+ . Build ( ) ;
146
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
- }
147
+ var component = autosub . Resolve < TestIReadOnlyListComponent > ( ) ;
148
+
149
+ Assert . That ( component . ServiceItems , Is . Not . Empty ) ;
150
+ Assert . That ( component . ServiceItems . Contains ( mockA . Value ) , Is . True ) ;
151
+ Assert . That ( component . ServiceItems . Contains ( mockB . Value ) , Is . True ) ;
151
152
}
152
153
}
153
154
}
0 commit comments