@@ -9,16 +9,33 @@ namespace LazyProxy.ServiceProvider.Tests
9
9
10
10
public class ServiceCollectionExtensionsTest
11
11
{
12
- [ Fact ]
13
- public void ServiceCtorMustBeExecutedAfterMethodIsCalledForTheFirstTime ( )
12
+
13
+ [ InlineData ( ServiceLifetime . Scoped ) ]
14
+ [ InlineData ( ServiceLifetime . Singleton ) ]
15
+ [ InlineData ( ServiceLifetime . Transient ) ]
16
+ [ Theory ]
17
+ public void ServiceCtorMustBeExecutedAfterMethodIsCalledForTheFirstTime ( ServiceLifetime lifetime )
14
18
{
15
19
_service1Id = string . Empty ;
16
20
_service2Id = string . Empty ;
17
21
18
22
var serviceCollection = new ServiceCollection ( ) ;
19
- serviceCollection . AddLazyScoped < IService1 , Service1 > ( ) ;
20
- serviceCollection . AddScoped < IService2 , Service2 > ( ) ;
21
-
23
+ switch ( lifetime )
24
+ {
25
+ case ServiceLifetime . Scoped :
26
+ serviceCollection . AddLazyScoped < IService1 , Service1 > ( ) ;
27
+ serviceCollection . AddScoped < IService2 , Service2 > ( ) ;
28
+ break ;
29
+ case ServiceLifetime . Singleton :
30
+ serviceCollection . AddLazySingleton < IService1 , Service1 > ( ) ;
31
+ serviceCollection . AddSingleton < IService2 , Service2 > ( ) ;
32
+ break ;
33
+ case ServiceLifetime . Transient :
34
+ serviceCollection . AddLazyTransient < IService1 , Service1 > ( ) ;
35
+ serviceCollection . AddTransient < IService2 , Service2 > ( ) ;
36
+ break ;
37
+ }
38
+
22
39
using ( var serviceProvider = serviceCollection . BuildServiceProvider ( ) )
23
40
{
24
41
var service = serviceProvider . GetService < IService1 > ( ) ;
@@ -43,15 +60,31 @@ public void ServiceCtorMustBeExecutedAfterMethodIsCalledForTheFirstTime()
43
60
}
44
61
}
45
62
46
- [ Fact ]
47
- public void ServiceCtorMustBeExecutedAfterPropertyGetterIsCalledForTheFirstTime ( )
63
+ [ InlineData ( ServiceLifetime . Scoped ) ]
64
+ [ InlineData ( ServiceLifetime . Singleton ) ]
65
+ [ InlineData ( ServiceLifetime . Transient ) ]
66
+ [ Theory ]
67
+ public void ServiceCtorMustBeExecutedAfterPropertyGetterIsCalledForTheFirstTime ( ServiceLifetime lifetime )
48
68
{
49
69
_service1Id = string . Empty ;
50
70
_service2Id = string . Empty ;
51
71
52
72
var serviceCollection = new ServiceCollection ( ) ;
53
- serviceCollection . AddLazyScoped < IService1 , Service1 > ( ) ;
54
- serviceCollection . AddScoped < IService2 , Service2 > ( ) ;
73
+ switch ( lifetime )
74
+ {
75
+ case ServiceLifetime . Scoped :
76
+ serviceCollection . AddLazyScoped < IService1 , Service1 > ( ) ;
77
+ serviceCollection . AddScoped < IService2 , Service2 > ( ) ;
78
+ break ;
79
+ case ServiceLifetime . Singleton :
80
+ serviceCollection . AddLazySingleton < IService1 , Service1 > ( ) ;
81
+ serviceCollection . AddSingleton < IService2 , Service2 > ( ) ;
82
+ break ;
83
+ case ServiceLifetime . Transient :
84
+ serviceCollection . AddLazyTransient < IService1 , Service1 > ( ) ;
85
+ serviceCollection . AddTransient < IService2 , Service2 > ( ) ;
86
+ break ;
87
+ }
55
88
56
89
using ( var serviceProvider = serviceCollection . BuildServiceProvider ( ) )
57
90
{
@@ -77,15 +110,31 @@ public void ServiceCtorMustBeExecutedAfterPropertyGetterIsCalledForTheFirstTime(
77
110
}
78
111
}
79
112
80
- [ Fact ]
81
- public void ServiceCtorMustBeExecutedAfterPropertySetterIsCalledForTheFirstTime ( )
113
+ [ InlineData ( ServiceLifetime . Scoped ) ]
114
+ [ InlineData ( ServiceLifetime . Singleton ) ]
115
+ [ InlineData ( ServiceLifetime . Transient ) ]
116
+ [ Theory ]
117
+ public void ServiceCtorMustBeExecutedAfterPropertySetterIsCalledForTheFirstTime ( ServiceLifetime lifetime )
82
118
{
83
119
_service1Id = string . Empty ;
84
120
_service2Id = string . Empty ;
85
121
86
122
var serviceCollection = new ServiceCollection ( ) ;
87
- serviceCollection . AddLazyScoped < IService1 , Service1 > ( ) ;
88
- serviceCollection . AddScoped < IService2 , Service2 > ( ) ;
123
+ switch ( lifetime )
124
+ {
125
+ case ServiceLifetime . Scoped :
126
+ serviceCollection . AddLazyScoped < IService1 , Service1 > ( ) ;
127
+ serviceCollection . AddScoped < IService2 , Service2 > ( ) ;
128
+ break ;
129
+ case ServiceLifetime . Singleton :
130
+ serviceCollection . AddLazySingleton < IService1 , Service1 > ( ) ;
131
+ serviceCollection . AddSingleton < IService2 , Service2 > ( ) ;
132
+ break ;
133
+ case ServiceLifetime . Transient :
134
+ serviceCollection . AddLazyTransient < IService1 , Service1 > ( ) ;
135
+ serviceCollection . AddTransient < IService2 , Service2 > ( ) ;
136
+ break ;
137
+ }
89
138
90
139
using ( var serviceProvider = serviceCollection . BuildServiceProvider ( ) )
91
140
{
@@ -109,15 +158,31 @@ public void ServiceCtorMustBeExecutedAfterPropertySetterIsCalledForTheFirstTime(
109
158
}
110
159
}
111
160
112
- [ Fact ]
113
- public void ArgumentsMustBePassedToMethodCorrectly ( )
161
+ [ InlineData ( ServiceLifetime . Scoped ) ]
162
+ [ InlineData ( ServiceLifetime . Singleton ) ]
163
+ [ InlineData ( ServiceLifetime . Transient ) ]
164
+ [ Theory ]
165
+ public void ArgumentsMustBePassedToMethodCorrectly ( ServiceLifetime lifetime )
114
166
{
115
167
const string arg1 = nameof ( arg1 ) ;
116
168
const string arg2 = nameof ( arg2 ) ;
117
169
118
170
var serviceCollection = new ServiceCollection ( ) ;
119
- serviceCollection . AddLazyScoped < IService1 , Service1 > ( ) ;
120
- serviceCollection . AddScoped < IService2 , Service2 > ( ) ;
171
+ switch ( lifetime )
172
+ {
173
+ case ServiceLifetime . Scoped :
174
+ serviceCollection . AddLazyScoped < IService1 , Service1 > ( ) ;
175
+ serviceCollection . AddScoped < IService2 , Service2 > ( ) ;
176
+ break ;
177
+ case ServiceLifetime . Singleton :
178
+ serviceCollection . AddLazySingleton < IService1 , Service1 > ( ) ;
179
+ serviceCollection . AddSingleton < IService2 , Service2 > ( ) ;
180
+ break ;
181
+ case ServiceLifetime . Transient :
182
+ serviceCollection . AddLazyTransient < IService1 , Service1 > ( ) ;
183
+ serviceCollection . AddTransient < IService2 , Service2 > ( ) ;
184
+ break ;
185
+ }
121
186
122
187
using ( var serviceProvider = serviceCollection . BuildServiceProvider ( ) )
123
188
{
@@ -131,11 +196,25 @@ public void ArgumentsMustBePassedToMethodCorrectly()
131
196
}
132
197
}
133
198
134
- [ Fact ]
135
- public void DependencyResolutionExceptionMustBeThrownAfterMethodIsCalledWhenDependentServiceIsNotRegistered ( )
199
+ [ InlineData ( ServiceLifetime . Scoped ) ]
200
+ [ InlineData ( ServiceLifetime . Singleton ) ]
201
+ [ InlineData ( ServiceLifetime . Transient ) ]
202
+ [ Theory ]
203
+ public void DependencyResolutionExceptionMustBeThrownAfterMethodIsCalledWhenDependentServiceIsNotRegistered ( ServiceLifetime lifetime )
136
204
{
137
205
var serviceCollection = new ServiceCollection ( ) ;
138
- serviceCollection . AddLazyScoped < IService1 , Service1 > ( ) ;
206
+ switch ( lifetime )
207
+ {
208
+ case ServiceLifetime . Scoped :
209
+ serviceCollection . AddLazyScoped < IService1 , Service1 > ( ) ;
210
+ break ;
211
+ case ServiceLifetime . Singleton :
212
+ serviceCollection . AddLazySingleton < IService1 , Service1 > ( ) ;
213
+ break ;
214
+ case ServiceLifetime . Transient :
215
+ serviceCollection . AddLazyTransient < IService1 , Service1 > ( ) ;
216
+ break ;
217
+ }
139
218
140
219
using ( var serviceProvider = serviceCollection . BuildServiceProvider ( ) )
141
220
{
@@ -145,11 +224,25 @@ public void DependencyResolutionExceptionMustBeThrownAfterMethodIsCalledWhenDepe
145
224
}
146
225
}
147
226
148
- [ Fact ]
149
- public void InternalServiceMustBeResolvedFromAssemblyMarkedAsVisibleForProxy ( )
227
+ [ InlineData ( ServiceLifetime . Scoped ) ]
228
+ [ InlineData ( ServiceLifetime . Singleton ) ]
229
+ [ InlineData ( ServiceLifetime . Transient ) ]
230
+ [ Theory ]
231
+ public void InternalServiceMustBeResolvedFromAssemblyMarkedAsVisibleForProxy ( ServiceLifetime lifetime )
150
232
{
151
233
var serviceCollection = new ServiceCollection ( ) ;
152
- serviceCollection . AddLazyScoped < IInternalService , InternalService > ( ) ;
234
+ switch ( lifetime )
235
+ {
236
+ case ServiceLifetime . Scoped :
237
+ serviceCollection . AddLazyScoped < IInternalService , InternalService > ( ) ;
238
+ break ;
239
+ case ServiceLifetime . Singleton :
240
+ serviceCollection . AddLazySingleton < IInternalService , InternalService > ( ) ;
241
+ break ;
242
+ case ServiceLifetime . Transient :
243
+ serviceCollection . AddLazyTransient < IInternalService , InternalService > ( ) ;
244
+ break ;
245
+ }
153
246
154
247
using ( var serviceProvider = serviceCollection . BuildServiceProvider ( ) )
155
248
{
@@ -160,10 +253,32 @@ public void InternalServiceMustBeResolvedFromAssemblyMarkedAsVisibleForProxy()
160
253
}
161
254
}
162
255
163
- [ Fact ]
164
- public void ClosedGenericServiceMustBeResolved ( )
256
+ [ InlineData ( ServiceLifetime . Scoped ) ]
257
+ [ InlineData ( ServiceLifetime . Singleton ) ]
258
+ [ InlineData ( ServiceLifetime . Transient ) ]
259
+ [ Theory ]
260
+ public void ClosedGenericServiceMustBeResolved ( ServiceLifetime lifetime )
165
261
{
166
262
var serviceCollection = new ServiceCollection ( ) ;
263
+ switch ( lifetime )
264
+ {
265
+ case ServiceLifetime . Scoped :
266
+ serviceCollection . AddLazyScoped (
267
+ typeof ( IGenericService < ParameterType1 , ParameterType2 , ParameterType3 > ) ,
268
+ typeof ( GenericService < ParameterType1 , ParameterType2 , ParameterType3 > ) ) ;
269
+ break ;
270
+ case ServiceLifetime . Singleton :
271
+ serviceCollection . AddLazySingleton (
272
+ typeof ( IGenericService < ParameterType1 , ParameterType2 , ParameterType3 > ) ,
273
+ typeof ( GenericService < ParameterType1 , ParameterType2 , ParameterType3 > ) ) ;
274
+ break ;
275
+ case ServiceLifetime . Transient :
276
+ serviceCollection . AddLazyTransient (
277
+ typeof ( IGenericService < ParameterType1 , ParameterType2 , ParameterType3 > ) ,
278
+ typeof ( GenericService < ParameterType1 , ParameterType2 , ParameterType3 > ) ) ;
279
+ break ;
280
+ }
281
+
167
282
serviceCollection . AddLazyScoped (
168
283
typeof ( IGenericService < ParameterType1 , ParameterType2 , ParameterType3 > ) ,
169
284
typeof ( GenericService < ParameterType1 , ParameterType2 , ParameterType3 > ) ) ;
0 commit comments