@@ -337,4 +337,150 @@ public async Task DoesNotContainKeyedServiceType_ShouldThrowAssertion_FromTypes_
337337 }
338338 #endregion
339339
340+ #region ContainsKeyedServiceImplementation
341+ [ Test ]
342+ public async Task ContainsKeyedServiceImplementation_ShouldAssert ( ) {
343+ // Arrange
344+ var services = new ServiceCollection ( ) ;
345+ const string key = "test-key" ;
346+
347+ // Act
348+ services . AddKeyedSingleton < IService , Service > ( key ) ;
349+
350+ // Assert
351+ await Assert . That ( services ) . ContainsKeyedServiceImplementation < IService , Service > ( key ) ;
352+ }
353+
354+ [ Test ]
355+ [ Arguments ( typeof ( IService ) , typeof ( Service ) ) ]
356+ public async Task ContainsKeyedServiceImplementation_ShouldAssert_FromTypes ( Type service , Type implementation ) {
357+ // Arrange
358+ var services = new ServiceCollection ( ) ;
359+ const string key = "test-key" ;
360+
361+ // Act
362+ services . AddKeyedSingleton ( service , key , implementation ) ;
363+
364+ // Assert
365+ await Assert . That ( services ) . ContainsKeyedServiceImplementation ( service , implementation , key ) ;
366+ }
367+
368+ [ Test ]
369+ public async Task ContainsKeyedServiceImplementation_ShouldThrowAssertion_WhenServiceNotFound ( ) {
370+ // Arrange
371+ var services = new ServiceCollection ( ) ;
372+ const string key = "test-key" ;
373+
374+ // Act
375+ services . AddKeyedSingleton < IService , Service > ( key ) ;
376+
377+ // Assert
378+ await Assert . ThrowsAsync < AssertionException > ( async ( ) => await Assert . That ( services ) . ContainsKeyedServiceImplementation < int , int > ( key )
379+ ) ;
380+ }
381+
382+ [ Test ]
383+ public async Task ContainsKeyedServiceImplementation_ShouldThrowAssertion_WhenKeyNotFound ( ) {
384+ // Arrange
385+ var services = new ServiceCollection ( ) ;
386+ const string key = "test-key" ;
387+ const string wrongKey = "wrong-key" ;
388+
389+ // Act
390+ services . AddKeyedSingleton < IService , Service > ( key ) ;
391+
392+ // Assert
393+ await Assert . ThrowsAsync < AssertionException > ( async ( ) => await Assert . That ( services ) . ContainsKeyedServiceImplementation < IService , Service > ( wrongKey )
394+ ) ;
395+ }
396+
397+ [ Test ]
398+ public async Task ContainsKeyedServiceImplementation_ShouldThrowAssertion_WhenWrongImplementation ( ) {
399+ // Arrange
400+ var services = new ServiceCollection ( ) ;
401+ const string key = "test-key" ;
402+
403+ // Act
404+ services . AddKeyedSingleton < IService , Service > ( key ) ;
405+
406+ // Assert
407+ await Assert . ThrowsAsync < AssertionException > ( async ( ) => await Assert . That ( services ) . ContainsKeyedServiceImplementation < IService , IService > ( key )
408+ ) ;
409+ }
410+ #endregion
411+
412+ #region DoesNotContainKeyedServiceImplementation
413+ [ Test ]
414+ public async Task DoesNotContainKeyedServiceImplementation_ShouldAssert ( ) {
415+ // Arrange
416+ var services = new ServiceCollection ( ) ;
417+ const string key = "test-key" ;
418+
419+ // Act
420+ services . AddKeyedSingleton < IService , Service > ( key ) ;
421+
422+ // Assert
423+ await Assert . That ( services ) . DoesNotContainKeyedServiceImplementation < int , int > ( key ) ;
424+ }
425+
426+ [ Test ]
427+ [ Arguments ( typeof ( IService ) , typeof ( Service ) ) ]
428+ public async Task DoesNotContainKeyedServiceImplementation_ShouldAssert_FromTypes ( Type service , Type implementation ) {
429+ // Arrange
430+ var services = new ServiceCollection ( ) ;
431+ const string key = "test-key" ;
432+
433+ // Act
434+ services . AddKeyedSingleton ( service , implementation , key ) ;
435+
436+ // Assert
437+ await Assert . That ( services ) . DoesNotContainKeyedServiceImplementation ( typeof ( int ) , typeof ( int ) , key ) ;
438+ }
439+
440+ [ Test ]
441+ public async Task DoesNotContainKeyedServiceImplementation_ShouldThrowAssertion_WhenFound ( ) {
442+ // Arrange
443+ var services = new ServiceCollection ( ) ;
444+ const string key = "test-key" ;
445+
446+ // Act
447+ services . AddKeyedSingleton < IService , Service > ( key ) ;
448+
449+ // Assert
450+ await Assert . ThrowsAsync < AssertionException > ( async ( ) => await Assert . That ( services ) . DoesNotContainKeyedServiceImplementation < IService , Service > ( key )
451+ ) ;
452+ }
453+
454+ [ Test ]
455+ [ Arguments ( typeof ( IService ) , typeof ( Service ) ) ]
456+ public async Task DoesNotContainKeyedServiceImplementation_ShouldThrowAssertion_FromTypes_WhenFound (
457+ Type service , Type implementation
458+ ) {
459+ // Arrange
460+ var services = new ServiceCollection ( ) ;
461+ const string key = "test-key" ;
462+
463+ // Act
464+ services . AddKeyedSingleton ( service , key , implementation ) ;
465+
466+ // Assert
467+ await Assert . ThrowsAsync < AssertionException > ( async ( ) => await Assert . That ( services ) . DoesNotContainKeyedServiceImplementation ( service , implementation , key )
468+ ) ;
469+ }
470+
471+ [ Test ]
472+ public async Task DoesNotContainKeyedServiceImplementation_ShouldAssert_WhenDifferentKey ( ) {
473+ // Arrange
474+ var services = new ServiceCollection ( ) ;
475+ const string key = "test-key" ;
476+ const string differentKey = "different-key" ;
477+
478+ // Act
479+ services . AddKeyedSingleton < IService , Service > ( key ) ;
480+
481+ // Assert
482+ await Assert . That ( services ) . DoesNotContainKeyedServiceImplementation < IService , Service > ( differentKey ) ;
483+ }
484+ #endregion
485+
340486}
0 commit comments