@@ -2,6 +2,7 @@ namespace Carter.Tests
22{
33 using System . Linq ;
44 using Carter . Tests . ContentNegotiation ;
5+ using Carter . Tests . InternalRooms ;
56 using Carter . Tests . ModelBinding ;
67 using Carter . Tests . StreamTests ;
78 using FluentValidation ;
@@ -123,7 +124,7 @@ public void Should_register_responsenegotiators_passed_in_by_configurator_and_de
123124 }
124125
125126 [ Fact ]
126- public void Should_register_multiple_responsenegotiators_passed_in_by_configurator_and_default_json_negotiator ( )
127+ public void Should_register_multiple_response_negotiators_passed_in_by_configurator_and_default_json_negotiator ( )
127128 {
128129 //Given
129130 var serviceCollection = new ServiceCollection ( ) ;
@@ -132,8 +133,8 @@ public void Should_register_multiple_responsenegotiators_passed_in_by_configurat
132133 serviceCollection . AddCarter ( configurator : configurator => configurator . WithResponseNegotiators ( typeof ( TestResponseNegotiator ) , typeof ( TestXmlResponseNegotiator ) ) ) ;
133134
134135 //Then
135- var responsenegotiators = serviceCollection . Where ( x => x . ServiceType == typeof ( IResponseNegotiator ) ) ;
136- Assert . Equal ( 3 , responsenegotiators . Count ( ) ) ;
136+ var responseNegotiators = serviceCollection . Where ( x => x . ServiceType == typeof ( IResponseNegotiator ) ) ;
137+ Assert . Equal ( 3 , responseNegotiators . Count ( ) ) ;
137138 }
138139
139140 [ Fact ]
@@ -177,5 +178,180 @@ public void Should_register_no_response_negotiators_passed_in_by_configurator()
177178 var responseNegotiators = serviceCollection . Where ( x => x . ServiceType == typeof ( IResponseNegotiator ) ) ;
178179 Assert . Single ( responseNegotiators ) ;
179180 }
181+
182+ [ Fact ]
183+ public void Should_register_internal_modules_when_assembly_scanned ( )
184+ {
185+ //Given
186+ var serviceCollection = new ServiceCollection ( ) ;
187+
188+ //When
189+ serviceCollection . AddCarter ( ) ;
190+
191+ //Then
192+ var modules = serviceCollection . Where ( x => x . ServiceType == typeof ( ICarterModule ) ) ;
193+ var internalModule = modules . FirstOrDefault ( x => x . ImplementationType == typeof ( InternalRoomModule ) ) ;
194+ Assert . NotNull ( internalModule ) ;
195+ }
196+
197+ [ Fact ]
198+ public void Should_register_internal_module_passed_in_by_configurator ( )
199+ {
200+ //Given
201+ var serviceCollection = new ServiceCollection ( ) ;
202+
203+ //When
204+ serviceCollection . AddCarter ( configurator : configurator => configurator . WithModule < InternalRoomModule > ( ) ) ;
205+
206+ //Then
207+ var modules = serviceCollection . Where ( x => x . ServiceType == typeof ( ICarterModule ) ) ;
208+ var internalModule = modules . FirstOrDefault ( x => x . ImplementationType == typeof ( InternalRoomModule ) ) ;
209+ Assert . NotNull ( internalModule ) ;
210+ }
211+
212+ [ Fact ]
213+ public void Should_register_multiple_internal_modules_passed_in_by_configurator ( )
214+ {
215+ //Given
216+ var serviceCollection = new ServiceCollection ( ) ;
217+
218+ //When
219+ serviceCollection . AddCarter ( configurator : configurator =>
220+ configurator . WithModules ( typeof ( InternalRoomModule ) , typeof ( NestedInternalRoomModuleWrapper . NestedInternalRoomModule ) ) ) ;
221+
222+ //Then
223+ var modules = serviceCollection . Where ( x => x . ServiceType == typeof ( ICarterModule ) ) . ToList ( ) ;
224+ Assert . Contains ( modules , m => m . ImplementationType == typeof ( InternalRoomModule ) ) ;
225+ Assert . Contains ( modules , m => m . ImplementationType == typeof ( NestedInternalRoomModuleWrapper . NestedInternalRoomModule ) ) ;
226+ Assert . Equal ( 2 , modules . Count ( ) ) ;
227+ }
228+
229+ [ Fact ]
230+ public void Should_register_internal_validators_when_assembly_scanned ( )
231+ {
232+ //Given
233+ var serviceCollection = new ServiceCollection ( ) ;
234+
235+ //When
236+ serviceCollection . AddCarter ( ) ;
237+
238+ //Then
239+ var validators = serviceCollection . Where ( x => x . ServiceType == typeof ( IValidator ) ) ;
240+ var internalValidator = validators . FirstOrDefault ( x => x . ImplementationType == typeof ( InternalRoomModelValidator ) ) ;
241+ Assert . NotNull ( internalValidator ) ;
242+ }
243+
244+ [ Fact ]
245+ public void Should_register_internal_validator_passed_in_by_configurator ( )
246+ {
247+ //Given
248+ var serviceCollection = new ServiceCollection ( ) ;
249+
250+ //When
251+ serviceCollection . AddCarter ( configurator : configurator => configurator . WithValidator < InternalRoomModelValidator > ( ) ) ;
252+
253+ //Then
254+ var validators = serviceCollection . Where ( x => x . ServiceType == typeof ( IValidator ) ) . ToList ( ) ;
255+ var internalValidator = validators . FirstOrDefault ( x => x . ImplementationType == typeof ( InternalRoomModelValidator ) ) ;
256+ Assert . NotNull ( internalValidator ) ;
257+ Assert . Single ( validators ) ;
258+ }
259+
260+ [ Fact ]
261+ public void Should_register_multiple_internal_validators_passed_in_by_configurator ( )
262+ {
263+ //Given
264+ var serviceCollection = new ServiceCollection ( ) ;
265+
266+ //When
267+ serviceCollection . AddCarter ( configurator : configurator =>
268+ configurator . WithValidators ( typeof ( InternalRoomModelValidator ) , typeof ( NestedInternalTestModelValidatorWrapper . InternalTestModelValidator ) ) ) ;
269+
270+ //Then
271+ var validators = serviceCollection . Where ( x => x . ServiceType == typeof ( IValidator ) ) . ToList ( ) ;
272+ Assert . Contains ( validators , v => v . ImplementationType == typeof ( InternalRoomModelValidator ) ) ;
273+ Assert . Contains ( validators , v => v . ImplementationType == typeof ( NestedInternalTestModelValidatorWrapper . InternalTestModelValidator ) ) ;
274+ Assert . Equal ( 2 , validators . Count ( ) ) ;
275+ }
276+
277+ [ Fact ]
278+ public void Should_register_internal_response_negotiators_when_assembly_scanned ( )
279+ {
280+ //Given
281+ var serviceCollection = new ServiceCollection ( ) ;
282+
283+ //When
284+ serviceCollection . AddCarter ( ) ;
285+
286+ //Then
287+ var responseNegotiators = serviceCollection . Where ( x => x . ServiceType == typeof ( IResponseNegotiator ) ) ;
288+ var internalNegotiator = responseNegotiators . FirstOrDefault ( x => x . ImplementationType == typeof ( InternalResponseNegotiator ) ) ;
289+ Assert . NotNull ( internalNegotiator ) ;
290+ }
291+
292+ [ Fact ]
293+ public void Should_register_internal_response_negotiator_passed_in_by_configurator ( )
294+ {
295+ //Given
296+ var serviceCollection = new ServiceCollection ( ) ;
297+
298+ //When
299+ serviceCollection . AddCarter ( configurator : configurator => configurator . WithResponseNegotiator < InternalResponseNegotiator > ( ) ) ;
300+
301+ //Then
302+ var responseNegotiators = serviceCollection . Where ( x => x . ServiceType == typeof ( IResponseNegotiator ) ) ;
303+ var internalNegotiator = responseNegotiators . FirstOrDefault ( x => x . ImplementationType == typeof ( InternalResponseNegotiator ) ) ;
304+ Assert . NotNull ( internalNegotiator ) ;
305+ }
306+
307+ [ Fact ]
308+ public void Should_register_multiple_internal_response_negotiators_passed_in_by_configurator ( )
309+ {
310+ //Given
311+ var serviceCollection = new ServiceCollection ( ) ;
312+
313+ //When
314+ serviceCollection . AddCarter ( configurator : configurator =>
315+ configurator . WithResponseNegotiators ( typeof ( InternalResponseNegotiator ) , typeof ( NestedInternalResponseNegotiatorWrapper . NestedInternalResponseNegotiator ) ) ) ;
316+
317+ //Then
318+ var responseNegotiators = serviceCollection . Where ( x => x . ServiceType == typeof ( IResponseNegotiator ) ) . ToList ( ) ;
319+ Assert . Contains ( responseNegotiators , r => r . ImplementationType == typeof ( InternalResponseNegotiator ) ) ;
320+ Assert . Contains ( responseNegotiators , r => r . ImplementationType == typeof ( NestedInternalResponseNegotiatorWrapper . NestedInternalResponseNegotiator ) ) ;
321+ }
322+
323+ [ Fact ]
324+ public void Should_register_mix_of_public_and_internal_modules ( )
325+ {
326+ //Given
327+ var serviceCollection = new ServiceCollection ( ) ;
328+
329+ //When
330+ serviceCollection . AddCarter ( configurator : configurator =>
331+ configurator . WithModules ( typeof ( TestModule ) , typeof ( InternalRoomModule ) ) ) ;
332+
333+ //Then
334+ var modules = serviceCollection . Where ( x => x . ServiceType == typeof ( ICarterModule ) ) . ToList ( ) ;
335+ Assert . Contains ( modules , m => m . ImplementationType == typeof ( TestModule ) ) ;
336+ Assert . Contains ( modules , m => m . ImplementationType == typeof ( InternalRoomModule ) ) ;
337+ Assert . Equal ( 2 , modules . Count ( ) ) ;
338+ }
339+
340+ [ Fact ]
341+ public void Should_register_mix_of_public_and_internal_validators ( )
342+ {
343+ //Given
344+ var serviceCollection = new ServiceCollection ( ) ;
345+
346+ //When
347+ serviceCollection . AddCarter ( configurator : configurator =>
348+ configurator . WithValidators ( typeof ( TestModelValidator ) , typeof ( InternalRoomModelValidator ) ) ) ;
349+
350+ //Then
351+ var validators = serviceCollection . Where ( x => x . ServiceType == typeof ( IValidator ) ) . ToList ( ) ;
352+ Assert . Contains ( validators , v => v . ImplementationType == typeof ( TestModelValidator ) ) ;
353+ Assert . Contains ( validators , v => v . ImplementationType == typeof ( InternalRoomModelValidator ) ) ;
354+ Assert . Equal ( 2 , validators . Count ( ) ) ;
355+ }
180356 }
181357}
0 commit comments