public void UseTemporaryMessagingEntityThatAlreadyExiststSpecifyingRecreateOptionShouldRecreate()
            {
                MessagingEntityVerifier messagingEntityVerifier = new MessagingEntityVerifier(_mockNamespaceManager.Object);

                messagingEntityVerifier.EnsureMessagingEntitiesExist(new[] { new MessageTypeMessagingEntityMappingDetails(typeof(ICommand), "commands", MessagingEntityType.Queue, MessagingEntityCreationOptions.CreateIfDoesntExist | MessagingEntityCreationOptions.CreateAsTemporary | MessagingEntityCreationOptions.RecreateExistingTemporary) });

                _mockNamespaceManager.Verify(nsm => nsm.DeleteQueue("commands"), Times.Once());
                _mockNamespaceManager.Verify(nsm => nsm.CreateQueue("commands"), Times.Once());
            }
            public void UseTemporaryMessagingEntityThatAlreadyExistsWithoutSpecifyingCanDeleteIfAlreadyExistsShouldThrow()
            {
                MessagingEntityVerifier messagingEntityVerifier = new MessagingEntityVerifier(_mockNamespaceManager.Object);

                Action action = () => messagingEntityVerifier.EnsureMessagingEntitiesExist(new[] { new MessageTypeMessagingEntityMappingDetails(typeof(ICommand), "commands", MessagingEntityType.Queue, MessagingEntityCreationOptions.CreateIfDoesntExist | MessagingEntityCreationOptions.CreateAsTemporary) });

                var exceptionAssertion = action.ShouldThrow <Obvs.AzureServiceBus.Configuration.MessagingEntityAlreadyExistsException>();

                exceptionAssertion.And.Path.Should().Be("commands");
                exceptionAssertion.And.MessagingEntityType.Should().Be(MessagingEntityType.Queue);
            }
            public void UseExistingMessagingEntityShouldNotTryToCreateTheMessagingEntity()
            {
                _mockNamespaceManager.Setup(nsm => nsm.QueueExists("commands"))
                .Returns(true);

                MessagingEntityVerifier messagingEntityVerifier = new MessagingEntityVerifier(_mockNamespaceManager.Object);

                messagingEntityVerifier.EnsureMessagingEntitiesExist(new[] { new MessageTypeMessagingEntityMappingDetails(typeof(ICommand), "commands", MessagingEntityType.Queue, MessagingEntityCreationOptions.CreateIfDoesntExist) });

                _mockNamespaceManager.Verify(nsm => nsm.QueueExists("commands"), Times.Once());
                _mockNamespaceManager.Verify(nsm => nsm.CreateQueue("commands"), Times.Never());
            }
            public void VerifyExistingMessagingEntityThatDoesNotExistShouldThrow()
            {
                _mockNamespaceManager.Setup(nsm => nsm.QueueExists("commands"))
                .Returns(false);

                MessagingEntityVerifier messagingEntityVerifier = new MessagingEntityVerifier(_mockNamespaceManager.Object);

                Action action = () => messagingEntityVerifier.EnsureMessagingEntitiesExist(new [] { new MessageTypeMessagingEntityMappingDetails(typeof(ICommand), "commands", MessagingEntityType.Queue, MessagingEntityCreationOptions.VerifyAlreadyExists) });

                var exceptionAssertion = action.ShouldThrow <MessagingEntityDoesNotAlreadyExistException>();

                exceptionAssertion.And.Path.Should().Be("commands");
                exceptionAssertion.And.MessagingEntityType.Should().Be(MessagingEntityType.Queue);
            }
            public void UseTemporarySubscriptionForTopicThatAlreadyExistsShouldCreateSubscription()
            {
                _mockNamespaceManager.Setup(nsm => nsm.TopicExists("events"))
                .Returns(true);

                _mockNamespaceManager.Setup(nsm => nsm.SubscriptionExists("events", "test-subscription"))
                .Returns(false);

                MessagingEntityVerifier messagingEntityVerifier = new MessagingEntityVerifier(_mockNamespaceManager.Object);

                messagingEntityVerifier.EnsureMessagingEntitiesExist(new[] { new MessageTypeMessagingEntityMappingDetails(typeof(IEvent), "events/subscriptions/test-subscription", MessagingEntityType.Subscription, MessagingEntityCreationOptions.CreateIfDoesntExist | MessagingEntityCreationOptions.CreateAsTemporary | MessagingEntityCreationOptions.RecreateExistingTemporary) });

                _mockNamespaceManager.Verify(nsm => nsm.TopicExists("events"), Times.Once());
                _mockNamespaceManager.Verify(nsm => nsm.CreateSubscription("events", "test-subscription"), Times.Once());
            }
            public void UseTemporarySubscriptionForTopicThatDoesntAlreadyExistThrows()
            {
                _mockNamespaceManager.Setup(nsm => nsm.TopicExists("events"))
                .Returns(false);

                _mockNamespaceManager.Setup(nsm => nsm.SubscriptionExists("events", "test-subscription"))
                .Returns(false);

                MessagingEntityVerifier messagingEntityVerifier = new MessagingEntityVerifier(_mockNamespaceManager.Object);

                Action action = () => messagingEntityVerifier.EnsureMessagingEntitiesExist(new[] { new MessageTypeMessagingEntityMappingDetails(typeof(IEvent), "events/subscriptions/test-subscription", MessagingEntityType.Subscription, MessagingEntityCreationOptions.CreateIfDoesntExist | MessagingEntityCreationOptions.CreateAsTemporary) });

                var exceptionAssertion = action.ShouldThrow <MessagingEntityDoesNotAlreadyExistException>();

                exceptionAssertion.And.Path.Should().Be("events");
                exceptionAssertion.And.MessagingEntityType.Should().Be(MessagingEntityType.Topic);
            }