public void ManagementApi_ShouldCreateGetOrDeleteHubOrRecieveConflictException() { LoadMockData(); try { bool notificationHubExists = true; IEnumerable <NotificationHubDescription> notificationHubDescriptions; // Check that GetNotification returns MessagingEntityNotFoundException than hub does not exist Assert.Throws <MessagingEntityNotFoundException>(() => _namespaceManager.GetNotificationHub(_notificationHubName)); // Check that NotificationHubExists returns false when notification hub does not exist notificationHubExists = _namespaceManager.NotificationHubExists(_notificationHubName); Assert.False(notificationHubExists); // Check that GetNotificationHubs returns collection without hub notificationHubDescriptions = _namespaceManager.GetNotificationHubs(); Assert.DoesNotContain(notificationHubDescriptions, nhd => nhd.Path == _notificationHubName); // Check that CreateNotificationHub method create hub with correct Path var createNotificationHubDescription = _namespaceManager.CreateNotificationHub(_notificationHubName); Assert.Equal(_notificationHubName, createNotificationHubDescription.Path); // Check that NotificationHubExists return true when notification hub exist notificationHubExists = _namespaceManager.NotificationHubExists(_notificationHubName); Assert.True(notificationHubExists); // Check that GetNotificationHubs returns collection with existed hub notificationHubDescriptions = _namespaceManager.GetNotificationHubs(); Assert.Single(notificationHubDescriptions); // Check that CreateNotificationHub returns MessagingEntityAlreadyExistsException than hub is alredy exist Assert.Throws <MessagingEntityAlreadyExistsException>(() => _namespaceManager.CreateNotificationHub(_notificationHubName)); // Check that GetNotificationHub returns correct hub var getNotificationHubDescription = _namespaceManager.GetNotificationHub(_notificationHubName); Assert.NotNull(getNotificationHubDescription); // Check that UpdateNotificationHub correctly update hub createNotificationHubDescription.IsDisabled = true; var updatedNotificationHubDescription = _namespaceManager.UpdateNotificationHub(createNotificationHubDescription); Assert.True(updatedNotificationHubDescription.IsDisabled); // Check that DeleteNotificationHub correctly remove hub _namespaceManager.DeleteNotificationHub(_notificationHubName); // Check that NotificationHubExists return false when notification hub is not exist notificationHubExists = _namespaceManager.NotificationHubExists(_notificationHubName); Assert.False(notificationHubExists); // Check that GetNotificationHubs returns collection without not existed hub notificationHubDescriptions = _namespaceManager.GetNotificationHubs(); Assert.Empty(notificationHubDescriptions); // Check that DeleteNotificationHub returns MessagingEntityNotFoundException than hub is not exist Assert.Throws <MessagingEntityNotFoundException>(() => _namespaceManager.DeleteNotificationHub(_notificationHubName)); } finally { RecordTestResults(); } }
private List <ExtendedAuthorizationRule> GetAuthorizationRulesToFilter(AuthorizationRuleFilterOption options) { if (!string.IsNullOrEmpty(options.EntityName)) { return(GetAuthorizationRuleCore( options.Namespace, options.EntityName, options.EntityType, r => true)); } else if (options.EntityTypes != null && options.EntityTypes.Count > 0) { NamespaceManager namespaceManager = CreateNamespaceManager(options.Namespace); List <ExtendedAuthorizationRule> rules = new List <ExtendedAuthorizationRule>(); options.EntityTypes = options.EntityTypes.Distinct().ToList(); foreach (ServiceBusEntityType type in options.EntityTypes) { switch (type) { case ServiceBusEntityType.Queue: rules.AddRange(namespaceManager.GetQueues() .SelectMany(e => e.Authorization .Select(r => CreateExtendedAuthorizationRule( r, options.Namespace, e.Path, ServiceBusEntityType.Queue)))); break; case ServiceBusEntityType.Topic: rules.AddRange(namespaceManager.GetTopics() .SelectMany(e => e.Authorization .Select(r => CreateExtendedAuthorizationRule( r, options.Namespace, e.Path, ServiceBusEntityType.Topic)))); break; case ServiceBusEntityType.Relay: rules.AddRange(namespaceManager.GetRelaysAsync().Result .SelectMany(e => e.Authorization .Select(r => CreateExtendedAuthorizationRule( r, options.Namespace, e.Path, ServiceBusEntityType.Relay)))); break; case ServiceBusEntityType.NotificationHub: rules.AddRange(namespaceManager.GetNotificationHubs() .SelectMany(e => e.Authorization .Select(r => CreateExtendedAuthorizationRule( r, options.Namespace, e.Path, ServiceBusEntityType.NotificationHub)))); break; default: throw new InvalidOperationException(); } } return(rules); } else { return(ServiceBusClient.Namespaces.ListAuthorizationRules(options.Namespace) .AuthorizationRules .Select(ar => ar.ToSharedAccessAuthorizationRule()) .Select(r => CreateExtendedAuthorizationRule(r, options.Namespace)) .ToList()); } }