@@ -20,31 +20,31 @@ public async Task Publish_CallsAllHandlers_WhenMultipleHandlersAreRegistered()
2020 cfg . RegisterPipelines = false ;
2121 cfg . RegisterNotifications = true ;
2222 } ) ;
23-
23+
2424 var spyPipelineOneMock = new Mock < INotificationHandler < MultiHandlersNotification > > ( ) ;
2525 var spyPipelineTwoMock = new Mock < INotificationHandler < MultiHandlersNotification > > ( ) ;
2626 var spyPipelineThreeMock = new Mock < INotificationHandler < MultiHandlersNotification > > ( ) ;
2727
2828 spyPipelineOneMock . Setup ( p => p . Handle ( It . IsAny < MultiHandlersNotification > ( ) , It . IsAny < CancellationToken > ( ) ) ) ;
2929 spyPipelineTwoMock . Setup ( p => p . Handle ( It . IsAny < MultiHandlersNotification > ( ) , It . IsAny < CancellationToken > ( ) ) ) ;
3030 spyPipelineThreeMock . Setup ( p => p . Handle ( It . IsAny < MultiHandlersNotification > ( ) , It . IsAny < CancellationToken > ( ) ) ) ;
31-
31+
3232 services . AddScoped < INotificationHandler < MultiHandlersNotification > > ( sp => spyPipelineOneMock . Object ) ;
3333 services . AddScoped < INotificationHandler < MultiHandlersNotification > > ( sp => spyPipelineTwoMock . Object ) ;
3434 services . AddScoped < INotificationHandler < MultiHandlersNotification > > ( sp => spyPipelineThreeMock . Object ) ;
35-
35+
3636 var serviceProvider = services . BuildServiceProvider ( ) ;
3737 var mediator = serviceProvider . GetRequiredService < IMediator > ( ) ;
38-
38+
3939 // Act
4040 await mediator . Publish ( new MultiHandlersNotification ( Guid . Empty ) , CancellationToken . None ) ;
41-
41+
4242 // Assert
4343 spyPipelineOneMock . Verify ( p => p . Handle ( It . IsAny < MultiHandlersNotification > ( ) , It . IsAny < CancellationToken > ( ) ) , Times . Exactly ( 1 ) ) ;
4444 spyPipelineTwoMock . Verify ( p => p . Handle ( It . IsAny < MultiHandlersNotification > ( ) , It . IsAny < CancellationToken > ( ) ) , Times . Exactly ( 1 ) ) ;
4545 spyPipelineThreeMock . Verify ( p => p . Handle ( It . IsAny < MultiHandlersNotification > ( ) , It . IsAny < CancellationToken > ( ) ) , Times . Exactly ( 1 ) ) ;
4646 }
47-
47+
4848 [ Fact ]
4949 public async Task PublishObject_CallsAllHandlers_WhenMultipleHandlersAreRegistered ( )
5050 {
@@ -56,29 +56,51 @@ public async Task PublishObject_CallsAllHandlers_WhenMultipleHandlersAreRegister
5656 cfg . RegisterPipelines = false ;
5757 cfg . RegisterNotifications = true ;
5858 } ) ;
59-
59+
6060 var spyPipelineOneMock = new Mock < INotificationHandler < MultiHandlersNotification > > ( ) ;
6161 var spyPipelineTwoMock = new Mock < INotificationHandler < MultiHandlersNotification > > ( ) ;
6262 var spyPipelineThreeMock = new Mock < INotificationHandler < MultiHandlersNotification > > ( ) ;
6363
6464 spyPipelineOneMock . Setup ( p => p . Handle ( It . IsAny < MultiHandlersNotification > ( ) , It . IsAny < CancellationToken > ( ) ) ) ;
6565 spyPipelineTwoMock . Setup ( p => p . Handle ( It . IsAny < MultiHandlersNotification > ( ) , It . IsAny < CancellationToken > ( ) ) ) ;
6666 spyPipelineThreeMock . Setup ( p => p . Handle ( It . IsAny < MultiHandlersNotification > ( ) , It . IsAny < CancellationToken > ( ) ) ) ;
67-
67+
6868 services . AddScoped < INotificationHandler < MultiHandlersNotification > > ( sp => spyPipelineOneMock . Object ) ;
6969 services . AddScoped < INotificationHandler < MultiHandlersNotification > > ( sp => spyPipelineTwoMock . Object ) ;
7070 services . AddScoped < INotificationHandler < MultiHandlersNotification > > ( sp => spyPipelineThreeMock . Object ) ;
71-
71+
7272 var serviceProvider = services . BuildServiceProvider ( ) ;
7373 var mediator = serviceProvider . GetRequiredService < IMediator > ( ) ;
74-
74+
7575 // Act
7676 object notificationObject = new MultiHandlersNotification ( Guid . Empty ) ;
7777 await mediator . Publish ( notificationObject , CancellationToken . None ) ;
78-
78+
7979 // Assert
8080 spyPipelineOneMock . Verify ( p => p . Handle ( It . IsAny < MultiHandlersNotification > ( ) , It . IsAny < CancellationToken > ( ) ) , Times . Exactly ( 1 ) ) ;
8181 spyPipelineTwoMock . Verify ( p => p . Handle ( It . IsAny < MultiHandlersNotification > ( ) , It . IsAny < CancellationToken > ( ) ) , Times . Exactly ( 1 ) ) ;
8282 spyPipelineThreeMock . Verify ( p => p . Handle ( It . IsAny < MultiHandlersNotification > ( ) , It . IsAny < CancellationToken > ( ) ) , Times . Exactly ( 1 ) ) ;
8383 }
84- }
84+
85+ [ Fact ]
86+ public void RegisterNotification_SingleClassWithMultipleNotificationInterfaces_ResolvesAllHandlers ( )
87+ {
88+ // Arrange
89+ var services = new ServiceCollection ( ) ;
90+ services . AddDispatchR ( cfg =>
91+ {
92+ cfg . Assemblies . Add ( typeof ( Fixture ) . Assembly ) ;
93+ cfg . RegisterNotifications = true ;
94+ } ) ;
95+
96+ var serviceProvider = services . BuildServiceProvider ( ) ;
97+
98+ // Act
99+ var handlers1 = serviceProvider . GetServices < INotificationHandler < MultiHandlersNotification > > ( ) ;
100+ var handlers2 = serviceProvider . GetServices < INotificationHandler < MultiHandlersNotification2 > > ( ) ;
101+
102+ // Assert
103+ Assert . Contains ( handlers1 , h => h is MultiNotificationHandler ) ;
104+ Assert . Contains ( handlers2 , h => h is MultiNotificationHandler ) ;
105+ }
106+ }
0 commit comments