public void Unsubscribe_MessagingEntityNotFoundException_RemovedSubscription(
                [Frozen] Mock <IEventBusSubscriptionsManager> mockSubsManager,
                [Frozen] Mock <ServiceBusAdministrationClient> mockAdminClient,
                [Frozen] Mock <IServiceBusPersisterConnection> mockConnection,
                sb.EventBusServiceBus sut
                )
            {
                //Arrange
                mockConnection.Setup(_ => _.AdminClient)
                .Throws <Exception>();

                //Act
                sut.Unsubscribe <TestIntegrationEvent, TestIntegrationEventHandler>();

                //Assert
                mockAdminClient.Verify(
                    _ => _.DeleteSubscriptionAsync(
                        It.IsAny <string>(),
                        It.IsAny <string>(),
                        It.IsAny <CancellationToken>()
                        ),
                    Times.Never
                    );

                mockSubsManager.Verify(
                    _ => _.RemoveSubscription <TestIntegrationEvent, TestIntegrationEventHandler>()
                    );
            }
            public void Subscribe_HandlerNotRegistered_AddSubscription(
                [Frozen] Mock <IEventBusSubscriptionsManager> mockSubsManager,
                [Frozen] Mock <ServiceBusAdministrationClient> mockAdminClient,
                [Frozen] Mock <IServiceBusPersisterConnection> mockConnection,
                Mock <Response <SubscriptionProperties> > mockResponse,
                sb.EventBusServiceBus sut
                )
            {
                //Arrange
                mockAdminClient.Setup(_ => _.CreateSubscriptionAsync(
                                          It.IsAny <CreateSubscriptionOptions>(),
                                          It.IsAny <CreateRuleOptions>(),
                                          It.IsAny <CancellationToken>()
                                          ))
                .Returns(Task.FromResult(mockResponse.Object));

                mockConnection.Setup(_ => _.AdminClient)
                .Returns(mockAdminClient.Object);

                //Act
                sut.Subscribe <TestIntegrationEvent, TestIntegrationEventHandler>();

                //Assert
                mockAdminClient.Verify(_ => _.CreateSubscriptionAsync(
                                           It.IsAny <CreateSubscriptionOptions>(),
                                           It.IsAny <CreateRuleOptions>(),
                                           It.IsAny <CancellationToken>()
                                           ));

                mockSubsManager.Verify(
                    _ => _.AddSubscription <TestIntegrationEvent, TestIntegrationEventHandler>()
                    );
            }
            public void Publish_OK(
                [Frozen] Mock <IServiceBusPersisterConnection> mockConnection,
                [Frozen] Mock <ServiceBusClient> mockServiceBusClient,
                [Frozen] Mock <ServiceBusSender> mockServiceBusSender,
                sb.EventBusServiceBus sut,
                TestIntegrationEvent integrationEvent
                )
            {
                //Arrange
                mockServiceBusSender.Setup(_ => _.SendMessageAsync(
                                               It.IsAny <ServiceBusMessage>(),
                                               It.IsAny <CancellationToken>()
                                               ))
                .Returns(Task.CompletedTask);

                mockServiceBusClient.Setup(_ => _.CreateSender(It.IsAny <string>()))
                .Returns(mockServiceBusSender.Object);
                mockConnection.Setup(_ => _.ServiceBusClient)
                .Returns(mockServiceBusClient.Object);

                //Act
                sut.Publish(integrationEvent);

                //Assert
                mockServiceBusSender.Verify(_ => _.SendMessageAsync(
                                                It.IsAny <ServiceBusMessage>(),
                                                It.IsAny <CancellationToken>()
                                                ));
            }
            public void Unsubscribe_Ok_RemovedSubscription(
                [Frozen] Mock <IEventBusSubscriptionsManager> mockSubsManager,
                [Frozen] Mock <ServiceBusAdministrationClient> mockAdminClient,
                [Frozen] Mock <IServiceBusPersisterConnection> mockConnection,
                sb.EventBusServiceBus sut
                )
            {
                //Arrange
                mockConnection.Setup(_ => _.AdminClient)
                .Returns(mockAdminClient.Object);

                //Act
                sut.Unsubscribe <TestIntegrationEvent, TestIntegrationEventHandler>();

                //Assert
                mockAdminClient.Verify(_ => _.DeleteSubscriptionAsync(
                                           It.IsAny <string>(),
                                           It.IsAny <string>(),
                                           It.IsAny <CancellationToken>()
                                           ));

                mockSubsManager.Verify(
                    _ => _.RemoveSubscription <TestIntegrationEvent, TestIntegrationEventHandler>()
                    );
            }
            public void Subscribe_ServiceBusException_AddSubscriptionIsCalled(
                [Frozen] Mock <IEventBusSubscriptionsManager> mockSubsManager,
                [Frozen] Mock <ServiceBusAdministrationClient> mockAdminClient,
                [Frozen] Mock <IServiceBusPersisterConnection> mockConnection,
                sb.EventBusServiceBus sut
                )
            {
                //Arrange
                mockConnection.Setup(_ => _.AdminClient)
                .Throws <Exception>();

                mockSubsManager.Setup(_ => _.HasSubscriptionsForEvent <TestIntegrationEvent>())
                .Returns(false);

                //Act
                sut.Subscribe <TestIntegrationEvent, TestIntegrationEventHandler>();

                //Assert
                mockAdminClient.Verify(
                    _ => _.CreateSubscriptionAsync(
                        It.IsAny <CreateSubscriptionOptions>(),
                        It.IsAny <CancellationToken>()
                        ),
                    Times.Never
                    );

                mockSubsManager.Verify(
                    _ => _.AddSubscription <TestIntegrationEvent, TestIntegrationEventHandler>()
                    );
            }
            public void SubscribeDynamic_OK(
                [Frozen] Mock <IEventBusSubscriptionsManager> mockSubsManager,
                sb.EventBusServiceBus sut
                )
            {
                //Arrange

                //Act
                sut.SubscribeDynamic <TestDynamicIntegrationEventHandler>("eventName");

                //Assert
                mockSubsManager.Verify(
                    _ => _.AddDynamicSubscription <TestDynamicIntegrationEventHandler>("eventName")
                    );
            }
            public void Dispose_Ok(
                [Frozen] Mock <IEventBusSubscriptionsManager> mockSubsManager,
                sb.EventBusServiceBus sut
                )
            {
                //Arrange

                //Act
                sut.Dispose();

                //Assert
                mockSubsManager.Verify(
                    _ => _.Clear()
                    );
            }